The symbol table lists the names the object defines and the ones it needs. It starts at the file header’s PointerToSymbolTable and has NumberOfSymbols records of 18 bytes each. A record may be followed by auxiliary records, which are the same size and count towards NumberOfSymbols, so a relocation’s symbol index can point past them.
The symbol record
IMAGE_SYMBOL, 18 bytes:
0Name: 8 bytes, or 4 zero bytes and a string table offset8 bytes8Value4 bytes12SectionNumber2 bytes14Type2 bytes16StorageClass1 byte17NumberOfAuxSymbols1 byte
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 8 | Name | A union of three structures. A name of up to 8 bytes is stored in the field itself (ShortName), padded with nulls on the right if shorter than 8. Otherwise the first 4 bytes (Zeroes) are all zero and the second 4 bytes (Offset) are an offset into the string table; to tell the two apart, test whether the first 4 bytes equal zero. By convention names are zero-terminated UTF-8 strings. |
| 8 | 4 | Value | The value associated with the symbol; its interpretation depends on SectionNumber and StorageClass (a typical meaning is the relocatable address). See the storage class table. |
| 12 | 2 | SectionNumber | A signed integer: a one-based index into the section table, or one of the special values below (zero or negative). |
| 14 | 2 | Type | The low byte is the base type and the high byte the complex (derived) type; see Type representation. Microsoft tools set it to 0x20 (function) or 0x0 (not a function). This must be set correctly for functions: incremental linking depends on it. |
| 16 | 1 | StorageClass | What kind of symbol it is; see Storage classes. |
| 17 | 1 | NumberOfAuxSymbols | How many auxiliary records follow. |
| SectionNumber | Meaning |
|---|---|
0 | IMAGE_SYM_UNDEFINED: the symbol is not yet assigned a section. A Value of zero indicates a reference to an external symbol defined elsewhere; a non-zero Value indicates a common symbol whose size is the value. |
−1 | IMAGE_SYM_ABSOLUTE: the symbol has an absolute (non-relocatable) value and is not an address |
−2 | IMAGE_SYM_DEBUG: the symbol provides general type or debugging information but does not correspond to a section; Microsoft tools use this with .file records (storage class FILE) |
The symbol table is an array of 18-byte records. Zero or more auxiliary records immediately follow each standard record (typically no more than one, except for .file records with long names); an auxiliary record gives additional information on the last symbol defined, and the format used depends on the storage class. Tools that read the symbol table must ignore auxiliary records whose interpretation is unknown, so that new formats can be added. The symbol table is distinct from Visual C++ debug information (CodeView); a file can contain both, kept separate, and Microsoft tools use the symbol table only for limited purposes such as passing COMDAT information to the linker. (PE Format.)
Type representation
The Type field holds a base data type and a complex (derived) type. PE Format describes
them as the “LSB” and the “MSB” of the field, but it also says Microsoft tools write only
0x0 and 0x20 for a function, and 0x20 cannot be a
value in the high byte of a 16-bit field. LLVM’s COFF.h resolves this:
“Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT))” with the shift
equal to 4. So the base type is the low 4 bits (values 0 to 15) and the complex type
starts at bit 4. Microsoft tools generally leave the base type 0 and use Visual C++
debug information instead; the values are listed for completeness.
| Base value | Constant | Meaning |
|---|---|---|
| 0 | IMAGE_SYM_TYPE_NULL | No type information or unknown base type (what Microsoft tools use) |
| 1 | IMAGE_SYM_TYPE_VOID | No valid type; used with void pointers and functions |
| 2 | IMAGE_SYM_TYPE_CHAR | A character (signed byte) |
| 3 | IMAGE_SYM_TYPE_SHORT | A 2-byte signed integer |
| 4 | IMAGE_SYM_TYPE_INT | A natural integer type (normally 4 bytes in Windows) |
| 5 | IMAGE_SYM_TYPE_LONG | A 4-byte signed integer |
| 6 | IMAGE_SYM_TYPE_FLOAT | A 4-byte floating-point number |
| 7 | IMAGE_SYM_TYPE_DOUBLE | An 8-byte floating-point number |
| 8 | IMAGE_SYM_TYPE_STRUCT | A structure |
| 9 | IMAGE_SYM_TYPE_UNION | A union |
| 10 | IMAGE_SYM_TYPE_ENUM | An enumerated type |
| 11 | IMAGE_SYM_TYPE_MOE | A member of enumeration (a specific value) |
| 12 | IMAGE_SYM_TYPE_BYTE | A byte; unsigned 1-byte integer |
| 13 | IMAGE_SYM_TYPE_WORD | A word; unsigned 2-byte integer |
| 14 | IMAGE_SYM_TYPE_UINT | An unsigned integer of natural size (normally 4 bytes) |
| 15 | IMAGE_SYM_TYPE_DWORD | An unsigned 4-byte integer |
| Complex value | Constant | Meaning |
|---|---|---|
| 0 | IMAGE_SYM_DTYPE_NULL | No derived type; a simple scalar variable |
| 1 | IMAGE_SYM_DTYPE_POINTER | A pointer to the base type |
| 2 | IMAGE_SYM_DTYPE_FUNCTION | A function that returns the base type |
| 3 | IMAGE_SYM_DTYPE_ARRAY | An array of the base type |
So 0x20 is complex type 2 (function) with base type 0. Other tools may write other values; Microsoft’s specification says so (“other tools can use this field to communicate more information”).
Storage classes
| Value | Constant | Meaning |
|---|---|---|
| −1 (0xFF) | IMAGE_SYM_CLASS_END_OF_FUNCTION | A special symbol that represents the end of a function, for debugging purposes |
| 0 | IMAGE_SYM_CLASS_NULL | No assigned storage class |
| 1 | IMAGE_SYM_CLASS_AUTOMATIC | An automatic (stack) variable; Value is the stack frame offset |
| 2 | IMAGE_SYM_CLASS_EXTERNAL | What Microsoft tools use for external symbols. When SectionNumber is IMAGE_SYM_UNDEFINED (0), Value is the size; otherwise Value is the offset within the section |
| 3 | IMAGE_SYM_CLASS_STATIC | Value is the offset of the symbol within the section; if Value is zero, the symbol represents a section name |
| 4 | IMAGE_SYM_CLASS_REGISTER | A register variable; Value is the register number |
| 5 | IMAGE_SYM_CLASS_EXTERNAL_DEF | A symbol that is defined externally |
| 6 | IMAGE_SYM_CLASS_LABEL | A code label defined within the module; Value is the offset within the section |
| 7 | IMAGE_SYM_CLASS_UNDEFINED_LABEL | A reference to a code label that is not defined |
| 8 | IMAGE_SYM_CLASS_MEMBER_OF_STRUCT | A structure member; Value is the nth member |
| 9 | IMAGE_SYM_CLASS_ARGUMENT | A formal argument (parameter) of a function; Value is the nth argument |
| 10 | IMAGE_SYM_CLASS_STRUCT_TAG | The structure tag-name entry |
| 11 | IMAGE_SYM_CLASS_MEMBER_OF_UNION | A union member; Value is the nth member |
| 12 | IMAGE_SYM_CLASS_UNION_TAG | The union tag-name entry |
| 13 | IMAGE_SYM_CLASS_TYPE_DEFINITION | A typedef entry |
| 14 | IMAGE_SYM_CLASS_UNDEFINED_STATIC | A static data declaration |
| 15 | IMAGE_SYM_CLASS_ENUM_TAG | An enumerated type tag-name entry |
| 16 | IMAGE_SYM_CLASS_MEMBER_OF_ENUM | A member of an enumeration; Value is the nth member |
| 17 | IMAGE_SYM_CLASS_REGISTER_PARAM | A register parameter |
| 18 | IMAGE_SYM_CLASS_BIT_FIELD | A bit-field reference; Value is the nth bit in the bit field |
| 100 | IMAGE_SYM_CLASS_BLOCK | A .bb (beginning of block) or .eb (end of block) record; Value is the relocatable address of the code location |
| 101 | IMAGE_SYM_CLASS_FUNCTION | Records that define the extent of a function: .bf (begin function), .ef (end function) and .lf (lines in function). For .lf records Value is the number of source lines in the function; for .ef records, the size of the function code |
| 102 | IMAGE_SYM_CLASS_END_OF_STRUCT | An end-of-structure entry |
| 103 | IMAGE_SYM_CLASS_FILE | The source-file symbol record; auxiliary records that name the file follow it |
| 104 | IMAGE_SYM_CLASS_SECTION | A definition of a section (Microsoft tools use STATIC instead) |
| 105 | IMAGE_SYM_CLASS_WEAK_EXTERNAL | A weak external; see the weak external format below |
| 107 | IMAGE_SYM_CLASS_CLR_TOKEN | A CLR token symbol; its name is an ASCII string of the hexadecimal value of the token (see the CLR token format below) |
StorageClass is an unsigned byte, so −1 means 0xFF. Microsoft tools rely on Visual C++ debug information for most symbolic information and generally use only four classes: EXTERNAL (2), STATIC (3), FUNCTION (101) and FILE (103). Sources: PE Format, Storage Class; LLVM COFF.h has the same values (and gives 0xFF as an invalid marker, SSC_Invalid).
Auxiliary record formats
Each is one record the size of a symbol (18 bytes must be allocated so the table stays
an array of regular size). Its layout depends on the symbol before it. Auxiliary records
always follow, and apply to, a standard record. Microsoft tools recognise formats for:
function definitions, function begin and end symbols (.bf and
.ef), weak externals, file names and section definitions (plus the CLR
token format below). The traditional COFF design also has auxiliary formats for arrays and
structures; Microsoft tools do not use them but place that information in Visual C++
debug format. A reader must ignore an auxiliary record whose format it does not know.
Section definition
After a symbol that defines a section: its name is the section’s name (such as .text or .drectve) and its storage class is STATIC (3). The record duplicates some of the information in the section header.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | Length | The size of the section data; the same as SizeOfRawData in the section header |
| 4 | 2 | NumberOfRelocations | The number of relocation entries for the section |
| 6 | 2 | NumberOfLinenumbers | The number of line-number entries for the section |
| 8 | 4 | CheckSum | The checksum for communal data; applicable if IMAGE_SCN_LNK_COMDAT is set in the section header (see COMDAT). PE Format does not say how it is computed |
| 12 | 2 | Number | One-based index into the section table for the associated section; used when the COMDAT selection is 5 (associative). In a bigobj file LLVM reads the high 16 bits of this number from offset 16 |
| 14 | 1 | Selection | The COMDAT selection number, applicable if the section is a COMDAT section |
| 15 | 3 | Unused | PE Format: unused (in LLVM’s layout, byte 15 is unused and bytes 16 and 17 are the high part of Number in a bigobj file) |
Function definition
After a symbol that marks the beginning of a function definition: storage class EXTERNAL (2), a Type that indicates a function (0x20) and a section number greater than zero. A record with section number UNDEFINED (0) does not define the function and has no auxiliary record.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | TagIndex | The symbol-table index of the corresponding .bf (begin function) record |
| 4 | 4 | TotalSize | The size of the executable code of the function itself; if the function is in its own section, SizeOfRawData in the section header is greater than or equal to this, depending on alignment |
| 8 | 4 | PointerToLinenumber | The file offset of the first COFF line-number entry for the function, or 0 if none exists |
| 12 | 4 | PointerToNextFunction | The symbol-table index of the record for the next function; 0 if this is the last in the symbol table |
| 16 | 2 | Unused |
.bf and .ef records
For each function definition, three symbols with storage class FUNCTION (101) describe its beginning, end and line count: .bf (the Value field is unused), .lf (Value is the number of lines in the function) and .ef (Value equals the TotalSize of the function-definition record). The .bf and .ef records, but not .lf, are followed by an auxiliary record:
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | Unused | |
| 4 | 2 | Linenumber | The actual ordinal line number (1, 2, 3 and so on) within the source file, corresponding to the .bf or .ef record |
| 6 | 6 | Unused | |
| 12 | 4 | PointerToNextFunction | In .bf only: the symbol-table index of the next .bf record, 0 if the function is the last; not used for .ef |
| 16 | 2 | Unused |
Weak external
A module can contain an unresolved external symbol (sym1) with an auxiliary record saying that, if sym1 is not present at link time, another external symbol (sym2) resolves references instead. If a definition of sym1 is linked, references resolve normally; if not, all references to the weak external for sym1 refer to sym2. sym2 must always be linked; typically it is defined in the module that holds the weak reference. A weak external is a symbol with EXTERNAL storage class, UNDEF section number and a value of zero, followed by this record:
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | TagIndex | The symbol-table index of sym2, the symbol to link if sym1 is not found |
| 4 | 4 | Characteristics | 1 IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY: no library search for sym1 is performed; 2 SEARCH_LIBRARY: a library search for sym1 is performed; 3 SEARCH_ALIAS: sym1 is an alias for sym2. (PE Format gives the names; the numbers 1 to 3 are from LLVM’s COFF.h, which also defines 4 IMAGE_WEAK_EXTERN_ANTI_DEPENDENCY, a value PE Format does not list and gives no meaning for.) PE Format adds that the field is not defined in WINNT.H, where the Total Size field is used instead |
| 8 | 10 | Unused |
File name
After a symbol with storage class FILE (103) whose name should be .file: an 18-byte ANSI string naming the source file, padded with nulls if shorter. A name longer than 18 bytes continues over more auxiliary records (PE Format says only that .file records with long names have more than one; the continuation is not otherwise specified).
CLR token
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 1 | bAuxType | Must be IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF (1) |
| 1 | 1 | bReserved | Reserved, must be zero |
| 2 | 4 | SymbolTableIndex | The symbol index of the COFF symbol to which this CLR token definition refers |
| 6 | 12 | Reserved | Reserved, must be zero |
The string table
It comes immediately after the symbol table, at the offset PointerToSymbolTable plus 18 times NumberOfSymbols. It starts with a 4-byte size, counting those 4 bytes: an empty table has the value 4. The strings follow, each ending with a zero byte. A long symbol name or section name holds an offset from the start of this table, so the first string is at offset 4.