From 736a6c63a574517b1908ba7f5218bb797bfb7b15 Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Fri, 21 Aug 2026 01:27:46 -0700 Subject: [PATCH] remove per-section linker side arrays --- src/linker/lnk.c | 62 ++++++++++++++++----------------- src/linker/lnk_debug_info.c | 2 +- src/linker/lnk_obj.c | 47 +++++++++---------------- src/linker/lnk_obj.h | 2 -- src/linker/tests/linker_tests.c | 14 ++------ 5 files changed, 51 insertions(+), 76 deletions(-) diff --git a/src/linker/lnk.c b/src/linker/lnk.c index 3e8d8131..f6782ec9 100644 --- a/src/linker/lnk.c +++ b/src/linker/lnk.c @@ -2383,7 +2383,7 @@ lnk_link_image(TP_Context *tp, TP_Arena *arena, LNK_Config *config, LNK_Inputer if ( ! lnk_do_debug_info(config)) { sect_filter |= LNK_SECTION_FLAG_DEBUG; } // on /DEBUG:NONE linker never invokes the debug info machinery for EachIndex(sect_idx, obj->coff.sections.count) { - if (obj->coff.sections.flags[sect_idx] & sect_filter) { continue; } + if (obj->coff.sections.headers[sect_idx].flags & sect_filter) { continue; } // unpack section and relocations COFF_SectionHeader *section_header = §ion_table[sect_idx]; @@ -2708,7 +2708,7 @@ THREAD_POOL_TASK_FUNC(lnk_opt_ref_task) is_live[obj_idx] = push_array(scratch.arena, U8, obj->coff.sections.count + 1); for EachIndex(sect_idx, obj->coff.sections.count) { - is_live[obj_idx][sect_idx + 1] = !(obj->coff.sections.flags[sect_idx] & COFF_SectionFlag_LnkCOMDAT); + is_live[obj_idx][sect_idx + 1] = !(obj->coff.sections.headers[sect_idx].flags & COFF_SectionFlag_LnkCOMDAT); } } } @@ -2741,7 +2741,7 @@ THREAD_POOL_TASK_FUNC(lnk_opt_ref_task) for EachIndex(sect_idx, obj->coff.sections.count) { U32 section_number = sect_idx+1; - COFF_SectionFlags section_flags = obj->coff.sections.flags[sect_idx]; + COFF_SectionFlags section_flags = obj->coff.sections.headers[sect_idx].flags; // is section eligible for walking? if (section_flags & COFF_SectionFlag_LnkRemove) { continue; } @@ -2806,7 +2806,7 @@ THREAD_POOL_TASK_FUNC(lnk_opt_ref_task) for EachNode(section_n, U32Node, associated_sections.first) { U32 section_number = section_n->data; - COFF_SectionFlags section_flags = ref_symbol.obj->coff.sections.flags[section_number-1]; + COFF_SectionFlags section_flags = ref_symbol.obj->coff.sections.headers[section_number-1].flags; // on first section visit, set live flag and enqueue section U8 was_visited = ins_atomic_u8_eval_assign(&is_live[ref_symbol.obj->input_idx][section_number], 1); @@ -2877,7 +2877,7 @@ THREAD_POOL_TASK_FUNC(lnk_opt_ref_task) U32 section_number = sect_idx+1; COFF_SectionHeader *section_header = lnk_coff_section_header_from_section_number(obj, section_number); if ( ! is_live[obj->input_idx][section_number]) { - obj->coff.sections.flags[sect_idx] |= COFF_SectionFlag_LnkRemove; + obj->coff.sections.headers[sect_idx].flags |= COFF_SectionFlag_LnkRemove; } } } @@ -2895,19 +2895,19 @@ THREAD_POOL_TASK_FUNC(lnk_opt_ref_task) COFF_SectionHeader *section_header = lnk_coff_section_header_from_section_number(obj, section_number); U64 stat_kind = Stat_Null; - if (obj->coff.sections.flags[sect_idx] & LNK_SECTION_FLAG_DEBUG) { stat_kind = Stat_Debug; } - else if (obj->coff.sections.flags[sect_idx] & COFF_SectionFlag_CntCode) { stat_kind = Stat_Code; } + if (obj->coff.sections.headers[sect_idx].flags & LNK_SECTION_FLAG_DEBUG) { stat_kind = Stat_Debug; } + else if (obj->coff.sections.headers[sect_idx].flags & COFF_SectionFlag_CntCode) { stat_kind = Stat_Code; } else { stat_kind = Stat_Data; } if (is_live[obj->input_idx][section_number]) { stats[stat_kind].live_count += 1; - if (obj->coff.sections.flags[sect_idx] & COFF_SectionFlag_CntUninitializedData) { + if (obj->coff.sections.headers[sect_idx].flags & COFF_SectionFlag_CntUninitializedData) { stats[stat_kind].live_vsize += section_header->vsize; } else { stats[stat_kind].live_fsize += section_header->fsize; } } else { - if (obj->coff.sections.flags[sect_idx] & COFF_SectionFlag_CntUninitializedData) { + if (obj->coff.sections.headers[sect_idx].flags & COFF_SectionFlag_CntUninitializedData) { stats[stat_kind].vsize += section_header->vsize; } else { stats[stat_kind].fsize += section_header->fsize; @@ -2978,16 +2978,16 @@ lnk_icf_scope_from_section(LNK_Obj *obj, U32 sect_idx) // * section flags filter * COFF_SectionFlags expected_flags = COFF_SectionFlag_LnkCOMDAT | COFF_SectionFlag_MemRead; COFF_SectionFlags exclude_flags = COFF_SectionFlag_LnkRemove | COFF_SectionFlag_MemWrite | LNK_SECTION_FLAG_NOICF; - if ((obj->coff.sections.flags[sect_idx] & expected_flags) != expected_flags || (obj->coff.sections.flags[sect_idx] & exclude_flags) != 0) { + if ((obj->coff.sections.headers[sect_idx].flags & expected_flags) != expected_flags || (obj->coff.sections.headers[sect_idx].flags & exclude_flags) != 0) { goto exit; } - if (obj->coff.sections.flags[sect_idx] & COFF_SectionFlag_CntCode) { + if (obj->coff.sections.headers[sect_idx].flags & COFF_SectionFlag_CntCode) { result = LNK_ICF_Scope_Code; goto exit; } - if (obj->coff.sections.flags[sect_idx] & COFF_SectionFlag_CntInitializedData) { + if (obj->coff.sections.headers[sect_idx].flags & COFF_SectionFlag_CntInitializedData) { U64 section_number = sect_idx + 1; COFF_SectionHeader *section_header = lnk_coff_section_header_from_section_number(obj, section_number); String8 section_name = str8_cstring_capped(section_header->name, section_header->name + sizeof(section_header->name)); @@ -3141,12 +3141,12 @@ THREAD_POOL_TASK_FUNC(lnk_opt_icf_task) if (is_symbol_found) { COFF_ParsedSymbol symbol = lnk_parsed_symbol_from_coff_symbol_idx_no_name(target_ref.obj, target_ref.symbol_idx); if (coff_interp_from_parsed_symbol(symbol) == COFF_SymbolValueInterp_Regular) { - target_ref.obj->coff.sections.flags[symbol.section_number - 1] |= LNK_SECTION_FLAG_NOICF; + target_ref.obj->coff.sections.headers[symbol.section_number - 1].flags |= LNK_SECTION_FLAG_NOICF; } } else { COFF_ParsedSymbol original_symbol = lnk_parsed_symbol_from_coff_symbol_idx_no_name(obj, symbol_idx); if (coff_interp_from_parsed_symbol(original_symbol) == COFF_SymbolValueInterp_Regular) { - obj->coff.sections.flags[original_symbol.section_number - 1] |= LNK_SECTION_FLAG_NOICF; + obj->coff.sections.headers[original_symbol.section_number - 1].flags |= LNK_SECTION_FLAG_NOICF; } else { lnk_log(LNK_Log_Debug, "%S: .llvm_addrsig: contains an unresolved symbol index 0x%x at offset 0x%x", lnk_loc_from_obj(scratch.arena, obj), symbol_idx, symbol_off); } @@ -3303,7 +3303,7 @@ THREAD_POOL_TASK_FUNC(lnk_opt_icf_task) // use the selected COMDAT leader so equivalent targets hash alike if (target_sect != 0 && target_sect <= target_obj->coff.sections.count && - target_obj->coff.sections.flags[target_sect - 1] & COFF_SectionFlag_LnkCOMDAT) { + target_obj->coff.sections.headers[target_sect - 1].flags & COFF_SectionFlag_LnkCOMDAT) { LNK_ObjSymbolRef leader_ref = {0}; if (lnk_obj_get_comdat_symlink(target_obj, target_sect, &leader_ref)) { COFF_ParsedSymbol leader_symbol = lnk_parsed_symbol_from_coff_symbol_idx_no_name(leader_ref.obj, leader_ref.symbol_idx); @@ -3602,8 +3602,8 @@ THREAD_POOL_TASK_FUNC(lnk_opt_icf_task) // TODO: double-check if discarded section headers should be updated with leaders' alignment, // leaders at this point are resolved - U64 contrib_align = coff_align_size_from_section_flags(contrib_obj->coff.sections.flags[contrib->sect_idx]); - COFF_SectionFlags *leader_flags = &leader_obj->coff.sections.flags[leader->sect_idx]; + U64 contrib_align = coff_align_size_from_section_flags(contrib_obj->coff.sections.headers[contrib->sect_idx].flags); + COFF_SectionFlags *leader_flags = &leader_obj->coff.sections.headers[leader->sect_idx].flags; for (COFF_SectionFlags old_flags = ins_atomic_u32_eval((U32 *)leader_flags);;) { U64 leader_align = coff_align_size_from_section_flags(old_flags); if (leader_align >= contrib_align) { break; } @@ -3618,7 +3618,7 @@ THREAD_POOL_TASK_FUNC(lnk_opt_icf_task) } // remove folded section from the image - contrib_obj->coff.sections.flags[contrib->sect_idx] |= COFF_SectionFlag_LnkRemove; + contrib_obj->coff.sections.headers[contrib->sect_idx].flags |= COFF_SectionFlag_LnkRemove; // update folded section COMDAT symlink to point to the leader section contrib_obj->symlinks[contrib->sect_idx + 1] = (LNK_ObjSymbolRef){ leader_obj, leader_obj->coff.sections.comdats[leader->sect_idx] }; @@ -3754,7 +3754,7 @@ lnk_section_definition_is_before(void *raw_a, void *raw_b) internal B32 lnk_should_gather_section(LNK_Obj *obj, U64 sect_idx, COFF_SectionHeader *sect_header) { - COFF_SectionFlags sect_flags = obj->coff.sections.flags[sect_idx]; + COFF_SectionFlags sect_flags = obj->coff.sections.headers[sect_idx].flags; // removed sections were eliminated before image layout if (sect_flags & COFF_SectionFlag_LnkRemove) { @@ -3808,7 +3808,7 @@ THREAD_POOL_TASK_FUNC(lnk_gather_sections_task) Temp temp = temp_begin(scratch.arena); // was section defined? - COFF_SectionFlags image_sect_flags = obj->coff.sections.flags[sect_idx] & ~(COFF_SectionFlags_LnkFlags | COFF_SectionFlags_Reserved); + COFF_SectionFlags image_sect_flags = obj->coff.sections.headers[sect_idx].flags & ~(COFF_SectionFlags_LnkFlags | COFF_SectionFlags_Reserved); String8 sect_name = coff_name_from_section_header(string_table, sect_header); image_sect_flags = lnk_apply_section_directives_to_flags(task->config, sect_name, image_sect_flags); String8 sect_name_with_flags = lnk_make_name_with_flags(temp.arena, sect_name, image_sect_flags); @@ -3934,7 +3934,7 @@ THREAD_POOL_TASK_FUNC(lnk_gather_sections_task) for EachIndex(sect_idx, obj->coff.sections.count) { LNK_SectionContrib *sc = task->null_sc; COFF_SectionHeader *sect_header = §ion_table[sect_idx]; - COFF_SectionFlags sect_flags = obj->coff.sections.flags[sect_idx]; + COFF_SectionFlags sect_flags = obj->coff.sections.headers[sect_idx].flags; task->sect_map[obj_idx][sect_idx] = sc; if ( ! lnk_should_gather_section(obj, sect_idx, sect_header)) { continue; } @@ -3987,7 +3987,7 @@ THREAD_POOL_TASK_FUNC(lnk_set_comdat_leaders_contribs_task) for EachIndex(sect_idx, obj->coff.sections.count) { U64 section_number = sect_idx+1; - if (~obj->coff.sections.flags[sect_idx] & COFF_SectionFlag_LnkCOMDAT) { continue; } + if (~obj->coff.sections.headers[sect_idx].flags & COFF_SectionFlag_LnkCOMDAT) { continue; } LNK_ObjSymbolRef symlink_ref = {0}; if ( ! lnk_obj_get_comdat_symlink(obj, section_number, &symlink_ref)) { continue; } @@ -4010,7 +4010,7 @@ THREAD_POOL_TASK_FUNC(lnk_flag_debug_symbols_task) symbol = lnk_parsed_symbol_from_coff_symbol_idx_no_name(obj, symbol_idx); COFF_SymbolValueInterpType interp = coff_interp_symbol(symbol.section_number, symbol.value, symbol.storage_class); if (interp == COFF_SymbolValueInterp_Regular) { - if (obj->coff.sections.flags[symbol.section_number-1] & LNK_SECTION_FLAG_DEBUG) { + if (obj->coff.sections.headers[symbol.section_number-1].flags & LNK_SECTION_FLAG_DEBUG) { task->u.patch_symtabs.was_symbol_patched[obj_idx][symbol_idx] = 1; } } @@ -4429,7 +4429,7 @@ THREAD_POOL_TASK_FUNC(lnk_obj_reloc_patcher) for EachIndex(sect_idx, obj_header.section_count_no_null) { COFF_SectionHeader *section_header = §ion_table[sect_idx]; - COFF_SectionFlags section_flags = obj->coff.sections.flags[sect_idx]; + COFF_SectionFlags section_flags = obj->coff.sections.headers[sect_idx].flags; if (section_flags & COFF_SectionFlag_LnkInfo) { continue; } if (section_flags & COFF_SectionFlag_LnkRemove) { continue; } @@ -4574,7 +4574,7 @@ THREAD_POOL_TASK_FUNC(lnk_flag_hotpatch_contribs_task) if (interp == COFF_SymbolValueInterp_Regular && COFF_SymbolType_IsFunc(symbol.type)) { LNK_SectionContrib *sc = task->sect_map[obj_idx][symbol.section_number-1]; if (sc != task->null_sc) { - sc->hotpatch = !!(obj->coff.sections.flags[symbol.section_number-1] & COFF_SectionFlag_CntCode); + sc->hotpatch = !!(obj->coff.sections.headers[symbol.section_number-1].flags & COFF_SectionFlag_CntCode); } } } @@ -4938,7 +4938,7 @@ THREAD_POOL_TASK_FUNC(lnk_patch_virtual_offsets_and_sizes_in_obj_section_headers COFF_SectionHeader *section_table = lnk_coff_section_table_from_obj(obj); for (U64 sect_idx = 0; sect_idx < obj->coff.sections.count; sect_idx += 1) { COFF_SectionHeader *sect_header = §ion_table[sect_idx]; - if (~obj->coff.sections.flags[sect_idx] & COFF_SectionFlag_LnkRemove) { + if (~obj->coff.sections.headers[sect_idx].flags & COFF_SectionFlag_LnkRemove) { LNK_SectionContrib *sc = task->sect_map[obj_idx][sect_idx]; LNK_Section *sect = task->image_sects.v[sc->u.sect_idx]; sect_header->vsize = lnk_size_from_section_contrib(sc); @@ -4959,7 +4959,7 @@ THREAD_POOL_TASK_FUNC(lnk_patch_file_offsets_and_sizes_in_obj_section_headers_ta COFF_SectionHeader *section_table = lnk_coff_section_table_from_obj(obj); for (U64 sect_idx = 0; sect_idx < obj->coff.sections.count; sect_idx += 1) { COFF_SectionHeader *sect_header = §ion_table[sect_idx]; - COFF_SectionFlags sect_flags = obj->coff.sections.flags[sect_idx]; + COFF_SectionFlags sect_flags = obj->coff.sections.headers[sect_idx].flags; B32 patch_section_header = (~sect_flags & COFF_SectionFlag_LnkRemove) && (~sect_flags & LNK_SECTION_FLAG_DEBUG); if (patch_section_header) { @@ -4992,7 +4992,7 @@ THREAD_POOL_TASK_FUNC(lnk_patch_section_symbols_task) COFF_SectionHeader *section_table = lnk_coff_section_table_from_obj(obj); for EachIndex(sect_idx, obj->coff.sections.count) { COFF_SectionHeader *section_header = §ion_table[sect_idx]; - COFF_SectionFlags section_flags = obj->coff.sections.flags[sect_idx]; + COFF_SectionFlags section_flags = obj->coff.sections.headers[sect_idx].flags; if (section_flags & COFF_SectionFlag_LnkRemove) { continue; } if (section_flags & COFF_SectionFlag_LnkInfo) { continue; } if (section_flags & LNK_SECTION_FLAG_DEBUG) { continue; } @@ -5058,7 +5058,7 @@ THREAD_POOL_TASK_FUNC(lnk_gather_base_reloc_pages_task) ProfBeginV("%S", obj->path); for EachIndex(sect_idx, obj->coff.sections.count) { COFF_SectionHeader *sect_header = §_table[sect_idx]; - if (obj->coff.sections.flags[sect_idx] & COFF_SectionFlag_LnkRemove) { continue; } + if (obj->coff.sections.headers[sect_idx].flags & COFF_SectionFlag_LnkRemove) { continue; } COFF_RelocArray relocs = lnk_coff_relocs_from_section_header(obj, sect_header); for EachIndex(reloc_idx, relocs.count) { @@ -6142,7 +6142,7 @@ lnk_obj_sect_idx_from_section(Arena *arena, U64 objs_count, LNK_Obj **objs, LNK_ String8 section_name, section_postfix; coff_parse_section_name(full_section_name, §ion_name, §ion_postfix); - if (obj->coff.sections.flags[sect_idx] & COFF_SectionFlag_LnkRemove) { continue; } + if (obj->coff.sections.headers[sect_idx].flags & COFF_SectionFlag_LnkRemove) { continue; } if (section_header->fsize == 0) { continue; } if (lnk_is_section_removed(config, section_name)) { continue; } @@ -6313,7 +6313,7 @@ lnk_build_rad_map(Arena *arena, String8 image_data, LNK_Config *config, U64 objs COFF_SectionHeader *section_table = str8_deserial_get_raw_ptr(obj->coff.data, obj->coff.header.section_table_range.min, 0); for (U64 sect_idx = 0; sect_idx < obj->coff.sections.count; sect_idx += 1) { COFF_SectionHeader *section_header = §ion_table[sect_idx]; - COFF_SectionFlags section_flags = obj->coff.sections.flags[sect_idx]; + COFF_SectionFlags section_flags = obj->coff.sections.headers[sect_idx].flags; if (~section_flags & COFF_SectionFlag_LnkRemove && section_flags & LNK_SECTION_FLAG_DEBUG) { LNK_Lib *lib = lnk_obj_get_lib(obj); if (lib) { diff --git a/src/linker/lnk_debug_info.c b/src/linker/lnk_debug_info.c index c8efd6e0..70ee1dab 100644 --- a/src/linker/lnk_debug_info.c +++ b/src/linker/lnk_debug_info.c @@ -2855,7 +2855,7 @@ THREAD_POOL_TASK_FUNC(lnk_push_dbi_sec_contrib_task) for EachIndex(sect_idx, obj->coff.sections.count) { // filter by section flags - if (obj->coff.sections.flags[sect_idx] & (COFF_SectionFlag_LnkInfo | COFF_SectionFlag_LnkRemove | LNK_SECTION_FLAG_DEBUG)) { continue; } + if (obj->coff.sections.headers[sect_idx].flags & (COFF_SectionFlag_LnkInfo | COFF_SectionFlag_LnkRemove | LNK_SECTION_FLAG_DEBUG)) { continue; } // skip unwind info for the section contribution String8 section_name = lnk_obj_section_name_from_sect_idx(obj, sect_idx); diff --git a/src/linker/lnk_obj.c b/src/linker/lnk_obj.c index b2074265..2163d5ca 100644 --- a/src/linker/lnk_obj.c +++ b/src/linker/lnk_obj.c @@ -103,23 +103,23 @@ THREAD_POOL_TASK_FUNC(lnk_obj_initer) // - find debug info and meta-data leaders // COFF_SectionHeader *coff_section_table = (COFF_SectionHeader *)raw_coff_section_table.str; - COFF_SectionFlags *section_flags = push_array_no_zero(arena, COFF_SectionFlags, header.section_count_no_null); U32 debug_t_sect_idx = ~0; U32 debug_p_sect_idx = ~0; U32 debug_h_sect_idx = ~0; U32 llvm_addrsig_sect_idx = ~0; for (U64 sect_idx = 0; sect_idx < header.section_count_no_null; sect_idx += 1) { COFF_SectionHeader *coff_sect_header = &coff_section_table[sect_idx]; - section_flags[sect_idx] = coff_sect_header->flags & ~3; // linker reserves low 2 bits for internal flags + COFF_SectionFlags *section_flags = §ion_headers[sect_idx].flags; String8 sect_name = coff_name_from_section_header(raw_coff_string_table, coff_sect_header); + *section_flags = coff_sect_header->flags & ~3; // linker reserves low 2 bits for internal flags if (str8_starts_with(sect_name, str8_lit(".debug$"))) { - section_flags[sect_idx] |= LNK_SECTION_FLAG_DEBUG; + *section_flags |= LNK_SECTION_FLAG_DEBUG; } if (str8_ends_with(sect_name, str8_lit("$fo$"), 0) || str8_ends_with(sect_name, str8_lit("$fo_rvas$"), 0) || str8_ends_with(sect_name, str8_lit("$fo_bdd$"), 0)) { - section_flags[sect_idx] |= COFF_SectionFlag_LnkInfo; + *section_flags |= COFF_SectionFlag_LnkInfo; } if (str8_match(sect_name, str8_lit(".debug$T"), 0)) { @@ -134,7 +134,7 @@ THREAD_POOL_TASK_FUNC(lnk_obj_initer) llvm_addrsig_sect_idx = sect_idx; } - if (~section_flags[sect_idx] & COFF_SectionFlag_CntUninitializedData) { + if (~*section_flags & COFF_SectionFlag_CntUninitializedData) { if (coff_sect_header->fsize > 0) { Rng1U64 sect_range = rng_1u64(coff_sect_header->foff, coff_sect_header->foff + coff_sect_header->fsize); if (contains_1u64(header.header_range, coff_sect_header->foff) || @@ -156,13 +156,6 @@ THREAD_POOL_TASK_FUNC(lnk_obj_initer) } } - String8 *section_data = push_array(arena, String8, header.section_count_no_null); - for EachIndex(sect_idx, header.section_count_no_null) { - COFF_SectionHeader *sect_header = &coff_section_table[sect_idx]; - String8 data = str8_substr(input->data, r1u64s(sect_header->foff, sect_header->fsize)); - section_data[sect_idx] = section_flags[sect_idx] & LNK_SECTION_FLAG_DEBUG ? push_str8_copy(arena, data) : data; - } - // // error check symbol table and cache name lengths for primary symbols // @@ -255,7 +248,7 @@ THREAD_POOL_TASK_FUNC(lnk_obj_initer) if (symbol.storage_class == COFF_SymStorageClass_Static) { if (symbol.section_number > 0 && symbol.section_number <= header.section_count_no_null) { COFF_SectionHeader *sect_header = &coff_section_table[symbol.section_number-1]; - if (section_flags[symbol.section_number-1] & COFF_SectionFlag_LnkCOMDAT) { + if (section_headers[symbol.section_number-1].flags & COFF_SectionFlag_LnkCOMDAT) { if (symbol.aux_symbol_count) { U32 section_length = 0; coff_parse_secdef(symbol, header.is_big_obj, 0, 0, §ion_length, 0); @@ -362,7 +355,7 @@ THREAD_POOL_TASK_FUNC(lnk_obj_initer) CV_Symbol comp_symbol = {0}; for EachIndex(sect_idx, header.section_count_no_null) { COFF_SectionHeader *sect_header = &coff_section_table[sect_idx]; - if (section_flags[sect_idx] & LNK_SECTION_FLAG_DEBUG) { + if (section_headers[sect_idx].flags & LNK_SECTION_FLAG_DEBUG) { String8 name = str8_cstring_capped(sect_header->name, sect_header->name+sizeof(sect_header->name)); if (str8_match(name, str8_lit(".debug$S"), 0)) { Temp temp = temp_begin(scratch.arena); @@ -402,8 +395,6 @@ THREAD_POOL_TASK_FUNC(lnk_obj_initer) .sections = { .count = header.section_count_no_null, .headers = section_headers, - .flags = section_flags, - .data = section_data, .comdats = comdats, .associations = associated_sections, }, @@ -521,7 +512,7 @@ lnk_symlinks_from_obj(Arena *arena, LNK_SymbolTable *symtab, LNK_Obj *obj) COFF_SymbolValueInterpType interp = coff_interp_from_parsed_symbol(symbol); if (interp != COFF_SymbolValueInterp_Regular) { continue; } - COFF_SectionFlags section_flags = obj->coff.sections.flags[symbol.section_number - 1]; + COFF_SectionFlags section_flags = obj->coff.sections.headers[symbol.section_number - 1].flags; if (~section_flags & COFF_SectionFlag_LnkCOMDAT) { continue; } LNK_ObjSymbolRef *symlink = &symlinks[symbol.section_number]; @@ -582,7 +573,7 @@ lnk_obj_collect_associated_sections(Arena *arena, LNK_Obj *obj, U32 root_section if (child_section == 0) { continue; } if (hash_map_search_u64_u64(&seen_hm, child_section)) { continue; } - if (obj->coff.sections.flags[child_section - 1] & skip_flags) { continue; } + if (obj->coff.sections.headers[child_section - 1].flags & skip_flags) { continue; } hash_map_push_u64_u64(scratch.arena, &seen_hm, child_section, 1); u32_list_push(arena, &queue, child_section); @@ -702,22 +693,18 @@ internal String8 lnk_obj_section_data_from_sect_idx(LNK_Obj *obj, U64 sect_idx) { Assert(sect_idx < obj->coff.sections.count); - return obj->coff.sections.data[sect_idx]; + COFF_SectionHeader *section_table = (COFF_SectionHeader *)str8_substr(obj->coff.data, obj->coff.header.section_table_range).str; + COFF_SectionHeader *section = §ion_table[sect_idx]; + return str8_substr(obj->coff.data, r1u64s(section->foff, section->fsize)); } internal U64 lnk_obj_foff_from_section_data_ptr(LNK_Obj *obj, void *ptr) { - U64 ptr_v = IntFromPtr(ptr); - for EachIndex(sect_idx, obj->coff.sections.count) { - String8 data = obj->coff.sections.data[sect_idx]; - U64 data_min = IntFromPtr(data.str); - if (data_min <= ptr_v && ptr_v < data_min + data.size) { - return obj->coff.sections.headers[sect_idx].foff + ptr_v - data_min; - } - } - InvalidPath; - return 0; + U64 data_min = IntFromPtr(obj->coff.data.str); + U64 ptr_v = IntFromPtr(ptr); + Assert(data_min <= ptr_v && ptr_v < data_min + obj->coff.data.size); + return ptr_v - data_min; } internal U64 @@ -757,7 +744,7 @@ lnk_obj_section_from_sect_idx(LNK_Obj *obj, U64 sect_idx) section.sect_idx = sect_idx; section.section_number = sect_idx+1; section.header = &lnk_coff_section_table_from_obj(obj)[sect_idx]; - section.flags = &obj->coff.sections.flags[sect_idx]; + section.flags = §ion.header->flags; section.vrange = rng_1u64(section.header->voff, section.header->voff + section.header->vsize); section.frange = rng_1u64(section.header->foff, section.header->foff + section.header->fsize); section.reloc_count = section.header->reloc_count; diff --git a/src/linker/lnk_obj.h b/src/linker/lnk_obj.h index 851b0c77..364f3189 100644 --- a/src/linker/lnk_obj.h +++ b/src/linker/lnk_obj.h @@ -31,8 +31,6 @@ typedef struct LNK_ObjSectionArray { U64 count; COFF_SectionHeader *headers; - COFF_SectionFlags *flags; - String8 *data; U32 *comdats; U32Node **associations; } LNK_ObjSectionArray; diff --git a/src/linker/tests/linker_tests.c b/src/linker/tests/linker_tests.c index a5f8aafd..c4597d3d 100644 --- a/src/linker/tests/linker_tests.c +++ b/src/linker/tests/linker_tests.c @@ -5881,12 +5881,8 @@ TEST(debug_p_sig_mismatch) T_Ok(t_write_file(str8_lit("b.obj"), b_obj)); T_Ok(t_write_entry_obj()); - String8 a_obj_before = t_read_file(arena, str8_lit("a.obj")); - String8 b_obj_before = t_read_file(arena, str8_lit("b.obj")); - t_invoke_linkerf("/RAD_MEMORY_MAP_FILES:READ_WRITE /subsystem:console /entry:entry /out:a.exe /debug:full a.obj b.obj entry.obj"); + t_invoke_linkerf("/subsystem:console /entry:entry /out:a.exe /debug:full a.obj b.obj entry.obj"); T_Ok(g_last_exit_code == 0); - T_Ok(str8_match(a_obj_before, t_read_file(arena, str8_lit("a.obj")), 0)); - T_Ok(str8_match(b_obj_before, t_read_file(arena, str8_lit("b.obj")), 0)); B32 found_error = 0; String8 a_obj_path = t_make_file_path(arena, str8_lit("a.obj")); @@ -6275,14 +6271,8 @@ TEST(gen_rrt) t_invoke_linkerf("/subsystem:console /entry:entry /out:a.exe /debug:full /rad_type_server:foo.rrt a.obj b.obj entry.obj"); T_Ok(g_last_exit_code == 0); - String8 a_obj_before = t_read_file(arena, a_obj_file_path); - String8 b_obj_before = t_read_file(arena, b_obj_file_path); - String8 rrt_before = t_read_file(arena, str8_lit("foo.rrt")); - t_invoke_linkerf("/RAD_MEMORY_MAP_FILES:READ_WRITE /subsystem:console /entry:entry /out:a.exe /debug:ghash a.obj foo.rrt b.obj entry.obj"); + t_invoke_linkerf("/subsystem:console /entry:entry /out:a.exe /debug:ghash a.obj foo.rrt b.obj entry.obj"); T_Ok(g_last_exit_code == 0); - T_Ok(str8_match(a_obj_before, t_read_file(arena, a_obj_file_path), 0)); - T_Ok(str8_match(b_obj_before, t_read_file(arena, b_obj_file_path), 0)); - T_Ok(str8_match(rrt_before, t_read_file(arena, str8_lit("foo.rrt")), 0)); } TEST(debug_p_and_debug_t_in_obj)