GNU/Linux Application Programming (Programming Series)

In this final section, we ll look at some of the other GNU tools (usually called binutils ) that help us in the development process.

First, how can we identify how large our executable image or intermediate object is? The size utility emits the text size (instruction count) and also the data and bss segments. Consider this example:

$ size test.o text data bss dec hex filename 789 256 4 1049 419 test.o $

Here we request the size of our intermediate object file, test.o . We find that the text size (instructions and constants) is 789 bytes, the data segment is 256 bytes, and the bss segment (which will be automatically initialized to zero) is 4 bytes. If we want more detailed information on the image, we can use the objdump utility. We can explore the symbol table of the image or object using the -syms argument, as:

$ objdump -syms test.o

This results in a list of symbols available in the object, their type ( text , bss , data ), lengths, offset, and so on. We can also disassemble the image using the ”disassemble argument, as:

# objdump disassemble test.o

This provides a list of the functions found in the object, along with the instructions that were generated for each by GCC.

Finally, the nm utility can also be used to understand the symbols that are present in an object file. This utility lists not only each symbol but also detailed information on the type of the symbol. Numerous other options are available, which can be found in the nm main page.

Категории