Tracy
Tracy

Reputation: 59

What does xdata section do?

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.

Upvotes: 2

Views: 3159

Answers (2)

Carlo Kok
Carlo Kok

Reputation: 1168

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.

Upvotes: 5

SoronelHaetir
SoronelHaetir

Reputation: 15162

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.

Upvotes: 0

Related Questions