skillfed

dynamic-linking

Master Linux shared library fundamentals: create position-independent libraries with proper soname versioning, embed search paths using RPATH or RUNPATH, and debug loading failures with LD_DEBUG and ldd. Build plugin systems with dlopen/dlsym, intercept functions via LD_PRELOAD, and control symbol visibility to reduce binary bloat and namespace collisions.

Dynamic Linking guides you through shared library creation, RPATH/RUNPATH configuration, soname versioning, dlopen/dlsym plugin patterns, and LD_PRELOAD interposition on Linux.

AI-generated summary based on this skill's SKILL.md

148 19 MIT updated by mohitmishra786

Install

mohitmishra786/low-level-dev-skills/dynamic-linking · repository language: JavaScript

git clone https://github.com/mohitmishra786/low-level-dev-skills
cp -r low-level-dev-skills/skills/binaries/dynamic-linking ~/.claude/skills/dynamic-linking
npx skillfed install mohitmishra786/low-level-dev-skills/dynamic-linking

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

How do I fix 'cannot open shared object file' error?

dynamic-linking addresses this by teaching you to inspect library paths with ldd, set RPATH or RUNPATH during compilation, use LD_LIBRARY_PATH as a temporary override, or register libraries system-wide with ldconfig. The skill covers diagnosing missing dependencies, embedding absolute or relative search paths in your binary, and verifying correct soname references with readelf to resolve loading failures.

What is RPATH vs RUNPATH in Linux?

dynamic-linking explains that RPATH is a legacy search path embedded in binaries, checked before LD_LIBRARY_PATH, while RUNPATH is the modern replacement, checked after LD_LIBRARY_PATH, allowing environment overrides. Both are set at link time with -Wl,-rpath or -Wl,--runpath flags. RUNPATH is preferred because it respects LD_LIBRARY_PATH and supports relative paths like $ORIGIN for portable deployments.

How do I create a dlopen dlsym plugin system?

dynamic-linking teaches you to design plugin interfaces as header files, compile plugins as shared libraries with -fPIC -shared, then load them at runtime using dlopen with RTLD_LAZY or RTLD_NOW flags, and resolve function pointers with dlsym. The skill covers error handling via dlerror, managing plugin lifecycle with dlclose, and versioning plugin ABIs to maintain compatibility across updates.

How can I use LD_PRELOAD for function interception?

dynamic-linking shows how to write a shared library that defines wrapper functions matching target signatures, compile it with -fPIC -shared, then preload it before execution: LD_PRELOAD=./wrapper.so ./program. The skill covers intercepting malloc, printf, or system calls for debugging or testing, preserving original behavior via dlsym(RTLD_NEXT), and avoiding infinite recursion in wrapper logic.

What is soname versioning and why does it matter?

dynamic-linking explains soname versioning ensures backward compatibility: set soname at link time with -Wl,-soname,libfoo.so.1, create symlinks (libfoo.so.1 → libfoo.so.1.2.3), and increment MAJOR on breaking changes, MINOR on additions, PATCH on fixes. Clients link against libfoo.so.1, so you can release libfoo.so.1.2.4 without recompilation, while libfoo.so.2 signals incompatible changes requiring rebuilds.

How do I control symbol visibility and reduce binary size?

dynamic-linking teaches symbol visibility control via -fvisibility=hidden compiler flag and __attribute__((visibility("default"))) for exported symbols, or version scripts with linker directives. This hides internal symbols, reduces binary size, prevents namespace collisions, and improves load times. Combine with -fPIC for position-independent code, and use readelf -s to verify only intended symbols are exported.

SKILL.md

rendered from the published skill — quoted content, verbatim

Dynamic Linking

Purpose

Guide agents through Linux dynamic linking: shared library creation, RPATH/RUNPATH configuration, soname versioning, dlopen/dlsym plugin patterns, LD_PRELOAD interposition, and symbol visibility control.

Triggers

  • "Cannot open shared object file: No such file or directory"
  • "How do I set RPATH so my binary finds its shared library?"
  • "How do I use dlopen/dlsym for a plugin system?"
  • "What's the difference between RPATH and RUNPATH?"
  • "How do I use LD_PRELOAD to intercept a function?"
  • "How do I version my shared library with soname?"

Workflow

1. Creating a shared library

```bash

Compile with -fPIC (position-independent code)

gcc -fPIC -c src/mylib.c -o mylib.o

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 2 files
skills/binaries/dynamic-linking/SKILL.md
skills/binaries/dynamic-linking/references/ld-rpath-soname.md

Related skills

Tags

runtime-library-loading symbol-resolution binary-relocation plugin-architecture function-hooking library-versioning elf-metadata deployment-flexibility