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
2009-05-26 19:49:11
+6
A:
The size
utility will report that, under "data".
> size ./my_program
Shmoopty
2009-05-26 19:53:30
+1 for size, which nails it!
dwc
2009-05-26 19:55:38
+1
A:
Yes. Use...
objdump -h progfile
which will list the "headers". Find the .data
header and check the size column.
dwc
2009-05-26 19:53:58