tags:

views:

99

answers:

3

Is it possible to determine the total amount of memory dedicated to static and global variables from the binary? I'm looking for a Linux utility that reads an elf file and figures out how much memory is pre-allocated for variables.

+1  A: 

You can use the nm command (or objdump as suggested by @sharth). Using nm is more 'portable' in that it is available on non-Linux Unix systems too; it is not much more portable because the output format is not completely standardized (though it is defined by POSIX, there are several common variations on the output format).

Jonathan Leffler
+6  A: 

The size utility will report that, under "data".

> size ./my_program
Shmoopty
+1 for size, which nails it!
dwc
+1  A: 

Yes. Use...

objdump -h progfile

which will list the "headers". Find the .data header and check the size column.

dwc