Show number of padding bytes in data structures
Frank Winklmeier
frank.winklmeier@cern.ch
Wed May 2 16:21:00 GMT 2007
Paul Koning wrote:
>>>>>> "Frank" == Frank Winklmeier <frank.winklmeier@cern.ch> writes:
>
> Frank> Hi, is there any way of using one of the binutils to show the
> Frank> additional padding bytes that a compiler inserted into a
> Frank> struct/class to make it align according to the systems memory
> Frank> alignment rules? Or is this information lost once the compiler
> Frank> has done its job?
>
> Frank> For example, for the following data structure compiled on x64,
> Frank> I would expect the tool to tell me that the compiler added 4
> Frank> padding bytes:
>
> Frank> class MyData { int i; double d; };
>
> I don't know about any binutils. You can easily do this in gdb if
> your binary still contains the necessary debug data.
>
> For example:
>
> print ((int)(((MyData *)0)->d))-((int)((((MyData *)0)->i)+1))
>
> will do the job for the example you gave.
>
> paul
>
Hi Paul,
thanks for your reply. I was hoping for a more efficient way for a large
number of classes and structs. Ideally, I would like to compare the
number of padding bytes for a library compiled in 32 and 64 bit and see
how many bytes got wasted for each data structure due to the different
memory alignment.
Frank
More information about the Binutils
mailing list