gnu binutils

I decided to read through the man pages of binutils, to see if there's something interesting I've never come across. The only things that were not previously very familiar were the c++filt and addr2line tools. Anyway, here are the notes I made while reading about each of the tools in the binutils package.

ar and ranlib
manage archives: static libraries of compiled object files. Most often these are used indirectly through libtool and automake.

nm
Lists symbols from object files.
This is useful when troubleshooting linking problems. With nm you can check which data and functions are actually found in each intermediate object or library.

objcopy
Copies and converts object files.
Typical use of objcopy is to convert and ELF file into a binary file. This is effectively pre-computing the work of an elf loader for targets where elf loader is not relevant at run time, like ROM code.
Objcopy can also work the other way. Objcopy can wrap a binary file in an elf object, so that binary data can be embedded into application during linking. However, this is ofthen done by dumping the binary as a C source (xxd -i) and then compiling it into an object, which is often easier and more portable.
Objcopy can also transform objects within a single format. It can strip sections or transform symbol names (--prefix-symbols=string).

objdump
Displays the contents of an object file.
Objdump (-d) can disassemble an object, to take a look what the compiler actually produced.
Objdump (-t) lists the symbols and their sizes in an ELF file. Sort this list and see where to focus your size optimization efforts first.

size
displays the text, data, bss segment sizes of an object file. A good sanity check if working with limited memory target.

strings
Displays anything that resembles text. Good for first look at foreign binaries.

strip
Slims down an object file by removing all that is not necessary for loading and relocating the binary. Symbols and debugging information are removed by default. Manually it is possible to remove any specific sections.

c++filt
Interprets c++ mangled symbols. Individual command line arguments can be demangled, or c++filt can filter symbols found in the middle of a stdin/out stream.

add2line
Traces addresses in a binary back to source files, functions and line numbers. Optionally demangling symbols like c++filt.

readelf
Interprets the tructure of an ELF binary file.
-h shows the file header: for which machine the file is for
-l shows the segments/program headers: what to load into memory
-S shows the sections
-s shows the symbols


I decided to skip the windows-specific tools. Instead, I should some day match these up with Mach-O specific tools.

Comments

Popular posts from this blog

iMovie event library on a network drive, NAS

Proxmox PCIe passthrough on HP gen8 - failed to set iommu for container

Backup and restore observium