tags:

views:

196

answers:

4

I want to be able to get an estimate of how much code & static data is used by my C++ program?

Is there a way to find this out by looking at the executable or object files? Or perhaps something I can do at runtime?

Will objdump & readelf help?

+1  A: 

readelf will indeed help. You can use the -S option; that will show the sizes of all sections. .text is (the bulk of) your executable code. .data and .rodata is your static data. There are other sections too, some of which are used at runtime, others only at link time.

Chris Jester-Young
+4  A: 

"size" is the traditional tool. "readelf" has a lot of options.

$ size /bin/sh
   text    data     bss     dec     hex filename
 712739   37524   21832  772095   bc7ff /bin/sh
Mark Harrison
+1  A: 

If you want to take the next step of identifying the functions and data structures to focus on for footprint reduction, the --size-sort argument to nm can show you:

$ nm --size-sort /usr/bin/fld | tail -10
000000ae T FontLoadFontx
000000b0 T CodingByRegistry
000000b1 t ShmFont
000000ec t FontLoadw
000000ef T LoadFontFile
000000f6 T FontLoadDFontx
00000108 D fSRegs
00000170 T FontLoadMinix
000001e7 T main
00000508 T FontLoadBdf
DGentry
A: 
size -A
jfm3