ELF structure (readelf)
readelf -h <elf>
ELF header: type, arch, entry
readelf -S <elf>
Section headers
readelf -l <elf>
Program headers (segments)
readelf -d <elf>
Dynamic section: NEEDED, RPATH
readelf -s -W <elf>
Symbol tables, wide lines
readelf --dyn-syms <elf>
Dynamic symbols only
readelf -r <elf>
Relocations
readelf -n <elf>
Notes such as the build ID
readelf -p .comment <elf>
Dump a section as strings
Shows the compiler that built the file.
readelf -x .rodata <elf>
Hex dump of a section
readelf --debug-dump=info <elf>
DWARF debug info
readelf -a <elf>
Everything at once
readelf -W <elf>
Do not wrap wide output
Disassembly (objdump)
objdump -d <file>
Disassemble code sections
objdump -d -C <file>
Disassemble, demangled names
objdump -d -M intel <file>
Intel syntax instead of AT&T
objdump -D <file>
Disassemble all sections, even data
objdump -S <file>
Interleave source (needs -g)
objdump -d --no-show-raw-insn <file>
Hide the opcode bytes
objdump -d --disassemble=<sym> <file>
Only one function
Older releases lack the =<sym> form; use -d and grep -A
there.
objdump -d --start-address=<a>
--stop-address=<b> <file>
Only an address range
objdump -h <file>
Section headers with sizes
objdump -x <file>
All headers
objdump -t <file>
Symbol table
objdump -T <file>
Dynamic symbol table
objdump -R <file>
Dynamic relocations
objdump -s -j <sect> <file>
Hex dump of one section
objdump -p <file>
Private headers, NEEDED libs
objdump -r -d <obj.o>
Show relocations inside code
objdump -f <file>
File header, start address
Addresses and libraries
addr2line -e <elf> <addr>
Address to file:line
addr2line -e <elf> -f -C -i <addr>
Add function, demangle, inlines
addr2line -e <lib.so> -a <off>
Print address, for shared lib offsets
PIE and .so crashes log runtime addresses: subtract the load
base first.
ldd <bin>
Shared libs it needs
ldd -v <bin>
Also versions required
ldd -r <bin>
Report missing functions too
readelf -d <bin> | grep NEEDED
Direct dependencies, no execution
Safe alternative to ldd on untrusted files.
objdump -p <bin> | grep -E
'NEEDED|RPATH|RUNPATH'
Libs and search paths
file <bin>
Type, arch, stripped or not
Strip, copy, archives
strip <file>
Remove all symbols and debug info
strip --strip-debug <file>
Keep symbols, drop debug info
strip -o <out> <file>
Write result to another file
strip --strip-unneeded <file>
Drop symbols not needed for relocation
objcopy --only-keep-debug <elf> <elf>.dbg
Split debug info into a file
objcopy --add-gnu-debuglink=<elf>.dbg
<elf>
Point stripped binary at it
objcopy -O binary <elf> <out.bin>
Raw image of the sections
objcopy -j <sect> -O binary <elf>
<out>
Extract one section
ar t <lib.a>
List archive members
ar rcs <lib.a> <obj.o>...
Create or update static lib
ar x <lib.a> [<member>]
Extract members
ar d <lib.a> <member>
Delete a member
ar tv <lib.a>
Members with size and date
ranlib <lib.a>
Rebuild archive symbol index