diff --git a/src/linker/lnk.c b/src/linker/lnk.c index 4e8cb79c..b5fa1ea7 100644 --- a/src/linker/lnk.c +++ b/src/linker/lnk.c @@ -414,13 +414,13 @@ lnk_res_number_id_is_before(void *raw_a, void *raw_b) } internal void -lnk_serialize_pe_resource_tree(LNK_SectionTable *st, LNK_SymbolTable *symtab, PE_ResourceDir *root_dir) +lnk_serialize_pe_resource_tree(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, PE_ResourceDir *root_dir) { ProfBeginFunction(); Temp scratch = scratch_begin(0, 0); - LNK_Section *dir_sect = lnk_section_table_push(st, str8_lit(".rsrc$01"), LNK_RSRC_SECTION_FLAGS); - LNK_Section *data_sect = lnk_section_table_push(st, str8_lit(".rsrc$02"), LNK_RSRC_SECTION_FLAGS); + LNK_Section *dir_sect = lnk_section_table_push(sectab, str8_lit(".rsrc$01"), LNK_RSRC_SECTION_FLAGS); + LNK_Section *data_sect = lnk_section_table_push(sectab, str8_lit(".rsrc$02"), LNK_RSRC_SECTION_FLAGS); LNK_Chunk *dir_tree_chunk = lnk_section_push_chunk_list(dir_sect, dir_sect->root, str8_zero()); LNK_Chunk *dir_data_chunk = lnk_section_push_chunk_list(dir_sect, dir_sect->root, str8_zero()); @@ -580,7 +580,7 @@ lnk_serialize_pe_resource_tree(LNK_SectionTable *st, LNK_SymbolTable *symtab, PE } internal void -lnk_add_resource_debug_s(LNK_SectionTable *st, +lnk_add_resource_debug_s(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, String8 obj_path, String8 cwd_path, @@ -674,7 +674,7 @@ lnk_add_resource_debug_s(LNK_SectionTable *st, str8_serial_push_data_list(scratch.arena, &sub_sect_srl, symbol_srl.first); str8_serial_push_align(scratch.arena, &sub_sect_srl, CV_C13SubSectionAlign); - LNK_Section *debug_s = lnk_section_table_push(st, str8_lit(".debug$S"), LNK_DEBUG_SECTION_FLAGS); + LNK_Section *debug_s = lnk_section_table_push(sectab, str8_lit(".debug$S"), LNK_DEBUG_SECTION_FLAGS); String8 sub_sect_data = str8_serial_end(debug_s->arena, &sub_sect_srl); lnk_section_push_chunk_data(debug_s, debug_s->root, sub_sect_data, str8_zero()); @@ -706,24 +706,24 @@ lnk_make_res_obj(TP_Context *tp, temp_tp_arena->v[0] = arena_alloc(); LNK_SymbolTable *symtab = lnk_symbol_table_init(temp_tp_arena); - LNK_SectionTable *st = lnk_section_table_alloc(0, sect_virt_align, sect_file_align); - LNK_Section *header_sect = lnk_section_table_push(st, str8_lit(".null"), 0); + LNK_SectionTable *sectab = lnk_section_table_alloc(0, sect_virt_align, sect_file_align); + LNK_Section *header_sect = lnk_section_table_push(sectab, str8_lit(".null"), 0); - lnk_serialize_pe_resource_tree(st, symtab, root_dir); + lnk_serialize_pe_resource_tree(sectab, symtab, root_dir); CV_Arch cv_arch = cv_arch_from_coff_machine(machine); - lnk_add_resource_debug_s(st, symtab, path, cwd_path, exe_path, cv_arch, res_file_list, res_hash_array); + lnk_add_resource_debug_s(sectab, symtab, path, cwd_path, exe_path, cv_arch, res_file_list, res_hash_array); // register section symbols (after this point don't push new sections) - for (LNK_SectionNode *sect_node = st->list.first; sect_node != 0; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != 0; sect_node = sect_node->next) { LNK_Section *sect = §_node->data; lnk_symbol_table_push_defined_chunk(symtab, sect->name, LNK_DefinedSymbolVisibility_Internal, 0, sect->root, 0, 0, 0); } - st->null_sect = lnk_section_list_remove(&st->list, str8_lit(".null")); - lnk_section_table_build_data(tp, st, machine); - lnk_section_table_push_null(st); - lnk_section_table_assign_indices(st); - LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, st); + sectab->null_sect = lnk_section_list_remove(§ab->list, str8_lit(".null")); + lnk_section_table_build_data(tp, sectab, machine); + lnk_section_table_push_null(sectab); + lnk_section_table_assign_indices(sectab); + LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, sectab); COFF_Symbol16List coff_symbol_list = {0}; @@ -735,7 +735,7 @@ lnk_make_res_obj(TP_Context *tp, coff_symbol16_list_push(scratch.arena, &coff_symbol_list, coff_feat00); // emit coff symbols for section definitions - for (LNK_SectionNode *sect_node = st->list.first; sect_node != 0; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != 0; sect_node = sect_node->next) { LNK_Section *sect = §_node->data; if (sect == header_sect) continue; if (!sect->emit_header) continue; @@ -768,7 +768,7 @@ lnk_make_res_obj(TP_Context *tp, // convert relocations and symbols to coff format { - for (LNK_SectionNode *sect_node = st->list.first; sect_node != 0; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != 0; sect_node = sect_node->next) { LNK_Section *sect = §_node->data; // filter out resource relocations @@ -827,8 +827,8 @@ lnk_make_res_obj(TP_Context *tp, if (coff_reloc_list.count == 0) continue; // push section for relocation data - String8 sect_name = push_str8f(st->arena, "%S.relocs", sect->name); - LNK_Section *reloc_sect = lnk_section_table_push(st, sect_name, 0); + String8 sect_name = push_str8f(sectab->arena, "%S.relocs", sect->name); + LNK_Section *reloc_sect = lnk_section_table_push(sectab, sect_name, 0); reloc_sect->emit_header = 0; // push chunk layout for relocations @@ -848,7 +848,7 @@ lnk_make_res_obj(TP_Context *tp, } } - LNK_Section *misc_sect = lnk_section_table_push(st, str8_lit(".misc"), COFF_SectionFlag_LnkInfo|COFF_SectionFlag_LnkRemove); + LNK_Section *misc_sect = lnk_section_table_push(sectab, str8_lit(".misc"), COFF_SectionFlag_LnkInfo|COFF_SectionFlag_LnkRemove); misc_sect->emit_header = 0; // serialize coff symbol list @@ -894,9 +894,9 @@ lnk_make_res_obj(TP_Context *tp, // build section headers { LNK_Chunk *coff_section_header_array_chunk = lnk_section_push_chunk_list(header_sect, header_sect->root, str8_zero()); - for (LNK_SectionNode *sect_node = st->list.first; sect_node != 0; sect_node = sect_node->next) { - if (sect_node == st->null_sect) continue; - if (!sect_node->data.emit_header) continue; + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != 0; sect_node = sect_node->next) { + if (sect_node == sectab->null_sect) continue; + if (!sect_node->data.emit_header) continue; LNK_Section *sect = §_node->data; // init section header @@ -941,13 +941,13 @@ lnk_make_res_obj(TP_Context *tp, lnk_symbol_table_push(symtab, coff_section_header_count_symbol); } - lnk_section_table_assign_indices(st); - lnk_section_table_build_data(tp, st, machine); - lnk_section_table_assign_file_offsets(st); - String8 res_obj = lnk_section_table_serialize(tp, arena, st, machine); - sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, st); - lnk_patch_relocs_linker(tp, symtab, st, sect_id_map, res_obj, 0); - lnk_section_table_release(&st); + lnk_section_table_assign_indices(sectab); + lnk_section_table_build_data(tp, sectab, machine); + lnk_section_table_assign_file_offsets(sectab); + String8 res_obj = lnk_section_table_serialize(tp, arena, sectab, machine); + sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, sectab); + lnk_patch_relocs_linker(tp, symtab, sectab, sect_id_map, res_obj, 0); + lnk_section_table_release(§ab); arena_release(temp_tp_arena->v[0]); scratch_end(scratch); @@ -958,7 +958,7 @@ lnk_make_res_obj(TP_Context *tp, internal String8 lnk_obj_from_res_file_list(TP_Context *tp, Arena *arena, - LNK_SectionTable *st, + LNK_SectionTable *sectab, LNK_SymbolTable *symtab, String8List res_data_list, String8List res_path_list, @@ -1030,10 +1030,10 @@ lnk_make_linker_coff_obj(TP_Context *tp, temp_tp_arena->count = 1; LNK_SymbolTable *symtab = lnk_symbol_table_init(temp_tp_arena); - LNK_SectionTable *st = lnk_section_table_alloc(0, 1, 1); + LNK_SectionTable *sectab = lnk_section_table_alloc(0, 1, 1); - LNK_Section *header_sect = lnk_section_table_push(st, str8_lit(".coffhdr"), 0); - LNK_Section *debug_s_sect = lnk_section_table_push(st, str8_lit(".debug$S"), LNK_DEBUG_SECTION_FLAGS); + LNK_Section *header_sect = lnk_section_table_push(sectab, str8_lit(".coffhdr"), 0); + LNK_Section *debug_s_sect = lnk_section_table_push(sectab, str8_lit(".debug$S"), LNK_DEBUG_SECTION_FLAGS); // TODO: remove! hack! header_sect->emit_header = 0; @@ -1105,15 +1105,15 @@ lnk_make_linker_coff_obj(TP_Context *tp, { // register section symbols (after this point don't push new sections) - for (LNK_SectionNode *sect_node = st->list.first; sect_node != NULL; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != NULL; sect_node = sect_node->next) { LNK_Section *sect = §_node->data; lnk_symbol_table_push_defined_chunk(symtab, sect->name, LNK_DefinedSymbolVisibility_Internal, 0, sect->root, 0, 0, 0); } LNK_Chunk *coff_section_header_array_chunk = lnk_section_push_chunk_list(header_sect, header_sect->root, str8_zero()); - for (LNK_SectionNode *sect_node = st->list.first; sect_node != NULL; sect_node = sect_node->next) { - if (sect_node == st->null_sect) continue; - if (!sect_node->data.emit_header) continue; + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != NULL; sect_node = sect_node->next) { + if (sect_node == sectab->null_sect) continue; + if (!sect_node->data.emit_header) continue; LNK_Section *sect = §_node->data; // init section header @@ -1157,14 +1157,14 @@ lnk_make_linker_coff_obj(TP_Context *tp, lnk_symbol_table_push(symtab, coff_section_header_count_symbol); } - lnk_section_table_assign_indices(st); - lnk_section_table_build_data(tp, st, machine); - lnk_section_table_assign_file_offsets(st); - String8 coff_data = lnk_section_table_serialize(tp, arena, st, machine); - LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, st); - lnk_patch_relocs_linker(tp, symtab, st, sect_id_map, coff_data, 0); + lnk_section_table_assign_indices(sectab); + lnk_section_table_build_data(tp, sectab, machine); + lnk_section_table_assign_file_offsets(sectab); + String8 coff_data = lnk_section_table_serialize(tp, arena, sectab, machine); + LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, sectab); + lnk_patch_relocs_linker(tp, symtab, sectab, sect_id_map, coff_data, 0); - lnk_section_table_release(&st); + lnk_section_table_release(§ab); scratch_end(scratch); return coff_data; @@ -1378,7 +1378,7 @@ lnk_push_pe_debug_data_directory(LNK_Section *sect, } internal void -lnk_build_debug_pdb(LNK_SectionTable *st, +lnk_build_debug_pdb(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, LNK_Section *sect, LNK_Chunk *dir_array_chunk, @@ -1405,7 +1405,7 @@ lnk_build_debug_pdb(LNK_SectionTable *st, } internal void -lnk_build_debug_rdi(LNK_SectionTable *st, +lnk_build_debug_rdi(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, LNK_Section *debug_sect, LNK_Chunk *debug_dir_array_chunk, @@ -1415,7 +1415,7 @@ lnk_build_debug_rdi(LNK_SectionTable *st, { ProfBeginFunction(); - LNK_Section *rdi_sect = lnk_section_table_push(st, str8_lit(".raddbg"), COFF_SectionFlag_CntInitializedData|COFF_SectionFlag_MemRead); + LNK_Section *rdi_sect = lnk_section_table_push(sectab, str8_lit(".raddbg"), COFF_SectionFlag_CntInitializedData|COFF_SectionFlag_MemRead); // push chunks String8 debug_rdi = pe_make_debug_header_rdi(rdi_sect->arena, guid, rdi_path); @@ -1434,7 +1434,7 @@ lnk_build_debug_rdi(LNK_SectionTable *st, internal void lnk_build_guard_tables(TP_Context *tp, - LNK_SectionTable *st, + LNK_SectionTable *sectab, LNK_SymbolTable *symtab, LNK_ExportTable *exptab, LNK_ObjList obj_list, @@ -1446,7 +1446,7 @@ lnk_build_guard_tables(TP_Context *tp, ProfBeginFunction(); Temp scratch = scratch_begin(0, 0); - LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, st); + LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, sectab); enum { GUARD_FIDS, GUARD_IATS, GUARD_LJMP, GUARD_EHCONT, GUARD_COUNT }; LNK_SymbolList guard_symbol_list_table[GUARD_COUNT]; MemoryZeroStruct(&guard_symbol_list_table[0]); @@ -1561,8 +1561,8 @@ lnk_build_guard_tables(TP_Context *tp, #endif // build section data - lnk_section_table_build_data(tp, st, machine); - lnk_section_table_assign_virtual_offsets(st); + lnk_section_table_build_data(tp, sectab, machine); + lnk_section_table_assign_virtual_offsets(sectab); // compute symbols virtual offsets U64Array guard_voff_arr_table[GUARD_COUNT]; @@ -1604,7 +1604,7 @@ lnk_build_guard_tables(TP_Context *tp, { ".gehcont", LNK_GEHCONT_SYMBOL_NAME, LNK_GEHCONT_SECTION_FLAGS }, }; for (U64 i = 0; i < ArrayCount(sect_layout); ++i) { - LNK_Section *sect = lnk_section_table_push(st, str8_cstring(sect_layout[i].name), sect_layout[i].flags); + LNK_Section *sect = lnk_section_table_push(sectab, str8_cstring(sect_layout[i].name), sect_layout[i].flags); lnk_symbol_table_push_defined_chunk(symtab, str8_cstring(sect_layout[i].symbol), LNK_DefinedSymbolVisibility_Internal, 0, sect->root, 0, 0, 0); } @@ -1619,10 +1619,10 @@ lnk_build_guard_tables(TP_Context *tp, LNK_Symbol *gljmp_symbol = lnk_symbol_table_search(symtab, LNK_SymbolScopeFlag_Internal, str8_lit(LNK_GLJMP_SYMBOL_NAME)); LNK_Symbol *gehcont_symbol = lnk_symbol_table_search(symtab, LNK_SymbolScopeFlag_Internal, str8_lit(LNK_GEHCONT_SYMBOL_NAME)); - LNK_Section *gfids_sect = lnk_section_table_search_id(st, gfids_symbol->u.defined.u.chunk->ref.sect_id); - LNK_Section *giats_sect = lnk_section_table_search_id(st, giats_symbol->u.defined.u.chunk->ref.sect_id); - LNK_Section *gljmp_sect = lnk_section_table_search_id(st, gljmp_symbol->u.defined.u.chunk->ref.sect_id); - LNK_Section *gehcont_sect = lnk_section_table_search_id(st, gehcont_symbol->u.defined.u.chunk->ref.sect_id); + LNK_Section *gfids_sect = lnk_section_table_search_id(sectab, gfids_symbol->u.defined.u.chunk->ref.sect_id); + LNK_Section *giats_sect = lnk_section_table_search_id(sectab, giats_symbol->u.defined.u.chunk->ref.sect_id); + LNK_Section *gljmp_sect = lnk_section_table_search_id(sectab, gljmp_symbol->u.defined.u.chunk->ref.sect_id); + LNK_Section *gehcont_sect = lnk_section_table_search_id(sectab, gehcont_symbol->u.defined.u.chunk->ref.sect_id); LNK_Chunk *gfids_array_chunk = gfids_sect->root; LNK_Chunk *giats_array_chunk = giats_sect->root; @@ -1683,7 +1683,7 @@ lnk_build_guard_tables(TP_Context *tp, gflags_def->u.va |= PE_LoadConfigGuardFlags_EH_CONTINUATION_TABLE_PRESENT; } { - LNK_Section *didat_sect = lnk_section_table_search(st, str8_lit(".didat")); + LNK_Section *didat_sect = lnk_section_table_search(sectab, str8_lit(".didat")); if (didat_sect) { gflags_def->u.va |= PE_LoadConfigGuardFlags_DELAYLOAD_IAT_IN_ITS_OWN_SECTION; } @@ -1852,7 +1852,7 @@ lnk_base_reloc_page_array_sort(LNK_BaseRelocPageArray arr) internal void lnk_build_base_relocs(TP_Context *tp, TP_Arena *tp_arena, - LNK_SectionTable *st, + LNK_SectionTable *sectab, LNK_SymbolTable *symtab, COFF_MachineType machine, U64 page_size, @@ -1863,10 +1863,10 @@ lnk_build_base_relocs(TP_Context *tp, TP_Temp temp = tp_temp_begin(tp_arena); - lnk_section_table_build_data(tp, st, machine); - lnk_section_table_assign_virtual_offsets(st); + lnk_section_table_build_data(tp, sectab, machine); + lnk_section_table_assign_virtual_offsets(sectab); - LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(tp_arena->v[0], st); + LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(tp_arena->v[0], sectab); LNK_BaseRelocPageList *page_list_arr = push_array(tp_arena->v[0], LNK_BaseRelocPageList, tp->worker_count); HashTable **page_ht_arr = push_array_no_zero(tp_arena->v[0], HashTable *, tp->worker_count); @@ -1876,7 +1876,7 @@ lnk_build_base_relocs(TP_Context *tp, // emit pages from relocs defined in section table ProfBegin("Emit Relocs From Section Table"); - for (LNK_SectionNode *sect_node = st->list.first; sect_node != 0; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != 0; sect_node = sect_node->next) { LNK_BaseRelocTask task = {0}; task.page_size = page_size; task.sect_id_map = sect_id_map; @@ -1938,7 +1938,7 @@ lnk_build_base_relocs(TP_Context *tp, ProfEnd(); if (main_page_list->count > 0) { - LNK_Section *base_reloc_sect = lnk_section_table_push(st, str8_lit(".reloc"), LNK_RELOC_SECTION_FLAGS); + LNK_Section *base_reloc_sect = lnk_section_table_push(sectab, str8_lit(".reloc"), LNK_RELOC_SECTION_FLAGS); lnk_symbol_table_push_defined_chunk(symtab, str8_lit(LNK_BASE_RELOC_SYMBOL_NAME), LNK_DefinedSymbolVisibility_Internal, 0, base_reloc_sect->root, 0, 0, 0); ProfBegin("Page List -> Array"); @@ -2772,7 +2772,7 @@ THREAD_POOL_TASK_FUNC(lnk_section_reloc_patcher) String8 image_data = task->image_data; LNK_SymbolTable *symtab = task->symtab; - LNK_SectionTable *st = task->st; + LNK_SectionTable *sectab = task->sectab; LNK_Section **sect_id_map = task->sect_id_map; U64 base_addr = task->base_addr; Rng1U64 range = task->range_arr[task_id]; @@ -2786,24 +2786,24 @@ THREAD_POOL_TASK_FUNC(lnk_section_reloc_patcher) continue; } String8 chunk_data = lnk_data_from_chunk_ref(sect_id_map, image_data, chunk->ref); - lnk_apply_reloc(base_addr, st->sect_align, st->file_align, sect_id_map, symtab, chunk_data, reloc); + lnk_apply_reloc(base_addr, sectab->sect_align, sectab->file_align, sect_id_map, symtab, chunk_data, reloc); int bad_vs = 0; (void)bad_vs; } } } internal void -lnk_patch_relocs_linker(TP_Context *tp, LNK_SymbolTable *symtab, LNK_SectionTable *st, LNK_Section **sect_id_map, String8 image_data, U64 base_addr) +lnk_patch_relocs_linker(TP_Context *tp, LNK_SymbolTable *symtab, LNK_SectionTable *sectab, LNK_Section **sect_id_map, String8 image_data, U64 base_addr) { ProfBeginFunction(); Temp scratch = scratch_begin(0,0); - LNK_SectionPtrArray sect_arr = lnk_section_ptr_array_from_list(scratch.arena, st->list); + LNK_SectionPtrArray sect_arr = lnk_section_ptr_array_from_list(scratch.arena, sectab->list); LNK_SectionRelocPatcher task = {0}; task.image_data = image_data; task.symtab = symtab; - task.st = st; + task.sectab = sectab; task.sect_id_map = sect_id_map; task.sect_arr = sect_arr.v; task.base_addr = base_addr; @@ -2829,14 +2829,14 @@ THREAD_POOL_TASK_FUNC(lnk_obj_reloc_patcher) continue; } String8 chunk_data = lnk_data_from_chunk_ref(sect_id_map, image_data, reloc->chunk->ref); - lnk_apply_reloc(task->base_addr, task->st->sect_align, task->st->file_align, task->sect_id_map, task->symtab, chunk_data, reloc); + lnk_apply_reloc(task->base_addr, task->sectab->sect_align, task->sectab->file_align, task->sect_id_map, task->symtab, chunk_data, reloc); int bad_vs = 0; (void)bad_vs; } } } internal void -lnk_patch_relocs_obj(TP_Context *tp, LNK_ObjList obj_list, LNK_SymbolTable *symtab, LNK_SectionTable *st, LNK_Section **sect_id_map, String8 image_data, U64 base_addr) +lnk_patch_relocs_obj(TP_Context *tp, LNK_ObjList obj_list, LNK_SymbolTable *symtab, LNK_SectionTable *sectab, LNK_Section **sect_id_map, String8 image_data, U64 base_addr) { ProfBeginFunction(); Temp scratch = scratch_begin(0,0); @@ -2844,7 +2844,7 @@ lnk_patch_relocs_obj(TP_Context *tp, LNK_ObjList obj_list, LNK_SymbolTable *symt LNK_ObjRelocPatcher task; task.image_data = image_data; task.symtab = symtab; - task.st = st; + task.sectab = sectab; task.sect_id_map = sect_id_map; task.base_addr = base_addr; task.obj_arr = lnk_obj_arr_from_list(scratch.arena, obj_list); @@ -2879,24 +2879,24 @@ lnk_init_section_table(LNK_SymbolTable *symtab, U64 section_virt_off, U64 sect_a { ".tls", LNK_TLS_SYMBOL_NAME, LNK_DATA_SECTION_FLAGS }, }; - LNK_SectionTable *st = lnk_section_table_alloc(section_virt_off, sect_align, file_align); + LNK_SectionTable *sectab = lnk_section_table_alloc(section_virt_off, sect_align, file_align); for (U64 i = 0; i < ArrayCount(sect_layout); ++i) { - LNK_Section *sect = lnk_section_table_push(st, str8_cstring(sect_layout[i].name), sect_layout[i].flags); + LNK_Section *sect = lnk_section_table_push(sectab, str8_cstring(sect_layout[i].name), sect_layout[i].flags); sect->symbol_name = str8_cstring(sect_layout[i].symbol); sect->symbol_name = push_str8_copy(sect->arena, sect->symbol_name); lnk_symbol_table_push_defined_chunk(symtab, sect->symbol_name, LNK_DefinedSymbolVisibility_Internal, 0, sect->root, 0, 0, 0); } - st->null_sect = lnk_section_list_remove(&st->list, str8_lit(".null")); + sectab->null_sect = lnk_section_list_remove(§ab->list, str8_lit(".null")); // dont build layout because we discard debug from image and move it to pdb - LNK_Section *debug_sect = lnk_section_table_search(st, str8_lit(".debug")); + LNK_Section *debug_sect = lnk_section_table_search(sectab, str8_lit(".debug")); debug_sect->emit_header = 0; debug_sect->has_layout = 0; ProfEnd(); - return st; + return sectab; } internal LNK_MergeDirectiveList @@ -2928,7 +2928,7 @@ lnk_init_merge_directive_list(Arena *arena, LNK_ObjList obj_list) } internal void -lnk_discard_meta_data_sections(LNK_SectionTable *st) +lnk_discard_meta_data_sections(LNK_SectionTable *sectab) { static char * meta_data_sect_arr[] = { ".gfids", @@ -2938,7 +2938,7 @@ lnk_discard_meta_data_sections(LNK_SectionTable *st) }; for (U64 meta_idx = 0; meta_idx < ArrayCount(meta_data_sect_arr); meta_idx += 1) { String8 name = str8_cstring(meta_data_sect_arr[meta_idx]); - LNK_Section *sect = lnk_section_table_search(st, name); + LNK_Section *sect = lnk_section_table_search(sectab, name); if (sect) { lnk_visit_chunks(sect->id, sect->root, lnk_chunk_mark_discarded, NULL); sect->root->is_discarded = 0; @@ -2960,15 +2960,15 @@ lnk_pdata_is_before_x8664(void *raw_a, void *raw_b) //////////////////////////////// internal void -lnk_log_size_breakdown(LNK_SectionTable *st, LNK_SymbolTable *symtab) +lnk_log_size_breakdown(LNK_SectionTable *sectab, LNK_SymbolTable *symtab) { Temp scratch = scratch_begin(0, 0); - LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, st); + LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, sectab); U64 code_size = 0; U64 data_size = 0; - for (LNK_SectionNode *sect_node = st->list.first; sect_node != NULL; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != NULL; sect_node = sect_node->next) { LNK_Section *sect = §_node->data; if (sect->has_layout) { U64 sect_size = lnk_file_size_from_chunk_ref(sect_id_map, sect->root->ref); @@ -2982,21 +2982,21 @@ lnk_log_size_breakdown(LNK_SectionTable *st, LNK_SymbolTable *symtab) LNK_Symbol *dos_header_symbol = lnk_symbol_table_search(symtab, LNK_SymbolScopeFlag_Internal, str8_lit(LNK_DOS_HEADER_SYMBOL_NAME)); LNK_Symbol *dos_program_symbol = lnk_symbol_table_search(symtab, LNK_SymbolScopeFlag_Internal, str8_lit(LNK_DOS_PROGRAM_SYMBOL_NAME)); - LNK_Symbol *COFF_FileHeader_symbol = lnk_symbol_table_search(symtab, LNK_SymbolScopeFlag_Internal, str8_lit(LNK_COFF_FILE_HEADER_SYMBOL_NAME)); + LNK_Symbol *coff_file_header_symbol = lnk_symbol_table_search(symtab, LNK_SymbolScopeFlag_Internal, str8_lit(LNK_COFF_FILE_HEADER_SYMBOL_NAME)); LNK_Symbol *coff_section_header_symbol = lnk_symbol_table_search(symtab, LNK_SymbolScopeFlag_Internal, str8_lit(LNK_COFF_SECT_HEADER_ARRAY_SYMBOL_NAME)); LNK_Symbol *pe_opt_header_symbol = lnk_symbol_table_search(symtab, LNK_SymbolScopeFlag_Internal, str8_lit(LNK_PE_OPT_HEADER_SYMBOL_NAME)); LNK_Symbol *pe_directories_symbol = lnk_symbol_table_search(symtab, LNK_SymbolScopeFlag_Internal, str8_lit(LNK_PE_DIRECTORY_ARRAY_SYMBOL_NAME)); LNK_Chunk *dos_header_chunk = dos_header_symbol->u.defined.u.chunk; LNK_Chunk *dos_program_chunk = dos_program_symbol->u.defined.u.chunk; - LNK_Chunk *COFF_FileHeader_chunk = COFF_FileHeader_symbol->u.defined.u.chunk; + LNK_Chunk *coff_file_header_chunk = coff_file_header_symbol->u.defined.u.chunk; LNK_Chunk *coff_section_header_chunk = coff_section_header_symbol->u.defined.u.chunk; LNK_Chunk *pe_opt_header_chunk = pe_opt_header_symbol->u.defined.u.chunk; LNK_Chunk *pe_directories_chunk = pe_directories_symbol->u.defined.u.chunk; U64 dos_header_size = lnk_file_size_from_chunk_ref(sect_id_map, dos_header_chunk->ref); U64 dos_program_size = lnk_file_size_from_chunk_ref(sect_id_map, dos_program_chunk->ref); - U64 COFF_FileHeader_size = lnk_file_size_from_chunk_ref(sect_id_map, COFF_FileHeader_chunk->ref); + U64 coff_file_header_size = lnk_file_size_from_chunk_ref(sect_id_map, coff_file_header_chunk->ref); U64 coff_section_header_size = lnk_file_size_from_chunk_ref(sect_id_map, coff_section_header_chunk->ref); U64 pe_opt_header_size = lnk_file_size_from_chunk_ref(sect_id_map, pe_opt_header_chunk->ref); U64 pe_directories_size = lnk_file_size_from_chunk_ref(sect_id_map, pe_directories_chunk->ref); @@ -3005,7 +3005,7 @@ lnk_log_size_breakdown(LNK_SectionTable *st, LNK_SymbolTable *symtab) str8_list_pushf(scratch.arena, &output_list, "--- Image Size Breakdown -------------------------------------------------------"); str8_list_pushf(scratch.arena, &output_list, " DOS Header: %M", dos_header_size); str8_list_pushf(scratch.arena, &output_list, " DOS Program Stub: %M", dos_program_size); - str8_list_pushf(scratch.arena, &output_list, " COFF Header: %M", COFF_FileHeader_size); + str8_list_pushf(scratch.arena, &output_list, " COFF Header: %M", coff_file_header_size); str8_list_pushf(scratch.arena, &output_list, " COFF Section Headers: %M", coff_section_header_size); str8_list_pushf(scratch.arena, &output_list, " PE Header: %M", pe_opt_header_size); str8_list_pushf(scratch.arena, &output_list, " Directories: %M", pe_directories_size); @@ -3020,7 +3020,7 @@ lnk_log_size_breakdown(LNK_SectionTable *st, LNK_SymbolTable *symtab) } internal void -lnk_log_link_stats(LNK_ObjList obj_list, LNK_LibList *lib_index, LNK_SectionTable *st) +lnk_log_link_stats(LNK_ObjList obj_list, LNK_LibList *lib_index, LNK_SectionTable *sectab) { Temp scratch = scratch_begin(0, 0); @@ -3029,7 +3029,7 @@ lnk_log_link_stats(LNK_ObjList obj_list, LNK_LibList *lib_index, LNK_SectionTabl lib_count += lib_index[i].count; } U32 reloc_count = 0; - for (LNK_SectionNode *sect_node = st->list.first; sect_node != NULL; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != NULL; sect_node = sect_node->next) { reloc_count += sect_node->data.reloc_list.count; } @@ -3204,18 +3204,18 @@ lnk_chunk_off_pair_array_bsearch(LNK_ChunkOffPair *arr, U64 count, U64 value) } internal String8List -lnk_build_rad_chunk_map(Arena *arena, String8 image_data, U64 thread_count, LNK_ObjList objs, LNK_LibList lib_index[LNK_InputSource_Count], LNK_SectionTable *st, LNK_SymbolTable *symtab) +lnk_build_rad_chunk_map(Arena *arena, String8 image_data, U64 thread_count, LNK_ObjList objs, LNK_LibList lib_index[LNK_InputSource_Count], LNK_SectionTable *sectab, LNK_SymbolTable *symtab) { ProfBeginFunction(); Temp scratch = scratch_begin(&arena, 1); String8List map = {0}; - LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, st); + LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, sectab); ProfBegin("SECTIONS"); str8_list_pushf(arena, &map, "# SECTIONS\n"); - for (LNK_SectionNode *sect_n = st->list.first; sect_n != 0; sect_n = sect_n->next) { + for (LNK_SectionNode *sect_n = sectab->list.first; sect_n != 0; sect_n = sect_n->next) { LNK_Section *sect = §_n->data; if (sect->has_layout) { LNK_Chunk **chunks = push_array_no_zero(scratch.arena, LNK_Chunk *, sect->layout.total_count); @@ -3436,7 +3436,7 @@ lnk_run(int argc, char **argv) // state LNK_SymbolTable *symtab = lnk_symbol_table_init(tp_arena); - LNK_SectionTable *st = lnk_init_section_table(symtab, config->section_virt_off, config->sect_align, config->file_align); + LNK_SectionTable *sectab = lnk_init_section_table(symtab, config->section_virt_off, config->sect_align, config->file_align); LNK_ImportTable *imptab_static = 0; LNK_ImportTable *imptab_delayed = 0; LNK_ExportTable *exptab = lnk_export_table_alloc(); @@ -3682,7 +3682,7 @@ lnk_run(int argc, char **argv) Assert(config->machine != COFF_MachineType_Unknown); B32 is_unloadable = !!(config->flags & LNK_ConfigFlag_DelayUnload); B32 is_bindable = !!(config->flags & LNK_ConfigFlag_DelayBind); - imptab_delayed = lnk_import_table_alloc_delayed(st, symtab, config->machine, is_unloadable, is_bindable); + imptab_delayed = lnk_import_table_alloc_delayed(sectab, symtab, config->machine, is_unloadable, is_bindable); } LNK_ImportDLL *dll = lnk_import_table_search_dll(imptab_delayed, import_header->dll_name); if (!dll) { @@ -3695,7 +3695,7 @@ lnk_run(int argc, char **argv) } else { if (!imptab_static) { Assert(config->machine != COFF_MachineType_Unknown); - imptab_static = lnk_import_table_alloc_static(st, symtab, config->machine); + imptab_static = lnk_import_table_alloc_static(sectab, symtab, config->machine); } LNK_ImportDLL *dll = lnk_import_table_search_dll(imptab_static, import_header->dll_name); if (!dll) { @@ -3769,7 +3769,7 @@ lnk_run(int argc, char **argv) } ProfEnd(); - LNK_ObjNodeArray obj_node_arr = lnk_obj_list_push_parallel(tp, tp_arena, &obj_list, st, config->function_pad_min, unique_obj_input_list.count, input_obj_arr); + LNK_ObjNodeArray obj_node_arr = lnk_obj_list_push_parallel(tp, tp_arena, &obj_list, sectab, config->function_pad_min, unique_obj_input_list.count, input_obj_arr); ProfBegin("Machine Compat Check"); for (U64 obj_idx = 0; obj_idx < obj_node_arr.count; ++obj_idx) { @@ -4012,7 +4012,7 @@ lnk_run(int argc, char **argv) String8 obj_name = str8_lit("* Resources *"); String8 obj_data = lnk_obj_from_res_file_list(tp, tp_arena->v[0], - st, + sectab, symtab, res_data_list, res_path_list, @@ -4101,14 +4101,14 @@ lnk_run(int argc, char **argv) case State_DiscardMetaDataSections: { ProfBegin("Discard Meta Data Sections"); - lnk_discard_meta_data_sections(st); + lnk_discard_meta_data_sections(sectab); ProfEnd(); } break; case State_BuildDebugDirectory: { ProfBegin("Build Debug Directory"); // push debug directory layout chunks - LNK_Section *debug_sect = lnk_section_table_search(st, str8_lit(".rdata")); + LNK_Section *debug_sect = lnk_section_table_search(sectab, str8_lit(".rdata")); LNK_Chunk *debug_chunk = lnk_section_push_chunk_list(debug_sect, debug_sect->root, str8_zero()); LNK_Chunk *debug_dir_array_chunk = lnk_section_push_chunk_list(debug_sect, debug_chunk, str8_zero()); @@ -4117,12 +4117,12 @@ lnk_run(int argc, char **argv) // debug entry for PDB if (config->debug_mode != LNK_DebugMode_None && config->debug_mode != LNK_DebugMode_Null) { - lnk_build_debug_pdb(st, symtab, debug_sect, debug_dir_array_chunk, config->time_stamp, config->guid, config->age, config->pdb_alt_path); + lnk_build_debug_pdb(sectab, symtab, debug_sect, debug_dir_array_chunk, config->time_stamp, config->guid, config->age, config->pdb_alt_path); } // debug entry for RDI if (config->rad_debug == LNK_SwitchState_Yes) { - lnk_build_debug_rdi(st, symtab, debug_sect, debug_dir_array_chunk, config->time_stamp, config->guid, config->rad_debug_alt_path); + lnk_build_debug_rdi(sectab, symtab, debug_sect, debug_dir_array_chunk, config->time_stamp, config->guid, config->rad_debug_alt_path); } ProfEnd(); @@ -4139,38 +4139,38 @@ lnk_run(int argc, char **argv) lnk_collect_exports_from_obj_directives(exptab, obj_list, symtab); // build export table section - lnk_build_edata(exptab, st, symtab, config->image_name, config->machine); + lnk_build_edata(exptab, sectab, symtab, config->image_name, config->machine); ProfEnd(); } break; case State_MergeSections: { ProfBegin("Merge Sections"); LNK_MergeDirectiveList merge_list = lnk_init_merge_directive_list(scratch.arena, obj_list); - lnk_section_table_merge(st, merge_list); + lnk_section_table_merge(sectab, merge_list); ProfEnd(); } break; case State_BuildCFGuards: { ProfBegin("Build CF Guards"); B32 emit_suppress_flag = 1; // MSVC emits this flag but every entry has zero set. - lnk_build_guard_tables(tp, st, symtab, exptab, obj_list, config->machine, config->entry_point_name, config->guard_flags, emit_suppress_flag); + lnk_build_guard_tables(tp, sectab, symtab, exptab, obj_list, config->machine, config->entry_point_name, config->guard_flags, emit_suppress_flag); ProfEnd(); } break; case State_BuildBaseRelocs: { ProfBegin("Base Relocs"); - lnk_build_base_relocs(tp, tp_arena, st, symtab, config->machine, config->page_size, config->file_characteristics, obj_list); + lnk_build_base_relocs(tp, tp_arena, sectab, symtab, config->machine, config->page_size, config->file_characteristics, obj_list); ProfEnd(); } break; case State_FinalizeImage: { ProfBegin("Build Win32 Header"); // remove empty section headers from output image - lnk_section_table_remove_empties(st, symtab); + lnk_section_table_remove_empties(sectab, symtab); // collect output sections - LNK_SectionArray out_sect_arr = lnk_section_table_get_output_sections(scratch.arena, st); + LNK_SectionArray out_sect_arr = lnk_section_table_get_output_sections(scratch.arena, sectab); // push back null section where we store image header - LNK_Section *header_sect = lnk_section_table_push_null(st); + LNK_Section *header_sect = lnk_section_table_push_null(sectab); // fill out header section with win32 image header data lnk_build_win32_image_header(symtab, header_sect, header_sect->root, config, out_sect_arr); @@ -4178,24 +4178,24 @@ lnk_run(int argc, char **argv) ProfEnd(); // finalize sections - lnk_section_table_build_data(tp, st, config->machine); - lnk_section_table_assign_indices(st); - lnk_section_table_assign_virtual_offsets(st); - lnk_section_table_assign_file_offsets(st); + lnk_section_table_build_data(tp, sectab, config->machine); + lnk_section_table_assign_indices(sectab); + lnk_section_table_assign_virtual_offsets(sectab); + lnk_section_table_assign_file_offsets(sectab); ProfBegin("Image Serialize"); - image_data = lnk_section_table_serialize(tp, scratch.arena, st, config->machine); + image_data = lnk_section_table_serialize(tp, scratch.arena, sectab, config->machine); Assert(image_data.size > 0); ProfEnd(); // image layout is finalized, section id map is stable after this point - LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, st); + LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, sectab); ProfBegin("Patch Relocs"); U64 base_addr = lnk_get_base_addr(config); - lnk_patch_relocs_obj(tp, obj_list, symtab, st, sect_id_map, image_data, base_addr); - lnk_patch_relocs_linker(tp, symtab, st, sect_id_map, image_data, base_addr); + lnk_patch_relocs_obj(tp, obj_list, symtab, sectab, sect_id_map, image_data, base_addr); + lnk_patch_relocs_linker(tp, symtab, sectab, sect_id_map, image_data, base_addr); ProfEnd(); @@ -4333,7 +4333,7 @@ lnk_run(int argc, char **argv) } break; case State_BuildRadChunkMap: { ProfBegin("RAD Chunk Map"); - String8List map = lnk_build_rad_chunk_map(scratch.arena, image_data, config->worker_count, obj_list, lib_index, st, symtab); + String8List map = lnk_build_rad_chunk_map(scratch.arena, image_data, config->worker_count, obj_list, lib_index, sectab, symtab); lnk_write_data_list_to_file_path(config->rad_chunk_map_name, config->temp_rad_chunk_map_name, map); ProfEnd(); } break; @@ -4343,12 +4343,12 @@ lnk_run(int argc, char **argv) LNK_CodeViewInput input = lnk_make_code_view_input(tp, tp_arena, config->lib_dir_list, obj_list); CV_DebugT *types = lnk_import_types(tp, tp_arena, &input); - LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, st); + LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, sectab); if (config->rad_debug == LNK_SwitchState_Yes) { lnk_timer_begin(LNK_Timer_Rdi); RDI_Arch arch = rdi_arch_from_coff_machine(config->machine); - LNK_SectionArray image_sects = lnk_section_table_get_output_sections(scratch.arena, st); + LNK_SectionArray image_sects = lnk_section_table_get_output_sections(scratch.arena, sectab); String8List rdi_data = lnk_build_rad_debug_info(tp, tp_arena, @@ -4553,10 +4553,10 @@ lnk_run(int argc, char **argv) } if (lnk_get_log_status(LNK_Log_SizeBreakdown)) { - lnk_log_size_breakdown(st, symtab); + lnk_log_size_breakdown(sectab, symtab); } if (lnk_get_log_status(LNK_Log_LinkStats)) { - lnk_log_link_stats(obj_list, lib_index, st); + lnk_log_link_stats(obj_list, lib_index, sectab); } if (lnk_get_log_status(LNK_Log_Timers)) { lnk_log_timers(); @@ -4566,7 +4566,7 @@ lnk_run(int argc, char **argv) // linker is done, punt memory release to OS //arena_release(ht_arena); - //lnk_section_table_release(&st); + //lnk_section_table_release(§ab); //lnk_export_table_release(&export_table); //lnk_import_table_release(&imptab_static); //lnk_import_table_release(&imptab_delayed); diff --git a/src/linker/lnk.h b/src/linker/lnk.h index d6732174..2790fa60 100644 --- a/src/linker/lnk.h +++ b/src/linker/lnk.h @@ -204,7 +204,7 @@ typedef struct { String8 image_data; LNK_SymbolTable *symtab; - LNK_SectionTable *st; + LNK_SectionTable *sectab; LNK_Section **sect_id_map; U64 base_addr; LNK_Section **sect_arr; @@ -215,7 +215,7 @@ typedef struct { String8 image_data; LNK_SymbolTable *symtab; - LNK_SectionTable *st; + LNK_SectionTable *sectab; LNK_Section **sect_id_map; U64 base_addr; LNK_Obj **obj_arr; @@ -262,10 +262,10 @@ internal void lnk_merge_manifest_files(String8 mt_path, String8 out_name, Str //////////////////////////////// // Resources -internal void lnk_serialize_pe_resource_tree(LNK_SectionTable *st, LNK_SymbolTable *symtab, PE_ResourceDir *root_dir); -internal void lnk_add_resource_debug_s(LNK_SectionTable *st, LNK_SymbolTable *symtab, String8 obj_path, String8 cwd_path, String8 exe_path, CV_Arch arch, String8List res_file_list, MD5Hash *res_hash_array); +internal void lnk_serialize_pe_resource_tree(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, PE_ResourceDir *root_dir); +internal void lnk_add_resource_debug_s(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, String8 obj_path, String8 cwd_path, String8 exe_path, CV_Arch arch, String8List res_file_list, MD5Hash *res_hash_array); internal String8 lnk_make_res_obj(TP_Context *tp, Arena *arena, PE_ResourceDir *root_dir, COFF_MachineType machine, COFF_TimeStamp time_stamp, String8 path, String8 cwd_path, String8 exe_path, String8List res_file_list, MD5Hash *res_hash_array); -internal String8 lnk_obj_from_res_file_list(TP_Context *tp, Arena *arena, LNK_SectionTable *st, LNK_SymbolTable *symtab, String8List res_file_list, String8List res_path_list, COFF_MachineType machine, U32 time_stamp, String8 work_dir, PathStyle system_path_style, String8 obj_name); +internal String8 lnk_obj_from_res_file_list(TP_Context *tp, Arena *arena, LNK_SectionTable *sectab, LNK_SymbolTable *symtab, String8List res_file_list, String8List res_path_list, COFF_MachineType machine, U32 time_stamp, String8 work_dir, PathStyle system_path_style, String8 obj_name); //////////////////////////////// // Debug @@ -275,10 +275,10 @@ internal String8 lnk_make_linker_coff_obj(TP_Context *tp, Arena *arena, COFF_Tim //////////////////////////////// // Win32 Image Helpers -internal void lnk_build_debug_pdb(LNK_SectionTable *st, LNK_SymbolTable *symtab, LNK_Section *debug_sect, LNK_Chunk *debug_dir_array_chunk, COFF_TimeStamp time_stamp, Guid guid, U32 age, String8 pdb_path); -internal void lnk_build_debug_rdi(LNK_SectionTable *st, LNK_SymbolTable *symtab, LNK_Section *debug_sect, LNK_Chunk *debug_dir_array_chunk, COFF_TimeStamp time_stamp, Guid guid, String8 rdi_path); -internal void lnk_build_guard_tables(TP_Context *tp, LNK_SectionTable *st, LNK_SymbolTable *symtab, LNK_ExportTable *exptab, LNK_ObjList obj_list, COFF_MachineType machine, String8 entry_point_name, LNK_GuardFlags guard_flags, B32 emit_suppress_flag); -internal void lnk_build_base_relocs(TP_Context *tp, TP_Arena *tp_arena, LNK_SectionTable *st, LNK_SymbolTable *symtab, COFF_MachineType machine, U64 page_size, PE_ImageFileCharacteristics file_chars, LNK_ObjList obj_list); +internal void lnk_build_debug_pdb(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, LNK_Section *debug_sect, LNK_Chunk *debug_dir_array_chunk, COFF_TimeStamp time_stamp, Guid guid, U32 age, String8 pdb_path); +internal void lnk_build_debug_rdi(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, LNK_Section *debug_sect, LNK_Chunk *debug_dir_array_chunk, COFF_TimeStamp time_stamp, Guid guid, String8 rdi_path); +internal void lnk_build_guard_tables(TP_Context *tp, LNK_SectionTable *sectab, LNK_SymbolTable *symtab, LNK_ExportTable *exptab, LNK_ObjList obj_list, COFF_MachineType machine, String8 entry_point_name, LNK_GuardFlags guard_flags, B32 emit_suppress_flag); +internal void lnk_build_base_relocs(TP_Context *tp, TP_Arena *tp_arena, LNK_SectionTable *sectab, LNK_SymbolTable *symtab, COFF_MachineType machine, U64 page_size, PE_ImageFileCharacteristics file_chars, LNK_ObjList obj_list); internal LNK_Chunk * lnk_build_dos_header(LNK_SymbolTable *symtab, LNK_Section *header_sect, LNK_Chunk *parent_chunk); internal LNK_Chunk * lnk_build_pe_magic(LNK_SymbolTable *symtab, LNK_Section *header_sect, LNK_Chunk *parent); internal LNK_Chunk * lnk_build_coff_file_header(LNK_SymbolTable *symtab, LNK_Section *header_sect, LNK_Chunk *parent, COFF_MachineType machine, COFF_TimeStamp time_stamp, PE_ImageFileCharacteristics file_characteristics); @@ -290,15 +290,15 @@ internal LNK_Chunk * lnk_build_win32_image_header(LNK_SymbolTable *symtab, LNK_S //////////////////////////////// // Relocs -internal void lnk_patch_relocs_linker(TP_Context *tp, LNK_SymbolTable *symtab, LNK_SectionTable *st, LNK_Section **sect_id_map, String8 image_data, U64 base_addr); -internal void lnk_patch_relocs_obj(TP_Context *tp, LNK_ObjList obj_list, LNK_SymbolTable *symtab, LNK_SectionTable *st, LNK_Section **sect_id_map, String8 image_data, U64 base_addr); +internal void lnk_patch_relocs_linker(TP_Context *tp, LNK_SymbolTable *symtab, LNK_SectionTable *sectab, LNK_Section **sect_id_map, String8 image_data, U64 base_addr); +internal void lnk_patch_relocs_obj(TP_Context *tp, LNK_ObjList obj_list, LNK_SymbolTable *symtab, LNK_SectionTable *sectab, LNK_Section **sect_id_map, String8 image_data, U64 base_addr); internal void lnk_apply_reloc(U64 base_addr, U64 virt_align, U64 file_align, LNK_Section **sect_id_map, LNK_SymbolTable *symtab, String8 chunk_data, LNK_Reloc *reloc); //////////////////////////////// -internal void lnk_log_size_breakdown(LNK_SectionTable *st, LNK_SymbolTable *symtab); -internal void lnk_log_link_stats(LNK_ObjList obj_list, LNK_LibList *lib_index, LNK_SectionTable *st); +internal void lnk_log_size_breakdown(LNK_SectionTable *sectab, LNK_SymbolTable *symtab); +internal void lnk_log_link_stats(LNK_ObjList obj_list, LNK_LibList *lib_index, LNK_SectionTable *sectab); internal void lnk_log_timers(void); //////////////////////////////// diff --git a/src/linker/lnk_export_table.c b/src/linker/lnk_export_table.c index ff36c649..d2beb95e 100644 --- a/src/linker/lnk_export_table.c +++ b/src/linker/lnk_export_table.c @@ -171,7 +171,7 @@ lnk_export_array_from_list(Arena *arena, LNK_ExportList list) } internal void -lnk_build_edata(LNK_ExportTable *exptab, LNK_SectionTable *st, LNK_SymbolTable *symtab, String8 image_name, COFF_MachineType machine) +lnk_build_edata(LNK_ExportTable *exptab, LNK_SectionTable *sectab, LNK_SymbolTable *symtab, String8 image_name, COFF_MachineType machine) { ProfBeginFunction(); Temp scratch = scratch_begin(0, 0); @@ -195,7 +195,7 @@ lnk_build_edata(LNK_ExportTable *exptab, LNK_SectionTable *st, LNK_SymbolTable * } } - LNK_Section *edata = lnk_section_table_search(st, str8_lit(".edata")); + LNK_Section *edata = lnk_section_table_search(sectab, str8_lit(".edata")); // push header PE_ExportTableHeader *header = push_array(edata->arena, PE_ExportTableHeader, 1); diff --git a/src/linker/lnk_export_table.h b/src/linker/lnk_export_table.h index 25cc31ca..08be801f 100644 --- a/src/linker/lnk_export_table.h +++ b/src/linker/lnk_export_table.h @@ -41,6 +41,6 @@ internal LNK_ExportTable * lnk_export_table_alloc(void); internal void lnk_export_table_release(LNK_ExportTable **exptab_ptr); internal LNK_Export * lnk_export_table_search(LNK_ExportTable *exptab, String8 name); internal void lnk_collect_exports_from_def_files(LNK_ExportTable *exptab, String8List path_list); -internal void lnk_build_edata(LNK_ExportTable *exptab, LNK_SectionTable *st, LNK_SymbolTable *symtab, String8 image_name, COFF_MachineType machine); +internal void lnk_build_edata(LNK_ExportTable *exptab, LNK_SectionTable *sectab, LNK_SymbolTable *symtab, String8 image_name, COFF_MachineType machine); internal void lnk_collect_exports_from_obj_directives(LNK_ExportTable *exptab, LNK_ObjList obj_list, LNK_SymbolTable *symtab); diff --git a/src/linker/lnk_import_table.c b/src/linker/lnk_import_table.c index 677ae6ba..c1973f30 100644 --- a/src/linker/lnk_import_table.c +++ b/src/linker/lnk_import_table.c @@ -2,12 +2,12 @@ // Licensed under the MIT license (https://opensource.org/license/mit/) internal LNK_ImportTable * -lnk_import_table_alloc_static(LNK_SectionTable *st, LNK_SymbolTable *symtab, COFF_MachineType machine) +lnk_import_table_alloc_static(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, COFF_MachineType machine) { ProfBeginFunction(); - LNK_Section *data_sect = lnk_section_table_push(st, str8_lit(".idata"), LNK_IDATA_SECTION_FLAGS); - LNK_Section *code_sect = lnk_section_table_search(st, str8_lit(".text")); + LNK_Section *data_sect = lnk_section_table_push(sectab, str8_lit(".idata"), LNK_IDATA_SECTION_FLAGS); + LNK_Section *code_sect = lnk_section_table_search(sectab, str8_lit(".text")); LNK_Chunk *dll_table_chunk = lnk_section_push_chunk_list(data_sect, data_sect->root, str8_zero()); LNK_Chunk *int_chunk = lnk_section_push_chunk_list(data_sect, data_sect->root, str8_zero()); @@ -47,12 +47,12 @@ lnk_import_table_alloc_static(LNK_SectionTable *st, LNK_SymbolTable *symtab, COF } internal LNK_ImportTable * -lnk_import_table_alloc_delayed(LNK_SectionTable *st, LNK_SymbolTable *symtab, COFF_MachineType machine, B32 is_unloadable, B32 is_bindable) +lnk_import_table_alloc_delayed(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, COFF_MachineType machine, B32 is_unloadable, B32 is_bindable) { ProfBeginFunction(); - LNK_Section *data_sect = lnk_section_table_push(st, str8_lit(".didat"), LNK_DEBUG_DIR_SECTION_FLAGS); - LNK_Section *code_sect = lnk_section_table_search(st, str8_lit(".text")); + LNK_Section *data_sect = lnk_section_table_push(sectab, str8_lit(".didat"), LNK_DEBUG_DIR_SECTION_FLAGS); + LNK_Section *code_sect = lnk_section_table_search(sectab, str8_lit(".text")); LNK_Chunk *dll_table_chunk = lnk_section_push_chunk_list(data_sect, data_sect->root, str8_zero()); LNK_Chunk *int_chunk = lnk_section_push_chunk_list(data_sect, data_sect->root, str8_zero()); diff --git a/src/linker/lnk_import_table.h b/src/linker/lnk_import_table.h index 6005b622..3bb9eb2f 100644 --- a/src/linker/lnk_import_table.h +++ b/src/linker/lnk_import_table.h @@ -59,8 +59,8 @@ typedef struct LNK_ImportTable HashTable *dll_ht; } LNK_ImportTable; -internal LNK_ImportTable * lnk_import_table_alloc_static(LNK_SectionTable *st, LNK_SymbolTable *symtab, COFF_MachineType machine); -internal LNK_ImportTable * lnk_import_table_alloc_delayed(LNK_SectionTable *st, LNK_SymbolTable *symtab, COFF_MachineType machine, B32 is_unloadable, B32 is_bindable); +internal LNK_ImportTable * lnk_import_table_alloc_static(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, COFF_MachineType machine); +internal LNK_ImportTable * lnk_import_table_alloc_delayed(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, COFF_MachineType machine, B32 is_unloadable, B32 is_bindable); internal void lnk_import_table_release(LNK_ImportTable **imptab); internal LNK_ImportDLL * lnk_import_table_push_dll_static(LNK_ImportTable *imptab, LNK_SymbolTable *symtab, String8 dll_name, COFF_MachineType machine); internal LNK_ImportDLL * lnk_import_table_push_dll_delayed(LNK_ImportTable *imptab, LNK_SymbolTable *symtab, String8 dll_name, COFF_MachineType machine); diff --git a/src/linker/lnk_lib.c b/src/linker/lnk_lib.c index fc4e54d0..d02f4fac 100644 --- a/src/linker/lnk_lib.c +++ b/src/linker/lnk_lib.c @@ -939,16 +939,16 @@ lnk_build_import_lib(TP_Context *tp, TP_Arena *arena, COFF_MachineType machine, } LNK_InputObj **inputs = lnk_array_from_input_obj_list(scratch.arena, input_obj_list); - LNK_SectionTable *st = lnk_section_table_alloc(0,0,0); + LNK_SectionTable *sectab = lnk_section_table_alloc(0,0,0); LNK_ObjList obj_list = {0}; - lnk_obj_list_push_parallel(tp, arena, &obj_list, st, 0, input_obj_list.count, inputs); + lnk_obj_list_push_parallel(tp, arena, &obj_list, sectab, 0, input_obj_list.count, inputs); LNK_LibBuild import_lib = lnk_build_lib(scratch.arena, machine, time_stamp, dll_name, obj_list, exptab); B32 emit_second_member = 0; // MSVC linker refuses to link with lib that has the second member. String8List coff_archive_data = lnk_coff_archive_from_lib_build(arena->v[0], &import_lib, emit_second_member, time_stamp, /* -rw-r--r-- */ 644); // cleanup memory - lnk_section_table_release(&st); + lnk_section_table_release(§ab); scratch_end(scratch); ProfEnd(); diff --git a/src/linker/lnk_obj.c b/src/linker/lnk_obj.c index b03d9fa8..af16561c 100644 --- a/src/linker/lnk_obj.c +++ b/src/linker/lnk_obj.c @@ -546,7 +546,7 @@ THREAD_POOL_TASK_FUNC(lnk_chunk_counter) for (U64 chunk_idx = 0; chunk_idx < obj->chunk_count; chunk_idx += 1) { String8 name = obj->sect_name_arr[chunk_idx]; LNK_Chunk *chunk = obj->chunk_arr[chunk_idx]; - LNK_Section *sect = lnk_section_table_search(task->st, name); + LNK_Section *sect = lnk_section_table_search(task->sectab, name); U64 count = 0; lnk_visit_chunks(0, chunk, lnk_chunk_get_count_cb, &count); @@ -586,7 +586,7 @@ THREAD_POOL_TASK_FUNC(lnk_chunk_ref_assigner) LNK_Chunk *chunk = obj->chunk_arr[chunk_idx]; // :find_chunk_section - LNK_Section *sect = lnk_section_table_search(task->st, name); + LNK_Section *sect = lnk_section_table_search(task->sectab, name); // :chunk_ref_assign LNK_ChunkRefAssign ctx = {0}; @@ -605,7 +605,7 @@ internal LNK_ObjNodeArray lnk_obj_list_push_parallel(TP_Context *tp, TP_Arena *arena, LNK_ObjList *obj_list, - LNK_SectionTable *st, + LNK_SectionTable *sectab, U64 *function_pad_min, U64 input_count, LNK_InputObj **inputs) @@ -627,7 +627,7 @@ lnk_obj_list_push_parallel(TP_Context *tp, } ProfEnd(); - if (st) { + if (sectab) { ProfBegin("Section Table Update"); { TP_Temp temp = tp_temp_begin(arena); @@ -647,7 +647,7 @@ lnk_obj_list_push_parallel(TP_Context *tp, HashTable *ht = hash_table_init(arena->v[0], 128); - for (LNK_SectionNode *sect_node = st->list.first; sect_node != 0; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != 0; sect_node = sect_node->next) { LNK_Section *sect = §_node->data; hash_table_push_string_u64(arena->v[0], ht, sect->name, sect->flags); } @@ -690,7 +690,7 @@ lnk_obj_list_push_parallel(TP_Context *tp, // push new sections for :find_chunk_section for (LNK_SectDefn *curr = new_list.first; curr != 0; curr = curr->next) { - lnk_section_table_push(st, curr->name, curr->flags & ~COFF_SectionFlags_LnkFlags); + lnk_section_table_push(sectab, curr->name, curr->flags & ~COFF_SectionFlags_LnkFlags); } tp_temp_end(temp); @@ -700,20 +700,20 @@ lnk_obj_list_push_parallel(TP_Context *tp, ProfBegin("Count Chunks Per Section"); U64 **chunk_ids; { - U64 **chunk_counts = push_array_no_zero(scratch.arena, U64 *, st->id_max); - for (U64 sect_idx = 0; sect_idx < st->id_max; sect_idx += 1) { + U64 **chunk_counts = push_array_no_zero(scratch.arena, U64 *, sectab->id_max); + for (U64 sect_idx = 0; sect_idx < sectab->id_max; sect_idx += 1) { chunk_counts[sect_idx] = push_array(scratch.arena, U64, obj_arr.count); } LNK_ChunkCounter task = {0}; - task.st = st; + task.sectab = sectab; task.obj_arr = obj_arr.v; task.chunk_counts = chunk_counts; tp_for_parallel(tp, 0, obj_arr.count, lnk_chunk_counter, &task); chunk_ids = chunk_counts; - for (U64 sect_idx = 1; sect_idx < st->id_max; sect_idx += 1) { - LNK_Section *sect = lnk_section_table_search_id(st, sect_idx); + for (U64 sect_idx = 1; sect_idx < sectab->id_max; sect_idx += 1) { + LNK_Section *sect = lnk_section_table_search_id(sectab, sect_idx); if (!sect) continue; for (U64 obj_idx = 0; obj_idx < obj_arr.count; obj_idx += 1) { U64 chunk_id_base = sect->cman->total_chunk_count; @@ -727,16 +727,16 @@ lnk_obj_list_push_parallel(TP_Context *tp, ProfBegin("Assign Chunk Refs"); { LNK_ChunkRefAssigner task; - task.st = st; + task.sectab = sectab; task.range_arr = tp_divide_work(scratch.arena, obj_arr.count, tp->worker_count); task.chunk_ids = chunk_ids; task.obj_arr = obj_arr.v; - task.nosort_chunk_list_arr_arr = lnk_make_chunk_list_arr_arr(scratch.arena, st->id_max, tp->worker_count); - task.chunk_list_arr_arr = lnk_make_chunk_list_arr_arr(scratch.arena, st->id_max, tp->worker_count); + task.nosort_chunk_list_arr_arr = lnk_make_chunk_list_arr_arr(scratch.arena, sectab->id_max, tp->worker_count); + task.chunk_list_arr_arr = lnk_make_chunk_list_arr_arr(scratch.arena, sectab->id_max, tp->worker_count); tp_for_parallel(tp, arena, tp->worker_count, lnk_chunk_ref_assigner, &task); // merge chunks - for (LNK_SectionNode *sect_node = st->list.first; sect_node != 0; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != 0; sect_node = sect_node->next) { LNK_Section *sect = §_node->data; lnk_chunk_list_concat_in_place_arr(sect->nosort_chunk->u.list, task.nosort_chunk_list_arr_arr[sect->id], tp->worker_count); lnk_chunk_list_concat_in_place_arr(sect->root->u.list, task.chunk_list_arr_arr[sect->id], tp->worker_count); diff --git a/src/linker/lnk_obj.h b/src/linker/lnk_obj.h index 876557ea..ec07d32e 100644 --- a/src/linker/lnk_obj.h +++ b/src/linker/lnk_obj.h @@ -112,7 +112,7 @@ typedef struct LNK_ObjNode *obj_node_arr; U64 obj_id_base; LNK_SectDefnList *defn_arr; - LNK_SectionTable *st; + LNK_SectionTable *sectab; U64 *function_pad_min; } LNK_ObjIniter; @@ -126,7 +126,7 @@ typedef struct typedef struct { - LNK_SectionTable *st; + LNK_SectionTable *sectab; LNK_ObjNode *obj_arr; U64 **chunk_counts; } LNK_ChunkCounter; @@ -139,7 +139,7 @@ typedef struct typedef struct { - LNK_SectionTable *st; + LNK_SectionTable *sectab; Rng1U64 *range_arr; U64 **chunk_ids; LNK_ObjNode *obj_arr; @@ -198,7 +198,7 @@ internal LNK_InputObjList lnk_input_obj_list_from_string_list(Arena *arena, Stri internal LNK_Obj ** lnk_obj_arr_from_list(Arena *arena, LNK_ObjList list); internal LNK_ObjNodeArray lnk_obj_list_reserve(Arena *arena, LNK_ObjList *list, U64 count); internal LNK_ChunkList * lnk_collect_obj_chunks(TP_Context *tp, TP_Arena *arena, U64 obj_count, LNK_Obj **obj_arr, String8 name, String8 postfix, B32 collect_discarded); -internal LNK_ObjNodeArray lnk_obj_list_push_parallel(TP_Context *tp, TP_Arena *tp_arena, LNK_ObjList *obj_list, LNK_SectionTable *st, U64 *function_pad_min, U64 input_count, LNK_InputObj **inputs); +internal LNK_ObjNodeArray lnk_obj_list_push_parallel(TP_Context *tp, TP_Arena *tp_arena, LNK_ObjList *obj_list, LNK_SectionTable *sectab, U64 *function_pad_min, U64 input_count, LNK_InputObj **inputs); internal LNK_Chunk * lnk_sect_chunk_array_from_coff(Arena *arena, U64 obj_id, String8 obj_path, String8 coff_data, U64 sect_count, COFF_SectionHeader *coff_sect_arr, String8 *sect_name_arr, String8 *sect_postfix_arr); internal LNK_SymbolArray lnk_symbol_array_from_coff(Arena *arena, LNK_Obj *obj, String8 obj_path, String8 lib_path, B32 is_big_obj, U64 function_pad_min, U64 sect_count, COFF_SectionHeader *section_table, U64 symbol_count, void *symbol_table, String8 string_table, LNK_ChunkPtr *chunk_table, LNK_Chunk *master_common_block); diff --git a/src/linker/lnk_section_table.c b/src/linker/lnk_section_table.c index a38ec9a7..4da0b857 100644 --- a/src/linker/lnk_section_table.c +++ b/src/linker/lnk_section_table.c @@ -271,33 +271,33 @@ lnk_section_table_alloc(U64 section_virt_off, U64 sect_align, U64 file_align) { ProfBeginFunction(); Arena *arena = arena_alloc(); - LNK_SectionTable *st = push_array(arena, LNK_SectionTable, 1); - st->arena = arena; - st->section_virt_off = section_virt_off; - st->sect_align = sect_align; - st->file_align = file_align; + LNK_SectionTable *sectab = push_array(arena, LNK_SectionTable, 1); + sectab->arena = arena; + sectab->section_virt_off = section_virt_off; + sectab->sect_align = sect_align; + sectab->file_align = file_align; ProfEnd(); - return st; + return sectab; } internal void lnk_section_table_release(LNK_SectionTable **st_ptr) { ProfBeginFunction(); - LNK_SectionTable *st = *st_ptr; - arena_release(st->arena); + LNK_SectionTable *sectab = *st_ptr; + arena_release(sectab->arena); *st_ptr = NULL; ProfEnd(); } internal LNK_Section * -lnk_section_table_push(LNK_SectionTable *st, String8 name, COFF_SectionFlags flags) +lnk_section_table_push(LNK_SectionTable *sectab, String8 name, COFF_SectionFlags flags) { ProfBeginFunction(); - LNK_SectionList *sect_list = &st->list; + LNK_SectionList *sect_list = §ab->list; - LNK_SectionNode *sect_node = push_array(st->arena, LNK_SectionNode, 1); - String8 sort_index = lnk_make_section_sort_index(st->arena, name, flags, st->id_max); + LNK_SectionNode *sect_node = push_array(sectab->arena, LNK_SectionNode, 1); + String8 sort_index = lnk_make_section_sort_index(sectab->arena, name, flags, sectab->id_max); B32 found = 0; for (LNK_SectionNode *curr = sect_list->first, *prev = NULL; curr != NULL; prev = curr, curr = curr->next) { @@ -320,8 +320,8 @@ lnk_section_table_push(LNK_SectionTable *st, String8 name, COFF_SectionFlags fla } sect_list->count += 1; - U64 sect_id = st->id_max; - st->id_max += 1; + U64 sect_id = sectab->id_max; + sectab->id_max += 1; LNK_Section *sect = §_node->data; sect->arena = arena_alloc(); @@ -329,7 +329,7 @@ lnk_section_table_push(LNK_SectionTable *st, String8 name, COFF_SectionFlags fla sect->name = push_str8_copy(sect->arena, name); sect->sort_index = sort_index; sect->flags = flags; - sect->cman = lnk_chunk_manager_alloc(sect->arena, sect_id, st->file_align); + sect->cman = lnk_chunk_manager_alloc(sect->arena, sect_id, sectab->file_align); sect->root = sect->cman->root; sect->nosort_chunk = lnk_chunk_push_list(sect->arena, sect->cman, sect->root, str8(0,0)); sect->nosort_chunk->sort_chunk = 0; @@ -345,12 +345,12 @@ lnk_section_table_push(LNK_SectionTable *st, String8 name, COFF_SectionFlags fla } internal LNK_Section * -lnk_section_table_push_null(LNK_SectionTable *st) +lnk_section_table_push_null(LNK_SectionTable *sectab) { - LNK_SectionList *list = &st->list; - SLLQueuePushFront(list->first, list->last, st->null_sect); + LNK_SectionList *list = §ab->list; + SLLQueuePushFront(list->first, list->last, sectab->null_sect); list->count += 1; - return &st->null_sect->data; + return §ab->null_sect->data; } LNK_CHUNK_VISITOR_SIG(lnk_chunk_has_leaf) @@ -375,12 +375,12 @@ LNK_CHUNK_VISITOR_SIG(lnk_chunk_mark_discarded) } internal void -lnk_section_table_remove(LNK_SectionTable *st, LNK_SymbolTable *symtab, String8 name) +lnk_section_table_remove(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, String8 name) { ProfBeginFunction(); // remove node from list - LNK_SectionNode *sect_node = lnk_section_list_remove(&st->list, name); + LNK_SectionNode *sect_node = lnk_section_list_remove(§ab->list, name); LNK_Section *sect = §_node->data; // remove symbol for section root chunk @@ -390,22 +390,22 @@ lnk_section_table_remove(LNK_SectionTable *st, LNK_SymbolTable *symtab, String8 lnk_visit_chunks(sect->id, sect->root, lnk_chunk_mark_discarded, NULL); // push to empties - SLLQueuePush(st->empties_list.first, st->empties_list.last, sect_node); - st->empties_list.count += 1; + SLLQueuePush(sectab->empties_list.first, sectab->empties_list.last, sect_node); + sectab->empties_list.count += 1; ProfEnd(); } internal LNK_Section * -lnk_section_table_search(LNK_SectionTable *st, String8 name) +lnk_section_table_search(LNK_SectionTable *sectab, String8 name) { - return lnk_section_list_search(&st->list, name); + return lnk_section_list_search(§ab->list, name); } internal LNK_Section * -lnk_section_table_search_id(LNK_SectionTable *st, U64 id) +lnk_section_table_search_id(LNK_SectionTable *sectab, U64 id) { - for (LNK_SectionNode *node = st->list.first; node != NULL; node = node->next) { + for (LNK_SectionNode *node = sectab->list.first; node != NULL; node = node->next) { if (node->data.id == id) { return &node->data; } @@ -414,16 +414,16 @@ lnk_section_table_search_id(LNK_SectionTable *st, U64 id) } internal void -lnk_section_table_merge(LNK_SectionTable *st, LNK_MergeDirectiveList merge_list) +lnk_section_table_merge(LNK_SectionTable *sectab, LNK_MergeDirectiveList merge_list) { ProfBeginFunction(); Temp scratch = scratch_begin(0, 0); - LNK_Section **src_dst = push_array(scratch.arena, LNK_Section *, st->id_max); + LNK_Section **src_dst = push_array(scratch.arena, LNK_Section *, sectab->id_max); for (LNK_MergeDirectiveNode *merge_node = merge_list.first; merge_node != NULL; merge_node = merge_node->next) { LNK_MergeDirective *merge = &merge_node->data; // are we trying to merge section that was already merged? - LNK_Section *merge_sect = lnk_section_list_search(&st->merge_list, merge->src); + LNK_Section *merge_sect = lnk_section_list_search(§ab->merge_list, merge->src); if (merge_sect) { LNK_Section *dst = src_dst[merge_sect->id]; B32 is_ambiguous_merge = !str8_match(dst->name, merge->dst, 0); @@ -436,7 +436,7 @@ lnk_section_table_merge(LNK_SectionTable *st, LNK_MergeDirectiveList merge_list) } // find source seciton - LNK_Section *src = lnk_section_table_search(st, merge->src); + LNK_Section *src = lnk_section_table_search(sectab, merge->src); if (src == NULL) { lnk_error(LNK_Warning_IllData, "Can't find section \"%S\" to merge with \"%S\"", merge->src, merge->dst); // TODO: supplement obj path if applicable @@ -444,7 +444,7 @@ lnk_section_table_merge(LNK_SectionTable *st, LNK_MergeDirectiveList merge_list) } // handle case where destination section doesn't exist - LNK_Section *dst = lnk_section_table_search(st, merge->dst); + LNK_Section *dst = lnk_section_table_search(sectab, merge->dst); if (dst == NULL) { src->name = push_str8_copy(src->arena, merge->dst); src_dst[src->id] = src; @@ -458,24 +458,24 @@ lnk_section_table_merge(LNK_SectionTable *st, LNK_MergeDirectiveList merge_list) lnk_section_merge(dst, src); // remove from output section list - LNK_SectionNode *src_node = lnk_section_list_remove(&st->list, src->name); + LNK_SectionNode *src_node = lnk_section_list_remove(§ab->list, src->name); // push section to merged list - SLLQueuePush(st->merge_list.first, st->merge_list.last, src_node); - st->merge_list.count += 1; + SLLQueuePush(sectab->merge_list.first, sectab->merge_list.last, src_node); + sectab->merge_list.count += 1; } scratch_end(scratch); ProfEnd(); } internal void -lnk_section_table_remove_empties(LNK_SectionTable *st, LNK_SymbolTable *symtab) +lnk_section_table_remove_empties(LNK_SectionTable *sectab, LNK_SymbolTable *symtab) { ProfBeginFunction(); Temp scratch = scratch_begin(0, 0); String8List name_list = {0}; - for (LNK_SectionNode *sect_node = st->list.first; sect_node != NULL; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != NULL; sect_node = sect_node->next) { LNK_Section *sect = §_node->data; B32 no_data = 1; @@ -488,28 +488,28 @@ lnk_section_table_remove_empties(LNK_SectionTable *st, LNK_SymbolTable *symtab) } for (String8Node *name = name_list.first; name != NULL; name = name->next) { - lnk_section_table_remove(st, symtab, name->string); + lnk_section_table_remove(sectab, symtab, name->string); } scratch_end(scratch); ProfEnd(); } internal LNK_SectionArray -lnk_section_table_get_output_sections(Arena *arena, LNK_SectionTable *st) +lnk_section_table_get_output_sections(Arena *arena, LNK_SectionTable *sectab) { LNK_SectionArray result = {0}; result.count = 0; - result.v = push_array(arena, LNK_Section, st->list.count); + result.v = push_array(arena, LNK_Section, sectab->list.count); - for (LNK_SectionNode *sect_node = st->list.first; sect_node != 0; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != 0; sect_node = sect_node->next) { if (sect_node->data.emit_header && sect_node->data.has_layout) { - Assert(result.count < st->list.count); + Assert(result.count < sectab->list.count); result.v[result.count] = sect_node->data; result.count += 1; } } - U64 unused_entry_count = st->list.count - result.count; + U64 unused_entry_count = sectab->list.count - result.count; arena_pop(arena, unused_entry_count * sizeof(result.v[0])); return result; @@ -526,12 +526,12 @@ THREAD_POOL_TASK_FUNC(lnk_section_data_builder) } internal void -lnk_section_table_build_data(TP_Context *tp, LNK_SectionTable *st, COFF_MachineType machine) +lnk_section_table_build_data(TP_Context *tp, LNK_SectionTable *sectab, COFF_MachineType machine) { ProfBeginFunction(); Temp scratch = scratch_begin(0, 0); - LNK_SectionPtrArray sect_arr = lnk_section_ptr_array_from_list(scratch.arena, st->list); + LNK_SectionPtrArray sect_arr = lnk_section_ptr_array_from_list(scratch.arena, sectab->list); LNK_SectionDataBuilder task = {0}; task.machine = machine; @@ -544,32 +544,32 @@ lnk_section_table_build_data(TP_Context *tp, LNK_SectionTable *st, COFF_MachineT } internal void -lnk_section_table_assign_virtual_offsets(LNK_SectionTable *st) +lnk_section_table_assign_virtual_offsets(LNK_SectionTable *sectab) { ProfBeginFunction(); Temp scratch = scratch_begin(0, 0); - LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, st); - U64 cursor = st->section_virt_off; + LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, sectab); + U64 cursor = sectab->section_virt_off; Assert(cursor >= 0x1000); - for (LNK_SectionNode *sect_node = st->list.first; sect_node != NULL; sect_node = sect_node->next) { - if (sect_node == st->null_sect) continue; + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != NULL; sect_node = sect_node->next) { + if (sect_node == sectab->null_sect) continue; LNK_Section *sect = §_node->data; if (!sect->has_layout) continue; sect->virt_off = cursor; U64 sect_size = lnk_virt_size_from_chunk_ref(sect_id_map, sect->root->ref); cursor += sect_size; - cursor = AlignPow2(cursor, st->sect_align); + cursor = AlignPow2(cursor, sectab->sect_align); } scratch_end(scratch); ProfEnd(); } internal void -lnk_section_table_assign_file_offsets(LNK_SectionTable *st) +lnk_section_table_assign_file_offsets(LNK_SectionTable *sectab) { ProfBeginFunction(); U64 cursor = 0; - for (LNK_SectionNode *sect_node = st->list.first; sect_node != NULL; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != NULL; sect_node = sect_node->next) { LNK_Section *sect = §_node->data; if (sect->flags & COFF_SectionFlag_CntUninitializedData) { continue; @@ -583,11 +583,11 @@ lnk_section_table_assign_file_offsets(LNK_SectionTable *st) } internal void -lnk_section_table_assign_indices(LNK_SectionTable *st) +lnk_section_table_assign_indices(LNK_SectionTable *sectab) { ProfBeginFunction(); U64 isect = 0; - for (LNK_SectionNode *sect_node = st->list.first; sect_node != NULL; sect_node = sect_node->next) { + for (LNK_SectionNode *sect_node = sectab->list.first; sect_node != NULL; sect_node = sect_node->next) { LNK_Section *sect = §_node->data; if (sect->emit_header) { sect->isect = isect++; @@ -597,13 +597,13 @@ lnk_section_table_assign_indices(LNK_SectionTable *st) } internal String8 -lnk_section_table_serialize(TP_Context *tp, Arena *arena, LNK_SectionTable *st, COFF_MachineType machine) +lnk_section_table_serialize(TP_Context *tp, Arena *arena, LNK_SectionTable *sectab, COFF_MachineType machine) { ProfBeginFunction(); Temp scratch = scratch_begin(&arena, 1); U64 image_size = 0; - for (LNK_SectionNode *sect_n = st->list.first; sect_n != 0; sect_n = sect_n->next) { + for (LNK_SectionNode *sect_n = sectab->list.first; sect_n != 0; sect_n = sect_n->next) { LNK_Section *sect = §_n->data; if (sect->has_layout) { U64 root_size = sect->layout.chunk_file_size_array[sect->root->ref.chunk_id]; @@ -615,7 +615,7 @@ lnk_section_table_serialize(TP_Context *tp, Arena *arena, LNK_SectionTable *st, String8 image = str8(image_buffer, image_size); U64 image_cursor = 0; - for (LNK_SectionNode *sect_n = st->list.first; sect_n != 0; sect_n = sect_n->next) { + for (LNK_SectionNode *sect_n = sectab->list.first; sect_n != 0; sect_n = sect_n->next) { LNK_Section *sect = §_n->data; if (sect->has_layout) { if (sect->flags & COFF_SectionFlag_CntUninitializedData) { @@ -642,15 +642,15 @@ lnk_section_table_serialize(TP_Context *tp, Arena *arena, LNK_SectionTable *st, } internal LNK_ChunkPtr ** -lnk_chunk_id_map_from_section_table(Arena *arena, LNK_SectionTable *st) +lnk_chunk_id_map_from_section_table(Arena *arena, LNK_SectionTable *sectab) { ProfBeginFunction(); - LNK_ChunkPtr **chunk_id_map = push_array(arena, LNK_ChunkPtr *, st->id_max); - for (LNK_SectionNode *node = st->list.first; node != 0; node = node->next) { + LNK_ChunkPtr **chunk_id_map = push_array(arena, LNK_ChunkPtr *, sectab->id_max); + for (LNK_SectionNode *node = sectab->list.first; node != 0; node = node->next) { LNK_Section *sect = &node->data; chunk_id_map[sect->id] = lnk_make_chunk_id_map(arena, sect->cman); } - if (st->list.first->data.id != 0) { + if (sectab->list.first->data.id != 0) { chunk_id_map[0] = push_array(arena, LNK_ChunkPtr, 1); chunk_id_map[0][0] = g_null_chunk_ptr; } @@ -659,15 +659,15 @@ lnk_chunk_id_map_from_section_table(Arena *arena, LNK_SectionTable *st) } internal LNK_Section ** -lnk_sect_id_map_from_section_table(Arena *arena, LNK_SectionTable *st) +lnk_sect_id_map_from_section_table(Arena *arena, LNK_SectionTable *sectab) { ProfBeginFunction(); - LNK_Section **map = push_array(arena, LNK_Section *, st->id_max); - LNK_SectionList *list_arr[] = { &st->list, &st->merge_list, &st->empties_list }; + LNK_Section **map = push_array(arena, LNK_Section *, sectab->id_max); + LNK_SectionList *list_arr[] = { §ab->list, §ab->merge_list, §ab->empties_list }; for (U64 list_idx = 0; list_idx < ArrayCount(list_arr); ++list_idx) { for (LNK_SectionNode *sect_node = list_arr[list_idx]->first; sect_node != NULL; sect_node = sect_node->next) { LNK_Section *sect = §_node->data; - Assert(sect->id < st->id_max); + Assert(sect->id < sectab->id_max); Assert(map[sect->id] == NULL); map[sect->id] = sect; } @@ -880,12 +880,12 @@ lnk_file_size_from_symbol(LNK_Section **sect_id_map, LNK_Symbol *symbol) #if LNK_DEBUG_CHUNKS internal void -lnk_dump_chunks(LNK_SectionTable *st) +lnk_dump_chunks(LNK_SectionTable *sectab) { Temp scratch = scratch_begin(0, 0); - LNK_ChunkPtr **chunk_id_map = lnk_chunk_id_map_from_section_table(scratch.arena, st); - LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, st); - for (U64 sect_id = 0; sect_id < st->id_max; ++sect_id) { + LNK_ChunkPtr **chunk_id_map = lnk_chunk_id_map_from_section_table(scratch.arena, sectab); + LNK_Section **sect_id_map = lnk_sect_id_map_from_section_table(scratch.arena, sectab); + for (U64 sect_id = 0; sect_id < sectab->id_max; ++sect_id) { LNK_Section *sect = sect_id_map[sect_id]; if (!sect) continue; if (sect->is_merged) continue; diff --git a/src/linker/lnk_section_table.h b/src/linker/lnk_section_table.h index 4aa6f2c3..770b934b 100644 --- a/src/linker/lnk_section_table.h +++ b/src/linker/lnk_section_table.h @@ -110,21 +110,21 @@ internal LNK_Chunk * lnk_section_push_chunk_list(LNK_Section *sect, LNK_Chunk internal LNK_SectionTable * lnk_section_table_alloc(U64 section_virt_off, U64 sect_align, U64 file_align); internal void lnk_section_table_release(LNK_SectionTable **st_ptr); -internal LNK_Section * lnk_section_table_push(LNK_SectionTable *st, String8 name, COFF_SectionFlags flags); -internal LNK_Section * lnk_section_table_push_null(LNK_SectionTable *st); -internal void lnk_section_table_remove(LNK_SectionTable *st, LNK_SymbolTable *symtab, String8 name); -internal LNK_Section * lnk_section_table_search(LNK_SectionTable *st, String8 name); -internal LNK_Section * lnk_section_table_search_id(LNK_SectionTable *st, U64 id); -internal void lnk_section_table_merge(LNK_SectionTable *st, LNK_MergeDirectiveList merge_list); -internal void lnk_section_table_remove_empties(LNK_SectionTable *st, LNK_SymbolTable *symtab); -internal void lnk_section_table_build_data(TP_Context *tp, LNK_SectionTable *st, COFF_MachineType machine); -internal void lnk_section_table_assign_virtual_offsets(LNK_SectionTable *st); -internal void lnk_section_table_assign_file_offsets(LNK_SectionTable *st); -internal void lnk_section_table_assign_indices(LNK_SectionTable *st); -internal String8 lnk_section_table_serialize(TP_Context *tp, Arena *arena, LNK_SectionTable *st, COFF_MachineType machine); +internal LNK_Section * lnk_section_table_push(LNK_SectionTable *sectab, String8 name, COFF_SectionFlags flags); +internal LNK_Section * lnk_section_table_push_null(LNK_SectionTable *sectab); +internal void lnk_section_table_remove(LNK_SectionTable *sectab, LNK_SymbolTable *symtab, String8 name); +internal LNK_Section * lnk_section_table_search(LNK_SectionTable *sectab, String8 name); +internal LNK_Section * lnk_section_table_search_id(LNK_SectionTable *sectab, U64 id); +internal void lnk_section_table_merge(LNK_SectionTable *sectab, LNK_MergeDirectiveList merge_list); +internal void lnk_section_table_remove_empties(LNK_SectionTable *sectab, LNK_SymbolTable *symtab); +internal void lnk_section_table_build_data(TP_Context *tp, LNK_SectionTable *sectab, COFF_MachineType machine); +internal void lnk_section_table_assign_virtual_offsets(LNK_SectionTable *sectab); +internal void lnk_section_table_assign_file_offsets(LNK_SectionTable *sectab); +internal void lnk_section_table_assign_indices(LNK_SectionTable *sectab); +internal String8 lnk_section_table_serialize(TP_Context *tp, Arena *arena, LNK_SectionTable *sectab, COFF_MachineType machine); -internal LNK_ChunkPtr ** lnk_chunk_id_map_from_section_table(Arena *arena, LNK_SectionTable *st); -internal LNK_Section ** lnk_sect_id_map_from_section_table(Arena *arena, LNK_SectionTable *st); +internal LNK_ChunkPtr ** lnk_chunk_id_map_from_section_table(Arena *arena, LNK_SectionTable *sectab); +internal LNK_Section ** lnk_sect_id_map_from_section_table(Arena *arena, LNK_SectionTable *sectab); internal LNK_ChunkRef lnk_get_final_chunk_ref(LNK_Section **sect_id_map, LNK_ChunkRef chunk_ref); internal LNK_Section * lnk_sect_from_chunk_ref(LNK_Section **sect_id_map, LNK_ChunkRef chunk_ref); internal LNK_Chunk * lnk_chunk_from_chunk_ref(LNK_Section **sect_id_map, LNK_ChunkPtr **chunk_id_map, LNK_ChunkRef chunk_ref); @@ -146,6 +146,6 @@ internal U64 lnk_virt_size_from_symbol(LNK_Section **sect_id_map, LN internal U64 lnk_file_size_from_symbol(LNK_Section **sect_id_map, LNK_Symbol *symbol); #if LNK_DEBUG_CHUNKS -internal void lnk_dump_chunks(LNK_SectionTable *st); +internal void lnk_dump_chunks(LNK_SectionTable *sectab); #endif diff --git a/src/linker/pdb_ext/msf_builder.c b/src/linker/pdb_ext/msf_builder.c index 9905147f..5ae0036d 100644 --- a/src/linker/pdb_ext/msf_builder.c +++ b/src/linker/pdb_ext/msf_builder.c @@ -798,7 +798,7 @@ msf_stream_alloc_(Arena *arena, MSF_StreamList *list) internal MSF_StreamNumber msf_stream_alloc_ex(MSF_Context *msf, MSF_UInt size) { - MSF_StreamNode *node = msf_stream_alloc_(msf->arena, &msf->st); + MSF_StreamNode *node = msf_stream_alloc_(msf->arena, &msf->sectab); MSF_Stream *stream = &node->data; msf_stream_resize_ex(msf, stream, size); return stream->sn; @@ -854,7 +854,7 @@ msf_stream_free(MSF_Context *msf, MSF_StreamNumber sn) B32 is_free_ok = 0; MSF_StreamNode *stream_node = msf_find_stream_node(msf, sn); if (stream_node) { - msf_stream_list_remove(&msf->st, stream_node); + msf_stream_list_remove(&msf->sectab, stream_node); msf_stream_resize_ex(msf, &stream_node->data, 0); stream_node->data.size = MSF_DELETED_STREAM_STAMP; is_free_ok = 1; @@ -1382,7 +1382,7 @@ internal MSF_StreamNode * msf_find_stream_node(MSF_Context *msf, MSF_StreamNumber sn) { MSF_StreamNode *node; - for (node = msf->st.first; node != 0; node = node->next) { + for (node = msf->sectab.first; node != 0; node = node->next) { if (node->data.sn == sn) { break; } @@ -1645,7 +1645,7 @@ msf_open(String8 data, MSF_Context **msf_out) msf->header_page_list = header_page_list; msf->root_page_list = root_page_list; msf->st_page_list = st_page_list; - msf->st = stream_list; + msf->sectab = stream_list; *msf_out = msf; @@ -1678,19 +1678,19 @@ msf_release(MSF_Context **msf_ptr) } internal String8List -msf_build_stream_table_data(Arena *arena, MSF_StreamList *st, MSF_UInt page_size, MSF_UInt page_count) +msf_build_stream_table_data(Arena *arena, MSF_StreamList *sectab, MSF_UInt page_size, MSF_UInt page_count) { ProfBeginFunction(); MSF_UInt *stream_count_ptr = push_array(arena, MSF_UInt, 1); - *stream_count_ptr = st->count; + *stream_count_ptr = sectab->count; - MSF_UInt *stream_size_arr = push_array(arena, MSF_UInt, st->count); + MSF_UInt *stream_size_arr = push_array(arena, MSF_UInt, sectab->count); MSF_UInt stream_page_count = 0; MSF_PageNumber *stream_pages_arr = push_array(arena, MSF_PageNumber, page_count); - for (MSF_StreamNode *stream_node = st->first; stream_node != 0; stream_node = stream_node->next) { + for (MSF_StreamNode *stream_node = sectab->first; stream_node != 0; stream_node = stream_node->next) { MSF_Stream *stream = &stream_node->data; // is page list correct? @@ -1747,7 +1747,7 @@ msf_build_stream_table(MSF_Context *msf, MSF_UInt *stream_table_size_out) MSF_Error error = MSF_Error_OK; - String8List st_data_list = msf_build_stream_table_data(scratch.arena, &msf->st, msf->page_size, msf->page_count); + String8List st_data_list = msf_build_stream_table_data(scratch.arena, &msf->sectab, msf->page_size, msf->page_count); MSF_UInt st_page_count = msf_count_pages(msf->page_size, st_data_list.total_size); msf_free_pages(msf, &msf->st_page_list); // TODO: page reuse diff --git a/src/linker/pdb_ext/msf_builder.h b/src/linker/pdb_ext/msf_builder.h index 40aba132..c9bda071 100644 --- a/src/linker/pdb_ext/msf_builder.h +++ b/src/linker/pdb_ext/msf_builder.h @@ -82,7 +82,7 @@ typedef struct MSF_Context MSF_PageList root_page_list; MSF_PageList st_page_list; MSF_PageList page_pool; - MSF_StreamList st; + MSF_StreamList sectab; } MSF_Context; typedef enum MSF_Error