| name | elf-inspection |
| description | ELF binary inspection skill for Linux. Use when examining ELF executables or shared libraries with readelf, objdump, nm, or ldd to understand symbol visibility, section layout, dynamic dependencies, build IDs, or relocation entries. Activates on queries about ELF format, shared library dependencies, symbol tables, section sizes, DWARF debug info in binaries, binary bloat analysis, or undefined symbol errors. |
ELF Inspection
Purpose
Guide agents through inspecting Linux ELF binaries: symbol tables, section layout, dynamic linking, debug info, and diagnosing linker errors.
Triggers
- "What libraries does this binary depend on?"
- "Why is this binary so large?"
- "I have an
undefined reference or symbol not found at runtime"
- "How do I check if debug info is in this binary?"
- "How do I find what symbols a library exports?"
- "How do I check if a binary is PIE / has RELRO?"
Workflow
1. Quick overview: file and size
file prog
size prog
size --format=sysv prog
2. Dynamic dependencies: ldd
ldd ./prog
ldd -v ./prog
ldd ./prog | grep libssl
ldd ./libfoo.so
If ldd shows not found, the shared library is missing from LD_LIBRARY_PATH or /etc/ld.so.conf.
Fix:
export LD_LIBRARY_PATH=/path/to/libs:$LD_LIBRARY_PATH
sudo ldconfig
3. Symbols: nm
nm prog
nm -D ./libfoo.so
nm -C prog
nm --defined-only prog
nm -u prog
nm -S prog
nm -D /usr/lib/libssl.so | grep SSL_read
Symbol type codes:
T / t — text (code): global / local
D / d — data (initialised): global / local
B / b — BSS (uninitialised): global / local
R / r — read-only data: global / local
U — undefined (needs to be provided at link time)
W / w — weak symbol
4. Sections: readelf
readelf -h prog
readelf -S prog
readelf -l prog
readelf -d prog
readelf -s prog
readelf -r prog
readelf -n prog
readelf --debug-dump=info prog | head -100
readelf -a prog
5. Disassembly and source: objdump
objdump -d prog
objdump -d -M intel prog
objdump -d -S prog
objdump -d prog | awk '/^[0-9a-f]+ <main>:/,/^$/'
objdump -D prog
objdump -f prog
objdump -p prog
6. Binary hardening check
checksec --file=prog
readelf -h prog | grep Type
readelf -d prog | grep GNU_RELRO
readelf -d prog | grep BIND_NOW
readelf -s prog | grep __stack_chk
readelf -l prog | grep GNU_STACK
7. Section size analysis (binary bloat)
size --format=sysv prog | sort -k2 -nr | head -20
bloaty prog
file prog
strip --strip-all -o prog.stripped prog
ls -lh prog prog.stripped
8. Build ID
Build IDs uniquely identify a binary/library build, enabling debuginfod lookups.
readelf -n prog | grep 'Build ID'
file prog | grep BuildID
9. Common diagnosis flows
"undefined symbol at runtime"
nm -D libfoo.so | grep mysymbol
ldd ./prog | grep libfoo
"binary is too large"
size --format=sysv prog | sort -k2 -nr | head
nm -S --defined-only prog | sort -k2 -nr | head -20
objdump -d prog | awk '/^[0-9a-f]+ </{fn=$2} /^[0-9a-f]/{count[fn]++} END{for(f in count) print count[f], f}' | sort -nr | head -20
For a quick reference, see references/cheatsheet.md.
Related skills
- Use
skills/binaries/linkers-lto for linker flags and LTO
- Use
skills/binaries/binutils for ar, strip, objcopy, addr2line
- Use
skills/debuggers/core-dumps for build ID and debuginfod usage