Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layout of compiled objects

Is there a way—much like viewing the result of preprocessing with gcc -E—to see what my objects look like once compiled into object files?

I am talking about GCC, but a solution including MSVC would be fine.

like image 556
user257620 Avatar asked Jan 26 '10 10:01

user257620


2 Answers

For Visual C++:

I finally managed to dig up the (well-hidden!) undocumented compiler flags that MSVC++ supports using information from here and here. Here they are:

/d1reportSingleClassLayoutXXX
/d1reportAllClassLayout

(replace XXX with the class name)

like image 100
j_random_hacker Avatar answered Nov 04 '22 12:11

j_random_hacker


For GCC compiled executables, checkout Pahole. It will show you how the compiler laid out your structs/classes and whether or not they have "holes" in them. Holes are padding due to memory alignment rules.

like image 7
paxos1977 Avatar answered Nov 04 '22 11:11

paxos1977