2

I have a simple hello world program and after i dumpbin it with /headers flag, i get this output:

FILE HEADER VALUES
            8664 machine (x64)
               D number of sections
        5A3D287F time date stamp Fri Dec 22 18:45:03 2017
             48F file pointer to symbol table
              2D number of symbols
               0 size of optional header
               0 characteristics

Summary

           F .data
          A0 .debug$S
          2F .drectve
          24 .pdata
          B9 .text$mn
          18 .xdata

What exactly xdata section do and what it contains? No info on msdn.

Tracy
  • 59
  • 1
  • 8
  • 1
    Do you know if your simple program source is C or C++? Do you know the difference? – Jongware Dec 22 '17 at 18:26
  • 2
    @usr2564301 what's your point? i'm compiling the program with /TC. – Tracy Dec 22 '17 at 18:31
  • The point is that C and C++ are different languages! If you don't know what you are using, then look at the file extension of your source code. If it's `.c` then you are programming in C. If it's `.cpp` then you are using C++. Check and delete the inappropriate tag. – Jongware Dec 22 '17 at 18:39
  • Good question @Tracy. I am looking now at an exe file for a c program and it has an xdata section. Did you ever get any info on what an xdata section is? – Roger Costello Oct 05 '19 at 12:57
  • @Jongware C++ is just a bunch of abstraction bloat over C, so they are the same languages at the core. – ScienceDiscoverer Aug 06 '22 at 11:38

2 Answers2

4

For future reference:

  • .text: codesegment (think functions); there can be multiple of those when enabling function sections or when comdat is involved (for example templates)
  • .data: datasegment (think global vars); there can be multiple of those when enabling data sections or when comdat is involved (for example templates)
  • .bss: datasegment initialized to zeros (not present above); there can be multiple of those when enabling data sections or when comdat is involved (for example templates)
  • .debug: Debug info; like others, there can be multiple of these when function sections are involved.
  • .pdata: for x86_64, this is the "exception info" for a method, it defines the start/end of a function, and a pointer to the unwind info (see .xdata); inside object files this is duplicated per function
  • .drectve: not sure; but from the name I'd guess linker directives.
  • .xdata: for x86_64; this is the unwind info part that pdata points to. It contains where the exception handler of a function is, and what to do to unwind it when an exception occurs: https://learn.microsoft.com/en-us/cpp/build/exception-handling-x64?view=vs-2019

The "$" postfix is used for sorting. Given: - .sec$z - .sec$data - .sec$a

The sections are sorted before they are merged into an executable (so .sec$a first, then data, then z), this can be used to create start/end symbols to a pe section.

Carlo Kok
  • 1,128
  • 5
  • 14
0

The repeated sections are for things like c++ templates, the compiler will instantiate a template in any translation unit that needs it and then the linker will pick one of those instantiations (usually the first encountered).

Less common are compiler-specific features like Microsoft's __declspec(selectany) that allow a variable to be defined more than once and again the linker will simply pick one of those definitions and discard the rest.

gcc's ld scripts will take all the .text* sections to create the final .text of the linked executable. You can examine those scripts to get an idea of how the linker creates an executable out of object files.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23