Show number of padding bytes in data structures

Paul Koning pkoning@equallogic.com
Wed May 2 16:11:00 GMT 2007


>>>>> "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



More information about the Binutils mailing list