I'm trying to reduce the size of an executable (using MINGW/GCC) by finding all large statically declared arrays. Is there a way to dump the list of data symbols along with their aggregate sizes?? I've looked at man pages for nm and objdump but dont see anything useful so far.
Thx.
Use the nm
utility from GNU binutils with the --print-size
option (abbreviated -S
). For example, to find the 20 largest symbols in an object file, do this:
nm --print-size --size-sort objfile.o | tail -20
The linker can generate a MAP file which will provide that information.
If you are using gcc to compile and link, you pass linker options to the linker with:
-Wl,<comma-separate-options-list>
If calling ld directly, you obviously just pass the linker options.
The linker option you need is:
-Map=<mapfilename>
You may also use --cref
to include a cross-reference table in the map file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With