dumping C structure sizes from ELF object file

Ray Balogh picture Ray Balogh · May 10, 2011 · Viewed 12.1k times · Source

How can you extract the sizes of all C structures from an ELF object file with debugging symbols?

Individual struct sizes can be obtained from GDB using "print sizeof(some_struct)", but what I need is to get a listing of all structures.

I've looked at "nm" and "objdump", but I don't see options to do what I'm looking for. Is there a way to do this with standard Unix tools, or do I need to extract the debug symbol section from the ELF file and process it myself? I'm hoping it's not the latter.

Thanks in advance for any advice. Ray

Answer

ninjalj picture ninjalj · May 10, 2011

pahole shows this and other details about structs. Its git repo is at http://www.kernel.org/git/?p=linux/kernel/git/acme/pahole.git;a=summary.