1

I am trying to estimate the code size of a binary's various components. I have access to the source code and resulting build directory containing all built object files. Of course, I want to include only the symbols that are actually used, so adding the sizes of the all the object file's .text and .data sections will end up overestimating actuals.

How can one determine the size and origin of all symbols used to link an ELF file? Something like this would be useful:

Symbol   Size   Origin
func1    0x50   ../src/func1.o
func2    0x75   ../src/func2.o
...

And something similar for all symbols that are .data. The resulting .map file seems to have some of this data, but it seems incomplete. Two sections that stand out are:

Allocating common symbols
Common symbol       size              file

s_Handle         0x8               ../BUILD/src/handle.o
_main_obj        0x48              ../BUILD/src/boot.o
....

But there are just a few dozen symbols listed here. The following section seems to have far more symbols, but it appears as if they are listed as being "Discarded" at link-time:

Discarded input sections

 .text          0x00000000        0x0 /home/user/.programs/gcc-arm-none-eabi-5_4-2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/armv7e-m/crti.o
 .data          0x00000000        0x0 /home/user/.programs/gcc-arm-none-eabi-5_4-2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/armv7e-m/crti.o
 .bss           0x00000000        0x0 /home/user/.programs/gcc-arm-none-eabi-5_4-2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/armv7e-m/crti.o
 .data          0x00000000        0x0 /home/user/.programs/gcc-arm-none-eabi-5_4-2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/crt0.o
 .bss           0x00000000        0x0 /home/user/.programs/gcc-arm-none-eabi-5_4-2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/crt0.o
 .ARM.extab     0x00000000        0x0 /home/user/.programs/gcc-arm-none-eabi-5_4-2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/crt0.o
 .text._Z12notify_startv
                0x00000000       0x14 ../BUILD/./test_env.o
 .text._Z30notify_performance_coefficientPKci
                0x00000000       0x18 ../BUILD/./test_env.o
 .text._Z30notify_performance_coefficientPKcj
                0x00000000       0x18 ../BUILD/./test_env.o
 .text._Z30notify_performance_coefficientPKcd
                0x00000000       0x20 ../BUILD/./test_env.o
 .text._Z17notify_completionb
                0x00000000       0x64 ../BUILD/./test_env.o
 .text._Z21notify_completion_strbPc
                0x00000000       0x30 ../BUILD/./test_env.o
...
1

You might want to use Bloaty McBloatface:

The "VM SIZE" column tells you how much space the binary will take when it is loaded into memory. The "FILE SIZE" column tells you about how much space the binary is taking on disk. [...] The default breakdown in Bloaty is by sections, but many other ways of slicing the binary are supported such as symbols and segments. If you compiled with debug info, you can even break down by compile units and inlines!

0

I can't comment so FYI: The Allocating common symbols section lists the names and sizes of the global variables in the program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.