Some sections are read by the linker rather than loaded by a program. They are told apart by their names and flags.
.drectve: linker directives
A section is a directive section if it has the IMAGE_SCN_LNK_INFO flag set
and the name .drectve. It holds a string of text that can be encoded as ANSI
or UTF-8; if the UTF-8 byte order mark (EF BB BF) is not present, the string
is interpreted as ANSI. The string is a series of linker options separated by spaces; PE
Format says each option contains a hyphen, the option name and any attribute (linkers in
practice also accept the slash form such as /DEFAULTLIB:"LIBCMT", which is
how real files are written; that is an observation, not from the specification). An
option that contains spaces must be enclosed in quotes. The section must not have
relocations or line numbers. The linker removes it after processing, so it does not
appear in the image.
A typical one reads /DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES": the
compiler telling the linker which runtime libraries to search. The options themselves
are those of the linker (for example /EXPORT or /INCLUDE); their
full list is the linker’s documentation, not part of the object file format.
CodeView debug sections
PE Format says only that .debug$S holds Visual C++ debug information (symbolic
information), .debug$T the type information and .debug$P
precompiled types shared by all objects compiled with the precompiled header that was
generated with this object; the linker gathers the data of all of them, with
.debug$F, into the PDB file. The contents are the CodeView format, which is
a separate specification (Microsoft’s cvinfo.h in the public
microsoft-pdb repository, and LLVM’s llvm/DebugInfo/CodeView);
the explanation below is from those two sources, not from PE Format, and the
individual symbol and type records are not described on this site. The sections start
with a 4-byte signature: 4 is CV_SIGNATURE_C13 (“C13 (vc7.x) zero terminated names”);
the older values are 0 (C6), 1 (C7) and 2 (C11, vc5.x 32-bit types), and 5 to 64K are
reserved (cvinfo.h).
.debug$S: symbols and lines
After the signature come subsections, each padded to a multiple of 4 bytes:
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | Kind | What the subsection holds. If bit 31 (0x80000000, DEBUG_S_IGNORE) is set, the subsection contents are ignored. |
| 4 | 4 | Length | The size of the contents |
| 8 | Length | Contents |
| Kind | Name | Holds |
|---|---|---|
0xF1 | DEBUG_S_SYMBOLS | CodeView symbol records |
0xF2 | DEBUG_S_LINES | Line numbers |
0xF3 | DEBUG_S_STRINGTABLE | A string table for file names |
0xF4 | DEBUG_S_FILECHKSMS | File names and their checksums |
0xF5 | DEBUG_S_FRAMEDATA | Stack frame information |
0xF6 | DEBUG_S_INLINEELINES | Line numbers of inlined functions |
0xF7 | DEBUG_S_CROSSSCOPEIMPORTS | Cross-scope imports |
0xF8 | DEBUG_S_CROSSSCOPEEXPORTS | Cross-scope exports |
0xF9 | DEBUG_S_IL_LINES | IL line numbers (LLVM: “appear to relate to .Net assembly info”) |
0xFA | DEBUG_S_FUNC_MDTOKEN_MAP | A function metadata token map |
0xFB | DEBUG_S_TYPE_MDTOKEN_MAP | A type metadata token map |
0xFC | DEBUG_S_MERGED_ASSEMBLYINPUT | Merged assembly input |
0xFD | DEBUG_S_COFF_SYMBOL_RVA | COFF symbol RVAs |
0xFF, 0x100 | (LLVM: XfgHashType, XfgHashVirtual) | Defined in LLVM’s CodeView.h but not in cvinfo.h, whose enum ends at 0xFD; LLVM gives no comment on them |
The contents of the subsections are not described on this site (they are CodeView, see
above). The padding of each subsection’s data to a multiple of 4 bytes is from LLVM’s
DebugSubsectionRecord.
A symbol record in DEBUG_S_SYMBOLS has a 2-byte length that doesn’t count itself and a 2-byte kind, such as 0x1110 (S_GPROC32, a function), 0x1101 (S_OBJNAME) or 0x113C (S_COMPILE3).
.debug$T: types
After the signature come type records, each a 2-byte length and a 2-byte kind, such as
0x1505 (LF_STRUCTURE), 0x1008 (LF_PROCEDURE) or
0x1203 (LF_FIELDLIST). When a build writes a program database with
/Zi, this section may instead hold a single LF_TYPESERVER2
record that points to the PDB file.
.debug$F, .debug$P: other debug sections
.debug$F (object only, x86 only, obsolete since Visual C++ 7.0, superseded by a .debug$S subsection) holds one or more FPO_DATA records (frame pointer omission information); the linker sorts them by procedure RVA and generates a debug directory entry for them, and the compiler should not generate FPO records for procedures with a standard frame. FPO_DATA is 16 bytes:
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | ulOffStart | Offset of the first byte of the function code |
| 4 | 4 | cbProcSize | Number of bytes in the function |
| 8 | 4 | cdwLocals | Number of bytes in locals, divided by 4 |
| 12 | 2 | cdwParams | Number of bytes in parameters, divided by 4 |
| 14 | 2 | bit field | Bits 0–7 cbProlog (bytes in the prolog); bits 8–10 cbRegs (registers saved); bit 11 fHasSEH (structured exception handling in the function); bit 12 fUseBP (EBP has been allocated); bit 13 reserved; bits 14–15 cbFrame (frame type: 0 FRAME_FPO, 1 FRAME_TRAP, 2 FRAME_TSS) |
The bit positions follow from the C declaration order in PE Format and the usual low-to-high allocation of bit fields by Microsoft’s compiler (inference; the specification gives the declaration but no bit table). .debug$P holds the precompiled types (see above).
Section names with a defined meaning
PE Format reserves these names. Tools and loaders recognise them by name, by flags in the section header, or by a pointer in the image optional header. A section marked “image only” can still appear in an object file as a way of getting into the image, but has no special meaning to the linker.
| Name | Content | Characteristics |
|---|---|---|
.bss | Uninitialised data | CNT_UNINITIALIZED_DATA, MEM_READ, MEM_WRITE |
.cormeta | CLR metadata; indicates the object contains managed code. The format of the metadata is not documented, but can be handed to the CLR interfaces | LNK_INFO |
.data | Initialised data | CNT_INITIALIZED_DATA, MEM_READ, MEM_WRITE |
.debug$F | Generated FPO debug information (object only, x86 only, obsolete) | CNT_INITIALIZED_DATA, MEM_READ, MEM_DISCARDABLE |
.debug$P | Precompiled debug types (object only) | CNT_INITIALIZED_DATA, MEM_READ, MEM_DISCARDABLE |
.debug$S | Debug symbols (object only) | CNT_INITIALIZED_DATA, MEM_READ, MEM_DISCARDABLE |
.debug$T | Debug types (object only) | CNT_INITIALIZED_DATA, MEM_READ, MEM_DISCARDABLE |
.drectve | Linker options (PE Format’s table spells it “.drective”) | LNK_INFO |
.edata | Export tables (image) | CNT_INITIALIZED_DATA, MEM_READ |
.idata | Import tables | CNT_INITIALIZED_DATA, MEM_READ, MEM_WRITE |
.idlsym | Registered SEH to support IDL attributes (image only) | LNK_INFO |
.pdata | Exception information | CNT_INITIALIZED_DATA, MEM_READ |
.rdata | Read-only initialised data | CNT_INITIALIZED_DATA, MEM_READ |
.reloc | Image relocations | CNT_INITIALIZED_DATA, MEM_READ, MEM_DISCARDABLE |
.rsrc | Resource directory | CNT_INITIALIZED_DATA, MEM_READ |
.sbss | GP-relative uninitialised data | CNT_UNINITIALIZED_DATA, MEM_READ, MEM_WRITE, GPREL (GPREL for IA64 only, object files only) |
.sdata | GP-relative initialised data | CNT_INITIALIZED_DATA, MEM_READ, MEM_WRITE, GPREL (IA64 only, object files only) |
.srdata | GP-relative read-only data | CNT_INITIALIZED_DATA, MEM_READ, GPREL (IA64 only, object files only) |
.sxdata | Registered exception handler data (x86, object only) | LNK_INFO |
.text | Executable code | CNT_CODE, MEM_EXECUTE, MEM_READ |
.tls, .tls$ | Thread-local storage (object only) | CNT_INITIALIZED_DATA, MEM_READ, MEM_WRITE |
.vsdata | GP-relative initialised data (ARM, SH4 and Thumb only) | CNT_INITIALIZED_DATA, MEM_READ, MEM_WRITE |
.xdata | Exception information | CNT_INITIALIZED_DATA, MEM_READ |
The image-only sections (.edata, .idata, .pdata,
.reloc, .rsrc, .tls contents, the load configuration structure and the debug
directory) are described by the PE32 pages, not here.
.sxdata and @feat.00: registered exception handlers (x86)
The valid exception handlers of an object are listed in its .sxdata section, marked IMAGE_SCN_LNK_INFO. It contains the COFF symbol index of each valid handler, 4 bytes per index; the symbol can be an UNDEF symbol or one defined in the module. The compiler also marks a COFF object as using registered SEH by emitting the absolute symbol @feat.00 with the least significant bit of its Value set to 1. An object with no registered handlers has the @feat.00 symbol but no .sxdata section. (PE Format.) PE Format documents only bit 0. LLVM’s COFF.h (Feat00Flags, which it says “appear to be some kind of compiler features bitfield read by link.exe”) lists more: 0x1 compatible with /safeseh, 0x100 compiled with /GS, 0x200 /sdl, 0x800 /guard:cf, 0x4000 /guard:ehcont, 0x40000000 /kernel. These meanings are LLVM’s observations, not Microsoft’s documentation.