| name | binutils |
| description | GNU binutils skill for binary manipulation and analysis. Use when using ar for static libraries, strip or objcopy for binary processing, addr2line for converting addresses to source locations, strings for text extraction, or c++filt for C++ name demangling. Activates on queries about ar, strip, objcopy, addr2line, strings, c++filt, ranlib, or binary post-processing tasks. |
GNU Binutils
Purpose
Guide agents through the binutils toolset for binary manipulation: static libraries, stripping, address-to-source mapping, and symbol demangling.
Triggers
- "How do I create a static library?"
- "How do I strip a binary but keep a debug file?"
- "I have an address from a crash — how do I find the source line?"
- "How do I demangle a C++ symbol name?"
- "How do I extract/replace sections in a binary?"
Workflow
1. ar — static library management
ar rcs libfoo.a foo.o bar.o baz.o
ar t libfoo.a
ar x libfoo.a foo.o
ar r libfoo.a newbar.o
ar d libfoo.a oldbar.o
nm libfoo.a
ranlib libfoo.a
For LTO archives: use gcc-ar/gcc-ranlib or llvm-ar instead of plain ar.
2. strip — remove debug info
strip --strip-all prog
strip --strip-debug prog
strip --strip-unneeded prog
strip prog
strip -o prog.stripped prog
3. objcopy — binary section manipulation
objcopy --only-keep-debug prog prog.debug
objcopy --strip-debug prog
objcopy --add-gnu-debuglink=prog.debug prog
objcopy -O binary prog prog.bin
objcopy -O srec prog prog.srec
objcopy --add-section .resources=data.bin prog
objcopy --remove-section .comment prog
objcopy --set-section-flags .data=alloc,contents,load,readonly prog
objcopy -I binary -O elf64-x86-64 \
--rename-section .data=.rodata,alloc,load,readonly,data,contents \
data.bin data.o
4. addr2line — address to source
addr2line -e prog -f 0x400a12
addr2line -e prog -f 0x400a12 0x400b34 0x400c56
addr2line -e prog -f -i 0x400a12
cat crash.log | grep '0x[0-9a-f]' | grep -o '0x[0-9a-f]*' | \
addr2line -e prog -f -i
Requires the binary to have debug info (compiled with -g). For stripped binaries, use the unstripped version or a .debug file.
5. c++filt — demangle C++ symbols
c++filt _ZN3foo3barEv
nm prog | c++filt
cat crash.log | c++filt
Alternative: nm -C prog (demangle directly in nm).
6. strings — extract printable strings
strings prog
strings -n 8 prog
strings -t x prog
strings -t d prog
strings prog | grep "version"
strings prog | grep "Copyright"
7. readelf and objdump quick reference
(Full coverage in skills/binaries/elf-inspection)
objdump -d -M intel prog | grep -A5 "400a12:"
objdump -t prog | grep my_function
8. Cross-binutils
For cross-compilation, use the target-prefixed versions:
aarch64-linux-gnu-strip prog
aarch64-linux-gnu-objcopy --only-keep-debug prog prog.debug
aarch64-linux-gnu-addr2line -e prog 0x400a12
arm-none-eabi-nm libfirmware.a
For a complete command cheatsheet covering all tools (ar, strip, objcopy, addr2line, strings, c++filt), see references/cheatsheet.md.
Related skills
- Use
skills/binaries/elf-inspection for readelf, nm, ldd, objdump inspection
- Use
skills/binaries/linkers-lto for linker flags and LTO
- Use
skills/debuggers/core-dumps for debug file management with objcopy --add-gnu-debuglink