Each row of the Section Table, in effect, is a section header. This table immediately follows the optional header, if any. This positioning is required because the file header does not contain a direct pointer to the section table; the location of the section table is determined by calculating the location of the first byte after the headers. Make sure to use the size of the optional header as specified in the file header. The number of entries in the Section Table is given by the NumberOfSections field in the file header. Entries in the Section Table are numbered starting from one. The code and data memory section entries are in the order chosen by the linker. In an image file, the virtual addresses for sections must be assigned by the linker such that they are in ascending order and adjacent, and they must be a multiple of the Section Align value in the optional header. Each section header (Section Table entry) has the following format, for a total of 40 bytes per entry: Offset | Size | Field | Description |
---|
0 | 8 | Name | An eight-byte, null-padded UTF-8 encoded string. There is no terminating null if the string is exactly eight characters long. For longer names, this field contains a slash (/) followed by ASCII representation of a decimal number: this number is an offset into the string table. Executable images do not use a string table and do not support section names longer than eight characters. Long names in object files will be truncated if emitted to an executable file. | 8 | 4 | VirtualSize | Total size of the section when loaded into memory. If this value is greater than Size of Raw Data, the section is zero-padded. This field is valid only for executable images and should be set to 0 for object files. | 12 | 4 | VirtualAddress | For executable images this is the address of the first byte of the section, when loaded into memory, relative to the image base. For object files, this field is the address of the first byte before relocation is applied; for simplicity, compilers should set this to zero. Otherwise, it is an arbitrary value that is subtracted from offsets during relocation. | 16 | 4 | SizeOfRawData | Size of the section (object file) or size of the initialized data on disk (image files). For executable image, this must be a multiple of FileAlignment from the optional header. If this is less than VirtualSize, the remainder of the section is zero filled. Because this field is rounded while the VirtualSize field is not, it is possible for this to be greater than VirtualSize as well. When a section contains only uninitialized data, this field should be 0. | 20 | 4 | PointerToRawData | File pointer to section's first page within the COFF file. For executable images, this must be a multiple of FileAlignment from the optional header. For object files, the value should be aligned on a four-byte boundary for best performance. When a section contains only uninitialized data, this field should be 0. | 24 | 4 | PointerToRelocations | File pointer to beginning of relocation entries for the section. Set to 0 for executable images or if there are no relocations. | 28 | 4 | PointerToLinenumbers | File pointer to beginning of line-number entries for the section. Set to 0 if there are no COFF line numbers. Should be zero for an image as COFF debugging information is deprecated. | 32 | 2 | NumberOfRelocations | Number of relocation entries for the section. Set to 0 for executable images. | 34 | 2 | NumberOfLinenumbers | Number of line-number entries for the section. Should be zero for an image as COFF debugging information is deprecated. | 36 | 4 | Characteristics | Flags describing section's characteristics. See Section 4.1, "Section Flags," for more information. | 4.1 Section Flags The Section Flags field indicates characteristics of the section. Flag | Value | Description |
---|
| 0x00000000 | Reserved for future use. | | 0x00000001 | Reserved for future use. | | 0x00000002 | Reserved for future use. | | 0x00000004 | Reserved for future use. | IMAGE_SCN_TYPE_NO_PAD | 0x00000008 | Section should not be padded to next boundary. This is obsolete and replaced by IMAGE_SCN_ALIGN_1BYTES. This is valid for object files only. | | 0x00000010 | Reserved for future use. | IMAGE_SCN_CNT_CODE | 0x00000020 | Section contains executable code. | IMAGE_SCN_CNT_INITIALIZED_DATA | 0x00000040 | Section contains initialized data. | IMAGE_SCN_CNT_UNINITIALIZED_DATA | 0x00000080 | Section contains uninitialized data. | IMAGE_SCN_LNK_OTHER | 0x00000100 | Reserved for future use. | IMAGE_SCN_LNK_INFO | 0x00000200 | Section contains comments or other information. The .drectve section has this type. This is valid for object files only. | | 0x00000400 | Reserved for future use. | IMAGE_SCN_LNK_REMOVE | 0x00000800 | Section will not become part of the image. This is valid for object files only. | IMAGE_SCN_LNK_COMDAT | 0x00001000 | Section contains COMDAT data. See Section 5.5.6, "COMDAT Sections," for more information. This is valid for object files only. | IMAGE_SCN_GPREL | 0x00008000 | Section contains data referenced via the GP. | IMAGE_SCN_MEM_PURGEABLE | 0x00020000 | Reserved for future use. | IMAGE_SCN_MEM_16BIT | 0x00020000 | Reserved for future use. | IMAGE_SCN_MEM_LOCKED | 0x00040000 | Reserved for future use. | IMAGE_SCN_MEM_PRELOAD | 0x00080000 | Reserved for future use. | IMAGE_SCN_ALIGN_1BYTES | 0x00100000 | Align data on a 1 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_2BYTES | 0x00200000 | Align data on a 2 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_4BYTES | 0x00300000 | Align data on a 4 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_8BYTES | 0x00400000 | Align data on an 8 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_16BYTES | 0x00500000 | Align data on a 16 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_32BYTES | 0x00600000 | Align data on a 32 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_64BYTES | 0x00700000 | Align data on a 64 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_128BYTES | 0x00800000 | Align data on a 128 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_256BYTES | 0x00900000 | Align data on a 256 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_512BYTES | 0x00A00000 | Align data on a 512 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_1024BYTES | 0x00B00000 | Align data on a 1024 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_2048BYTES | 0x00C00000 | Align data on a 2048 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_4096BYTES | 0x00D00000 | Align data on a 4096 byte boundary. Valid for object files only. | IMAGE_SCN_ALIGN_8192BYTES | 0x00E00000 | Align data on an 8192 byte boundary. Valid for object files only. | IMAGE_SCN_LNK_NRELOC_OVFL | 0x01000000 | Section contains extended relocations. | IMAGE_SCN_MEM_DISCARDABLE | 0x02000000 | Section can be discarded as needed. | IMAGE_SCN_MEM_NOT_CACHED | 0x04000000 | Section cannot be cached. | IMAGE_SCN_MEM_NOT_PAGED | 0x08000000 | Section is not pageable. | IMAGE_SCN_MEM_SHARED | 0x10000000 | Section can be shared in memory. | IMAGE_SCN_MEM_EXECUTE | 0x20000000 | Section can be executed as code. | IMAGE_SCN_MEM_READ | 0x40000000 | Section can be read. | IMAGE_SCN_MEM_WRITE | 0x80000000 | Section can be written to. | IMAGE_SCN_LNK_NRELOC_OVFL indicates that the count of relocations for the section exceeds the 16-bits reserved for it in [the] section header. If the bit is set and the NumberOfRelocations field in the section header is 0xffff, the actual relocation count is stored in the 32-bit VirtualAddress field of the first relocation. It is an error if IMAGE_SCN_LNK_NRELOC_OVFL is set and there are fewer than 0xffff relocations in the section. 4.2 Grouped Sections (Object Only) The "$" character (dollar sign) has a special interpretation in section names in object files. When determining the image section that will contain the contents of an object section, the linker discards the "$" and all characters following it. Thus, an object section named .text$X will actually contribute to the .text section in the image. However, the characters following the "$" determine the ordering of the contributions to the image section. All contributions with the same object-section name will be allocated contiguously in the image, and the blocks of contributions will be sorted in lexical order by object-section name. Therefore, everything in object files with section name .text$X will end up together, after the .text$W contributions and before the .text$Y contributions. The section name in an image file will never contain a "$" character. |