pass over coff header

This commit is contained in:
Nikita Smith
2024-11-07 11:54:25 -08:00
parent 0886963d93
commit ce9d43a92e
+43 -72
View File
@@ -120,7 +120,8 @@ enum
COFF_SectionFlag_MEM_16BIT = (1 << 17), COFF_SectionFlag_MEM_16BIT = (1 << 17),
COFF_SectionFlag_MEM_LOCKED = (1 << 18), COFF_SectionFlag_MEM_LOCKED = (1 << 18),
COFF_SectionFlag_MEM_PRELOAD = (1 << 19), COFF_SectionFlag_MEM_PRELOAD = (1 << 19),
COFF_SectionFlag_ALIGN_SHIFT = 20, COFF_SectionFlag_ALIGN_MASK = 0xf, COFF_SectionFlag_ALIGN_SHIFT = 20,
COFF_SectionFlag_ALIGN_MASK = 0xf,
COFF_SectionFlag_LNK_NRELOC_OVFL = (1 << 24), COFF_SectionFlag_LNK_NRELOC_OVFL = (1 << 24),
COFF_SectionFlag_MEM_DISCARDABLE = (1 << 25), COFF_SectionFlag_MEM_DISCARDABLE = (1 << 25),
COFF_SectionFlag_MEM_NOT_CACHED = (1 << 26), COFF_SectionFlag_MEM_NOT_CACHED = (1 << 26),
@@ -154,8 +155,7 @@ enum
COFF_RelocTypeX64_ABS = 0x0, COFF_RelocTypeX64_ABS = 0x0,
COFF_RelocTypeX64_ADDR64 = 0x1, COFF_RelocTypeX64_ADDR64 = 0x1,
COFF_RelocTypeX64_ADDR32 = 0x2, COFF_RelocTypeX64_ADDR32 = 0x2,
COFF_RelocTypeX64_ADDR32NB = 0x3, COFF_RelocTypeX64_ADDR32NB = 0x3, // NB => No Base
// NB => No Base
COFF_RelocTypeX64_REL32 = 0x4, COFF_RelocTypeX64_REL32 = 0x4,
COFF_RelocTypeX64_REL32_1 = 0x5, COFF_RelocTypeX64_REL32_1 = 0x5,
COFF_RelocTypeX64_REL32_2 = 0x6, COFF_RelocTypeX64_REL32_2 = 0x6,
@@ -164,11 +164,9 @@ enum
COFF_RelocTypeX64_REL32_5 = 0x9, COFF_RelocTypeX64_REL32_5 = 0x9,
COFF_RelocTypeX64_SECTION = 0xA, COFF_RelocTypeX64_SECTION = 0xA,
COFF_RelocTypeX64_SECREL = 0xB, COFF_RelocTypeX64_SECREL = 0xB,
COFF_RelocTypeX64_SECREL7 = 0xC, COFF_RelocTypeX64_SECREL7 = 0xC, // TODO(nick): MSDN doesn't specify size for CLR token
// TODO(nick): MSDN doesn't specify size for CLR token
COFF_RelocTypeX64_TOKEN = 0xD, COFF_RelocTypeX64_TOKEN = 0xD,
COFF_RelocTypeX64_SREL32 = 0xE, COFF_RelocTypeX64_SREL32 = 0xE, // TODO(nick): MSDN doesn't specify size for PAIR
// TODO(nick): MSDN doesn't specify size for PAIR
COFF_RelocTypeX64_PAIR = 0xF, COFF_RelocTypeX64_PAIR = 0xF,
COFF_RelocTypeX64_SSPAN32 = 0x10, COFF_RelocTypeX64_SSPAN32 = 0x10,
COFF_RelocTypeX64_COUNT = 17 COFF_RelocTypeX64_COUNT = 17
@@ -177,29 +175,19 @@ enum
typedef U16 COFF_RelocTypeX86; typedef U16 COFF_RelocTypeX86;
enum enum
{ {
COFF_RelocTypeX86_ABS = 0x0, COFF_RelocTypeX86_ABS = 0x0, // relocation is ignored
// relocation is ignored COFF_RelocTypeX86_DIR16 = 0x1, // no support
COFF_RelocTypeX86_DIR16 = 0x1, COFF_RelocTypeX86_REL16 = 0x2, // no support
// no support
COFF_RelocTypeX86_REL16 = 0x2,
// no support
COFF_RelocTypeX86_UNKNOWN0 = 0x3, COFF_RelocTypeX86_UNKNOWN0 = 0x3,
COFF_RelocTypeX86_UNKNOWN2 = 0x4, COFF_RelocTypeX86_UNKNOWN2 = 0x4,
COFF_RelocTypeX86_UNKNOWN3 = 0x5, COFF_RelocTypeX86_UNKNOWN3 = 0x5,
COFF_RelocTypeX86_DIR32 = 0x6, COFF_RelocTypeX86_DIR32 = 0x6, // 32-bit virtual address
// 32-bit virtual address COFF_RelocTypeX86_DIR32NB = 0x7, // 32-bit virtual offset
COFF_RelocTypeX86_DIR32NB = 0x7, COFF_RelocTypeX86_SEG12 = 0x9, // no support
// 32-bit virtual offset COFF_RelocTypeX86_SECTION = 0xA, // 16-bit section index, used for debug info purposes
COFF_RelocTypeX86_SEG12 = 0x9, COFF_RelocTypeX86_SECREL = 0xB, // 32-bit offset from start of a section
// no support COFF_RelocTypeX86_TOKEN = 0xC, // CLR token? (for managed languages)
COFF_RelocTypeX86_SECTION = 0xA, COFF_RelocTypeX86_SECREL7 = 0xD, // 7-bit offset from the base of the section that contains the target.
// 16-bit section index, used for debug info purposes
COFF_RelocTypeX86_SECREL = 0xB,
// 32-bit offset from start of a section
COFF_RelocTypeX86_TOKEN = 0xC,
// CLR token? (for managed languages)
COFF_RelocTypeX86_SECREL7 = 0xD,
// 7-bit offset from the base of the section that contains the target.
COFF_RelocTypeX86_UNKNOWN4 = 0xE, COFF_RelocTypeX86_UNKNOWN4 = 0xE,
COFF_RelocTypeX86_UNKNOWN5 = 0xF, COFF_RelocTypeX86_UNKNOWN5 = 0xF,
COFF_RelocTypeX86_UNKNOWN6 = 0x10, COFF_RelocTypeX86_UNKNOWN6 = 0x10,
@@ -273,8 +261,7 @@ enum
COFF_SymType_STRUCT, COFF_SymType_STRUCT,
COFF_SymType_UNION, COFF_SymType_UNION,
COFF_SymType_ENUM, COFF_SymType_ENUM,
COFF_SymType_MOE, COFF_SymType_MOE, // member of enumeration
// member of enumeration
COFF_SymType_BYTE, COFF_SymType_BYTE,
COFF_SymType_WORD, COFF_SymType_WORD,
COFF_SymType_UINT, COFF_SymType_UINT,
@@ -390,30 +377,18 @@ typedef struct COFF_ImportHeader
typedef U8 COFF_ComdatSelectType; typedef U8 COFF_ComdatSelectType;
enum enum
{ {
COFF_ComdatSelectType_NULL = 0, COFF_ComdatSelectType_NULL = 0, // Only one symbol is allowed to be in global symbol table, otherwise multiply defintion error is thrown.
// Only one symbol is allowed to be in global symbol table, otherwise multiply defintion error is thrown. COFF_ComdatSelectType_NODUPLICATES = 1, // Select any symbol, even if there are multiple definitions. (we default to first declaration)
COFF_ComdatSelectType_NODUPLICATES = 1, COFF_ComdatSelectType_ANY = 2, // Sections that symbols reference must match in size, otherwise multiply definition error is thrown.
// Select any symbol, even if there are multiple definitions. (we default to first declaration) COFF_ComdatSelectType_SAME_SIZE = 3, // Sections that symbols reference must have identical checksums, otherwise multiply defintion error is thrown.
COFF_ComdatSelectType_ANY = 2, COFF_ComdatSelectType_EXACT_MATCH = 4, // Symbols with associative type form a chain of sections are related to each other. (next link is indicated in COFF_SecDef in 'number')
// Sections that symbols reference must match in size, otherwise multiply definition error is thrown. COFF_ComdatSelectType_ASSOCIATIVE = 5, // Linker selects section with largest size.
COFF_ComdatSelectType_SAME_SIZE = 3,
// Sections that symbols reference must have identical checksums, otherwise multiply defintion error is thrown.
COFF_ComdatSelectType_EXACT_MATCH = 4,
// Symbols with associative type form a chain of sections are related to each other. (next link is indicated in COFF_SecDef in 'number')
COFF_ComdatSelectType_ASSOCIATIVE = 5,
// Linker selects section with largest size.
COFF_ComdatSelectType_LARGEST = 6, COFF_ComdatSelectType_LARGEST = 6,
COFF_ComdatSelectType_COUNT = 7 COFF_ComdatSelectType_COUNT = 7
}; };
#define COFF_MIN_BIG_OBJ_VERSION 2 #define COFF_MIN_BIG_OBJ_VERSION 2
global U8 coff_big_obj_magic[] =
{
0xC7,0xA1,0xBA,0xD1,0xEE,0xBA,0xA9,0x4B,
0xAF,0x20,0xFA,0xF6,0x6A,0xA4,0xDC,0xB8,
};
typedef struct COFF_HeaderBigObj COFF_HeaderBigObj; typedef struct COFF_HeaderBigObj COFF_HeaderBigObj;
struct COFF_HeaderBigObj struct COFF_HeaderBigObj
{ {
@@ -557,11 +532,6 @@ typedef U32 COFF_FeatFlags;
#define COFF_RES_ALIGN 4u #define COFF_RES_ALIGN 4u
read_only U8 g_coff_res_magic[] = {
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
typedef struct COFF_ResourceHeaderPrefix typedef struct COFF_ResourceHeaderPrefix
{ {
U32 data_size; U32 data_size;
@@ -650,9 +620,6 @@ typedef struct COFF_ResourceDirEntry
//////////////////////////////// ////////////////////////////////
read_only global U8 g_coff_archive_sig[8] = "!<arch>\n";
read_only global U8 g_coff_thin_archive_sig[8] = "!<thin>\n";
#define COFF_ARCHIVE_ALIGN 2 #define COFF_ARCHIVE_ALIGN 2
#define COFF_ARCHIVE_MAX_SHORT_NAME_SIZE 15 #define COFF_ARCHIVE_MAX_SHORT_NAME_SIZE 15
#define COFF_ARCHIVE_MEMBER_HEADER_SIZE 60 #define COFF_ARCHIVE_MEMBER_HEADER_SIZE 60
@@ -694,23 +661,12 @@ typedef struct COFF_HeaderInfo
enum enum
{ {
// symbol has section and offset. COFF_SymbolValueInterp_REGULAR, // symbol has section and offset.
COFF_SymbolValueInterp_REGULAR, COFF_SymbolValueInterp_WEAK, // symbol is overridable
COFF_SymbolValueInterp_UNDEFINED, // symbol doesn't have a reference section.
// symbol is overridable COFF_SymbolValueInterp_COMMON, // symbol has no section but still has size.
COFF_SymbolValueInterp_WEAK, COFF_SymbolValueInterp_ABS, // symbol has an absolute (non-relocatable) value and is not an address.
COFF_SymbolValueInterp_DEBUG // symbol is used to provide general type of debugging information.
// symbol doesn't have a reference section.
COFF_SymbolValueInterp_UNDEFINED,
// symbol has no section but still has size.
COFF_SymbolValueInterp_COMMON,
// symbol has an absolute (non-relocatable) value and is not an address.
COFF_SymbolValueInterp_ABS,
// symbol is used to provide general type of debugging information.
COFF_SymbolValueInterp_DEBUG
}; };
typedef U32 COFF_SymbolValueInterpType; typedef U32 COFF_SymbolValueInterpType;
@@ -834,6 +790,21 @@ typedef struct COFF_SectionHeaderArray
//////////////////////////////// ////////////////////////////////
//~ rjf: Globals //~ rjf: Globals
read_only global U8 coff_big_obj_magic[] =
{
0xC7,0xA1,0xBA,0xD1,0xEE,0xBA,0xA9,0x4B,
0xAF,0x20,0xFA,0xF6,0x6A,0xA4,0xDC,0xB8,
};
read_only global U8 g_coff_archive_sig[8] = "!<arch>\n";
read_only global U8 g_coff_thin_archive_sig[8] = "!<thin>\n";
read_only global U8 g_coff_res_magic[] =
{
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
read_only global COFF_SectionHeader coff_section_header_nil = {0}; read_only global COFF_SectionHeader coff_section_header_nil = {0};
//////////////////////////////// ////////////////////////////////