Layout of compiled objects

后端 未结 6 664
余生分开走
余生分开走 2020-12-01 01:57

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

相关标签:
6条回答
  • 2020-12-01 02:10

    A constructor is just another function (unless it's in-lined). Object files contain a lot of info for the linker; so you should be able to find the function in the .a file (the function names will be mangled though).

    0 讨论(0)
  • 2020-12-01 02:11

    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.

    0 讨论(0)
  • 2020-12-01 02:19

    Your question is a little confusing.

    If you want to see the result of preprocessing with MSVC, you can use /E, /P/, or /EP.

    There's an undocumented option in MSVC to show the data layout of structures and classes. I'm having trouble finding it right now.

    0 讨论(0)
  • 2020-12-01 02:20

    Object files contain binary data - the only higher level that most compilers can output is assembler, so if you can't read that you are out of luck. However, take a look at this question for more info in this area.

    0 讨论(0)
  • 2020-12-01 02:22

    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)

    0 讨论(0)
  • 2020-12-01 02:27

    You can inspect the layout of binaries and their contents using map files. Use /MAP for VC and -Map or --print-map for gcc.

    0 讨论(0)
提交回复
热议问题