From d604456def8fbfc7e76f5cd1f190f0f0d091bad9 Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Mon, 2 Jun 2025 16:04:17 -0700 Subject: [PATCH] align sizeofs --- src/linker/lnk.c | 5 ++++- src/torture/torture.c | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/linker/lnk.c b/src/linker/lnk.c index 78909ba3..58f0b588 100644 --- a/src/linker/lnk.c +++ b/src/linker/lnk.c @@ -2013,7 +2013,10 @@ lnk_build_win32_header(Arena *arena, LNK_SymbolTable *symtab, LNK_Config *config } sizeof_image = Max(sizeof_image, sects.v[sect_idx]->voff + sects.v[sect_idx]->vsize); } - sizeof_image = AlignPow2(sizeof_image, 4096); + sizeof_code = AlignPow2(sizeof_code, config->file_align); + sizeof_inited_data = AlignPow2(sizeof_inited_data, config->file_align); + sizeof_uninited_data = AlignPow2(sizeof_uninited_data, config->file_align); + sizeof_image = AlignPow2(sizeof_image, 4096); // // compute image headers size diff --git a/src/torture/torture.c b/src/torture/torture.c index ac6bd47d..1bf492a2 100644 --- a/src/torture/torture.c +++ b/src/torture/torture.c @@ -605,7 +605,7 @@ t_simple_link_test(void) COFF_ObjWriter *obj_writer = coff_obj_writer_alloc(0, COFF_MachineType_X64); COFF_ObjSection *text_sect = coff_obj_writer_push_section(obj_writer, str8_lit(".text"), PE_TEXT_SECTION_FLAGS, str8_array_fixed(text_payload)); coff_obj_writer_push_section(obj_writer, str8_lit(".data"), PE_DATA_SECTION_FLAGS, str8_lit("qwe")); - coff_obj_writer_push_section(obj_writer, str8_lit(".bss"), PE_BSS_SECTION_FLAGS, str8(0, 5)); + coff_obj_writer_push_section(obj_writer, str8_lit(".zero"), PE_BSS_SECTION_FLAGS, str8(0, 5)); coff_obj_writer_push_symbol_extern(obj_writer, str8_lit("my_entry"), 0, text_sect); main_obj = coff_obj_writer_serialize(scratch.arena, obj_writer); coff_obj_writer_release(&obj_writer); @@ -681,8 +681,8 @@ t_simple_link_test(void) goto exit; } - COFF_SectionHeader *bss_section = t_coff_section_header_from_name(string_table, section_table, pe.section_count, str8_lit(".bss")); - if (bss_section == 0) { + COFF_SectionHeader *zero_section = t_coff_section_header_from_name(string_table, section_table, pe.section_count, str8_lit(".zero")); + if (zero_section == 0) { goto exit; } @@ -698,7 +698,7 @@ t_simple_link_test(void) if (opt->sizeof_inited_data != text_section->fsize + data_section->fsize) { goto exit; } - if (opt->sizeof_uninited_data != 0) { + if (opt->sizeof_uninited_data != 0x200) { goto exit; } if (opt->code_base != 0x1000) { @@ -728,7 +728,7 @@ t_simple_link_test(void) if (opt->win32_version_value != 0) { goto exit; } - if (opt->sizeof_image != 0x3000) { + if (opt->sizeof_image != 0x4000) { goto exit; } if (opt->sizeof_headers != 0x200) {