[cfe-dev] calculating binary layout of c++ classes for various compilers and operating systems

chris nuernberger cnuernber at gmail.com
Tue Sep 14 09:28:19 PDT 2010


Hey All,

I need to take some sort of compiler-independent description of a c++
object and be able to interpret that object in memory or in a file,
including endian conversions and details around packing and such.

I don't need to reconstitute the vtable pointers myself, the compiler
can do that.  I would like to be able to do something like this:

save out an object compiled with MS VC++ using fwrite( &object,
sizeof(object)) on Windows.

In a third-party program read the object in and write out an object.

On a PS3 (some odd version of gcc), fread the object into memory, then
apply a trivial constructor to build up correct vtable ptrs and go
merrily on my way.

This will mean swizzling member variables (endian conversion) and
could perhaps mean a lot more complex translation than that depending
on the differences among the compilers.

Does anyone have specific experience with the actual object binary
layouts of the different compilers?  Where is the code that builds the
actual binary layouts in clang?  I was told it was later, in the code
gen phase.  I will probable want to use it as a template or reference.

Chris

-- 
A foolish consistency is the hobgoblin of little minds - Emerson



More information about the cfe-dev mailing list