From c0613c2a7e819294cf3a54ada816371071f9bb79 Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Mon, 19 May 2025 13:14:56 -0700 Subject: [PATCH] section align fixes --- src/coff/coff.c | 30 +++++++++++++++--------------- src/coff/coff.h | 1 + src/linker/lnk.c | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/coff/coff.c b/src/coff/coff.c index 9291a4b0..b63f9d2b 100644 --- a/src/coff/coff.c +++ b/src/coff/coff.c @@ -8,7 +8,6 @@ coff_align_size_from_section_flags(COFF_SectionFlags flags) U32 align_index = COFF_SectionFlags_ExtractAlign(flags); switch (align_index) { default: break; - case 0: align = 1; break; // alignment isn't specified, default to 1 case COFF_SectionAlign_1Bytes: align = 1; break; case COFF_SectionAlign_2Bytes: align = 2; break; case COFF_SectionAlign_4Bytes: align = 4; break; @@ -32,20 +31,21 @@ coff_section_flag_from_align_size(U64 align) { COFF_SectionFlags flags = 0; switch (align) { - case 1: flags = COFF_SectionAlign_1Bytes; break; - case 2: flags = COFF_SectionAlign_2Bytes; break; - case 4: flags = COFF_SectionAlign_4Bytes; break; - case 8: flags = COFF_SectionAlign_8Bytes; break; - case 16: flags = COFF_SectionAlign_16Bytes; break; - case 32: flags = COFF_SectionAlign_32Bytes; break; - case 64: flags = COFF_SectionAlign_64Bytes; break; - case 128: flags = COFF_SectionAlign_128Bytes; break; - case 256: flags = COFF_SectionAlign_256Bytes; break; - case 512: flags = COFF_SectionAlign_512Bytes; break; - case 1024: flags = COFF_SectionAlign_1024Bytes; break; - case 2048: flags = COFF_SectionAlign_2048Bytes; break; - case 4096: flags = COFF_SectionAlign_4096Bytes; break; - case 8192: flags = COFF_SectionAlign_8192Bytes; break; + case 0: flags = COFF_SectionAlign_None; break; + case 1: flags = COFF_SectionAlign_1Bytes; break; + case 2: flags = COFF_SectionAlign_2Bytes; break; + case 4: flags = COFF_SectionAlign_4Bytes; break; + case 8: flags = COFF_SectionAlign_8Bytes; break; + case 16: flags = COFF_SectionAlign_16Bytes; break; + case 32: flags = COFF_SectionAlign_32Bytes; break; + case 64: flags = COFF_SectionAlign_64Bytes; break; + case 128: flags = COFF_SectionAlign_128Bytes; break; + case 256: flags = COFF_SectionAlign_256Bytes; break; + case 512: flags = COFF_SectionAlign_512Bytes; break; + case 1024: flags = COFF_SectionAlign_1024Bytes; break; + case 2048: flags = COFF_SectionAlign_2048Bytes; break; + case 4096: flags = COFF_SectionAlign_4096Bytes; break; + case 8192: flags = COFF_SectionAlign_8192Bytes; break; } flags <<= COFF_SectionFlag_AlignShift; return flags; diff --git a/src/coff/coff.h b/src/coff/coff.h index 32f8bc7b..2a6ca456 100644 --- a/src/coff/coff.h +++ b/src/coff/coff.h @@ -103,6 +103,7 @@ typedef struct COFF_BigObjHeader typedef U32 COFF_SectionAlign; enum { + COFF_SectionAlign_None = 0x0, COFF_SectionAlign_1Bytes = 0x1, COFF_SectionAlign_2Bytes = 0x2, COFF_SectionAlign_4Bytes = 0x3, diff --git a/src/linker/lnk.c b/src/linker/lnk.c index ea7505c2..d70dc380 100644 --- a/src/linker/lnk.c +++ b/src/linker/lnk.c @@ -2239,7 +2239,7 @@ lnk_build_win32_image(TP_Arena *arena, TP_Context *tp, LNK_Config *config, LNK_S String8 sect_data = str8_substr(obj->data, rng_1u64(sect_header->foff, sect_header->foff + sect_header->fsize)); // extract align - U16 sc_align = coff_align_size_from_section_flags(COFF_SectionFlags_ExtractAlign(sect_header->flags)); + U16 sc_align = coff_align_size_from_section_flags(sect_header->flags); if (sc_align == 0) { sc_align = default_align; }