Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find size of static allocations from binary?

Tags:

c++

c

linux

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.

like image 934
Mike Bishop Avatar asked May 26 '09 19:05

Mike Bishop


2 Answers

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

> size ./my_program
like image 102
Drew Dormann Avatar answered Oct 02 '22 05:10

Drew Dormann


Yes. Use...

objdump -h progfile

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

like image 25
dwc Avatar answered Oct 02 '22 04:10

dwc