mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-11-15 10:40:12 -08:00
use packed linker symbol and section contribution arrays
This commit is contained in:
1 parent
e6e1f7a426
commit
7633bd90ab
8 files changed
+182
-200
No files matched your search
+25
-71
@@ -4071,15 +4071,9 @@ THREAD_POOL_TASK_FUNC(lnk_patch_comdat_leaders_task)
|
||||
}
|
||||
|
||||
if (should_patch) {
|
||||
if (obj->header.is_big_obj) {
|
||||
COFF_Symbol32 *symbol32 = symbol.raw_symbol;
|
||||
symbol32->section_number = section_number;
|
||||
symbol32->value = value;
|
||||
} else {
|
||||
COFF_Symbol16 *symbol16 = symbol.raw_symbol;
|
||||
symbol16->section_number = safe_cast_u16(section_number);
|
||||
symbol16->value = value;
|
||||
}
|
||||
symbol.section_number = section_number;
|
||||
symbol.value = value;
|
||||
lnk_obj_symbol_patch(obj, symbol_idx, symbol, LNK_ObjSymbolPatch_Section | LNK_ObjSymbolPatch_Value);
|
||||
}
|
||||
}
|
||||
ProfEnd();
|
||||
@@ -4241,15 +4235,9 @@ THREAD_POOL_TASK_FUNC(lnk_patch_common_block_leaders_task)
|
||||
COFF_ParsedSymbol parsed_symbol = lnk_parsed_from_symbol(symbol);
|
||||
U64 section_number = task->u.patch_symtabs.common_block_sect->sect_idx + 1;
|
||||
|
||||
if (symbol_ref.obj->header.is_big_obj) {
|
||||
COFF_Symbol32 *symbol32 = parsed_symbol.raw_symbol;
|
||||
symbol32->value = contrib->u.offset;
|
||||
symbol32->section_number = safe_cast_u32(section_number);
|
||||
} else {
|
||||
COFF_Symbol16 *symbol16 = parsed_symbol.raw_symbol;
|
||||
symbol16->value = contrib->u.offset;
|
||||
symbol16->section_number = safe_cast_u16(section_number);
|
||||
}
|
||||
parsed_symbol.value = contrib->u.offset;
|
||||
parsed_symbol.section_number = safe_cast_u32(section_number);
|
||||
lnk_obj_symbol_patch(symbol_ref.obj, symbol_ref.symbol_idx, parsed_symbol, LNK_ObjSymbolPatch_Value | LNK_ObjSymbolPatch_Section);
|
||||
|
||||
task->u.patch_symtabs.was_symbol_patched[symbol_ref.obj->input_idx][symbol_ref.symbol_idx] = 1;
|
||||
}
|
||||
@@ -4274,17 +4262,10 @@ THREAD_POOL_TASK_FUNC(lnk_patch_common_block_symbols_task)
|
||||
COFF_ParsedSymbol defn_parsed = lnk_parsed_from_symbol(defn);
|
||||
Assert(lnk_interp_from_symbol(defn) == COFF_SymbolValueInterp_Regular);
|
||||
if (defn) {
|
||||
if (obj->header.is_big_obj) {
|
||||
COFF_Symbol32 *symbol32 = symbol.raw_symbol;
|
||||
symbol32->section_number = defn_parsed.section_number;
|
||||
symbol32->value = safe_cast_u32(defn_parsed.value);
|
||||
symbol32->storage_class = COFF_SymStorageClass_Static;
|
||||
} else {
|
||||
COFF_Symbol16 *symbol16 = symbol.raw_symbol;
|
||||
symbol16->section_number = safe_cast_u16(defn_parsed.section_number);
|
||||
symbol16->value = safe_cast_u32(defn_parsed.value);
|
||||
symbol16->storage_class = COFF_SymStorageClass_Static;
|
||||
}
|
||||
symbol.section_number = defn_parsed.section_number;
|
||||
symbol.value = safe_cast_u32(defn_parsed.value);
|
||||
symbol.storage_class = COFF_SymStorageClass_Static;
|
||||
lnk_obj_symbol_patch(obj, symbol_idx, symbol, LNK_ObjSymbolPatch_Section | LNK_ObjSymbolPatch_Value | LNK_ObjSymbolPatch_StorageClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4318,15 +4299,9 @@ THREAD_POOL_TASK_FUNC(lnk_patch_regular_symbols_task)
|
||||
value = sc->u.off + symbol.value;
|
||||
}
|
||||
|
||||
if (obj->header.is_big_obj) {
|
||||
COFF_Symbol32 *symbol32 = symbol.raw_symbol;
|
||||
symbol32->section_number = section_number;
|
||||
symbol32->value = value;
|
||||
} else {
|
||||
COFF_Symbol16 *symbol16 = symbol.raw_symbol;
|
||||
symbol16->section_number = safe_cast_u16(section_number);
|
||||
symbol16->value = value;
|
||||
}
|
||||
symbol.section_number = section_number;
|
||||
symbol.value = value;
|
||||
lnk_obj_symbol_patch(obj, symbol_idx, symbol, LNK_ObjSymbolPatch_Section | LNK_ObjSymbolPatch_Value);
|
||||
}
|
||||
}
|
||||
ProfEnd();
|
||||
@@ -4363,17 +4338,10 @@ lnk_patch_obj_symtab(LNK_SymbolTable *symtab, LNK_Obj *obj, B8 *was_symbol_patch
|
||||
value = fixup_src.value;
|
||||
}
|
||||
|
||||
if (obj->header.is_big_obj) {
|
||||
COFF_Symbol32 *symbol32 = fixup_dst.raw_symbol;
|
||||
symbol32->section_number = section_number;
|
||||
symbol32->value = value;
|
||||
symbol32->storage_class = COFF_SymStorageClass_Static;
|
||||
} else {
|
||||
COFF_Symbol16 *symbol16 = fixup_dst.raw_symbol;
|
||||
symbol16->section_number = (U16)section_number;
|
||||
symbol16->value = value;
|
||||
symbol16->storage_class = COFF_SymStorageClass_Static;
|
||||
}
|
||||
fixup_dst.section_number = section_number;
|
||||
fixup_dst.value = value;
|
||||
fixup_dst.storage_class = COFF_SymStorageClass_Static;
|
||||
lnk_obj_symbol_patch(obj, symbol_idx, fixup_dst, LNK_ObjSymbolPatch_Section | LNK_ObjSymbolPatch_Value | LNK_ObjSymbolPatch_StorageClass);
|
||||
|
||||
was_symbol_patched[symbol_idx] = 1;
|
||||
}
|
||||
@@ -5047,17 +5015,10 @@ THREAD_POOL_TASK_FUNC(lnk_patch_section_symbols_task)
|
||||
if (sect && (~sect->flags & COFF_SectionFlag_LnkRemove)) {
|
||||
if (~sect->flags & COFF_SectionFlag_MemDiscardable) {
|
||||
LNK_SectionContrib *first_sc = lnk_get_first_section_contrib(sect);
|
||||
if (obj->header.is_big_obj) {
|
||||
COFF_Symbol32 *symbol32 = symbol.raw_symbol;
|
||||
symbol32->section_number = safe_cast_u32(first_sc->u.sect_idx + 1);
|
||||
symbol32->value = first_sc->u.off;
|
||||
symbol32->storage_class = COFF_SymStorageClass_Static;
|
||||
} else {
|
||||
COFF_Symbol16 *symbol16 = symbol.raw_symbol;
|
||||
symbol16->section_number = safe_cast_u16(first_sc->u.sect_idx + 1);
|
||||
symbol16->value = first_sc->u.off;
|
||||
symbol16->storage_class = COFF_SymStorageClass_Static;
|
||||
}
|
||||
symbol.section_number = safe_cast_u32(first_sc->u.sect_idx + 1);
|
||||
symbol.value = first_sc->u.off;
|
||||
symbol.storage_class = COFF_SymStorageClass_Static;
|
||||
lnk_obj_symbol_patch(obj, symbol_idx, symbol, LNK_ObjSymbolPatch_Section | LNK_ObjSymbolPatch_Value | LNK_ObjSymbolPatch_StorageClass);
|
||||
} else {
|
||||
lnk_error_obj(LNK_Error_SectRefsDiscardedMemory, obj, "symbol %S (No. 0x%llx) references section with discard flag", symbol_name, symbol_idx);
|
||||
}
|
||||
@@ -5075,17 +5036,10 @@ THREAD_POOL_TASK_FUNC(lnk_patch_section_symbols_task)
|
||||
LNK_Section *fallback_sect = task->image_sects.v[task->image_sects.count-1];
|
||||
U32 fallback_section_number = safe_cast_u32(fallback_sect->sect_idx + 1);
|
||||
U32 fallback_section_offset = safe_cast_u32(fallback_voff - fallback_sect->voff);
|
||||
if (obj->header.is_big_obj) {
|
||||
COFF_Symbol32 *symbol32 = symbol.raw_symbol;
|
||||
symbol32->section_number = fallback_section_number;
|
||||
symbol32->value = fallback_section_offset;
|
||||
symbol32->storage_class = COFF_SymStorageClass_Static;
|
||||
} else {
|
||||
COFF_Symbol16 *symbol16 = symbol.raw_symbol;
|
||||
symbol16->section_number = safe_cast_u16(fallback_section_number);
|
||||
symbol16->value = fallback_section_offset;
|
||||
symbol16->storage_class = COFF_SymStorageClass_Static;
|
||||
}
|
||||
symbol.section_number = fallback_section_number;
|
||||
symbol.value = fallback_section_offset;
|
||||
symbol.storage_class = COFF_SymStorageClass_Static;
|
||||
lnk_obj_symbol_patch(obj, symbol_idx, symbol, LNK_ObjSymbolPatch_Section | LNK_ObjSymbolPatch_Value | LNK_ObjSymbolPatch_StorageClass);
|
||||
|
||||
lnk_error_obj(LNK_Warning_UndefinedSectionSymbol, obj, "undefined section symbol %S (No. 0x%llx) refers to an image section that doesn't exist; patching to %#llx", symbol_name, symbol_idx, fallback_voff);
|
||||
}
|
||||
|
||||
+34
-20
@@ -3082,8 +3082,6 @@ THREAD_POOL_TASK_FUNC(lnk_write_pdb_modules)
|
||||
internal
|
||||
THREAD_POOL_TASK_FUNC(lnk_push_dbi_sec_contrib_task)
|
||||
{
|
||||
// TODO: use chunked lists for SC
|
||||
// TODO: put back unused sc nodes
|
||||
// TODO: compute CRC for relocations
|
||||
|
||||
U64 obj_idx = task_id;
|
||||
@@ -3091,8 +3089,9 @@ THREAD_POOL_TASK_FUNC(lnk_push_dbi_sec_contrib_task)
|
||||
PDB_DbiModule *mod = task->mod_arr [obj_idx];
|
||||
LNK_Obj *obj = task->cv->obj_arr[obj_idx];
|
||||
|
||||
PDB_DbiSCNode *sc_arr = push_array_no_zero(arena, PDB_DbiSCNode, obj->header.section_count_no_null);
|
||||
U64 sc_count = 0;
|
||||
PDB_DbiSCArray *sc_array = &task->sc_arrays[obj_idx];
|
||||
sc_array->v = push_array_no_zero(arena, PDB_DbiSC, obj->header.section_count_no_null);
|
||||
sc_array->cap = obj->header.section_count_no_null;
|
||||
|
||||
for EachIndex(sect_idx, obj->header.section_count_no_null) {
|
||||
|
||||
@@ -3127,23 +3126,22 @@ THREAD_POOL_TASK_FUNC(lnk_push_dbi_sec_contrib_task)
|
||||
U64 range_idx = search_result - 1;
|
||||
|
||||
// fill out & push section contribution
|
||||
PDB_DbiSCNode *sc = sc_arr + sc_count++;
|
||||
sc->data.base.sec = (U16)(is_virt ? range_idx : task->image_section_file_section_numbers[range_idx]);
|
||||
sc->data.base.pad0 = 0;
|
||||
sc->data.base.sec_off = section_range.min - image_ranges->v[range_idx].min;
|
||||
sc->data.base.size = dim_1u64(section_range);
|
||||
sc->data.base.flags = *section.flags;
|
||||
sc->data.base.mod = mod->imod;
|
||||
sc->data.base.pad1 = 0;
|
||||
sc->data.data_crc = is_virt ? 0 : crc32_from_string(str8_substr(task->image_data, section_range));
|
||||
sc->data.reloc_crc = 0;
|
||||
dbi_sec_contrib_list_push_node(&task->sc_list[obj_idx], sc);
|
||||
PDB_DbiSC *sc = &sc_array->v[sc_array->count++];
|
||||
sc->base.sec = (U16)(is_virt ? range_idx : task->image_section_file_section_numbers[range_idx]);
|
||||
sc->base.pad0 = 0;
|
||||
sc->base.sec_off = section_range.min - image_ranges->v[range_idx].min;
|
||||
sc->base.size = dim_1u64(section_range);
|
||||
sc->base.flags = *section.flags;
|
||||
sc->base.mod = mod->imod;
|
||||
sc->base.pad1 = 0;
|
||||
sc->data_crc = is_virt ? 0 : crc32_from_string(str8_substr(task->image_data, section_range));
|
||||
sc->reloc_crc = 0;
|
||||
}
|
||||
|
||||
// find first code section contribution for the Mod1::fUpdateSecContrib
|
||||
for EachIndex(i, sc_count) {
|
||||
if (sc_arr[i].data.base.flags & COFF_SectionFlag_CntCode) {
|
||||
mod->first_sc = sc_arr[i].data;
|
||||
for EachIndex(i, sc_array->count) {
|
||||
if (sc_array->v[i].base.flags & COFF_SectionFlag_CntCode) {
|
||||
mod->first_sc = sc_array->v[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -3393,9 +3391,25 @@ lnk_build_pdb(TP_Context *tp, TP_Arena *tp_arena, String8 image_data, LNK_Config
|
||||
task.image_section_virt_ranges.v[i] = rng_1u64(sect_header->voff, sect_header->voff + sect_header->vsize);
|
||||
}
|
||||
|
||||
task.sc_list = push_array(scratch.arena, PDB_DbiSCList, cv->obj_count);
|
||||
task.sc_arrays = push_array(scratch.arena, PDB_DbiSCArray, cv->obj_count);
|
||||
tp_for_parallel(tp, tp_arena, cv->obj_count, lnk_push_dbi_sec_contrib_task, &task);
|
||||
dbi_sec_list_concat_arr(&task.pdb->dbi->sec_contrib_list, cv->obj_count, task.sc_list);
|
||||
|
||||
PDB_DbiSCArray *sec_contribs = &task.pdb->dbi->sec_contribs;
|
||||
U64 new_count = sec_contribs->count;
|
||||
for EachIndex(obj_idx, cv->obj_count) {
|
||||
new_count += task.sc_arrays[obj_idx].count;
|
||||
}
|
||||
PDB_DbiSC *new_v = push_array_no_zero(task.pdb->dbi->arena, PDB_DbiSC, new_count);
|
||||
MemoryCopyTyped(new_v, sec_contribs->v, sec_contribs->count);
|
||||
U64 cursor = sec_contribs->count;
|
||||
for EachIndex(obj_idx, cv->obj_count) {
|
||||
PDB_DbiSCArray *src = &task.sc_arrays[obj_idx];
|
||||
MemoryCopyTyped(new_v + cursor, src->v, src->count);
|
||||
cursor += src->count;
|
||||
}
|
||||
sec_contribs->v = new_v;
|
||||
sec_contribs->count = new_count;
|
||||
sec_contribs->cap = new_count;
|
||||
}
|
||||
ProfEnd();
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ typedef struct
|
||||
Rng1U64Array image_section_virt_ranges;
|
||||
Rng1U64Array image_section_file_ranges;
|
||||
U64 *image_section_file_section_numbers;
|
||||
PDB_DbiSCList *sc_list; // [obj_count]
|
||||
PDB_DbiSCArray *sc_arrays; // [obj_count]
|
||||
} LNK_BuildPdb;
|
||||
|
||||
typedef struct
|
||||
|
||||
+65
-33
@@ -165,27 +165,38 @@ THREAD_POOL_TASK_FUNC(lnk_obj_initer)
|
||||
}
|
||||
}
|
||||
|
||||
U64 name_block_count = CeilIntegerDiv(header.symbol_count, 64);
|
||||
LNK_SymbolNameCache symbol_name_cache = {
|
||||
.masks = push_array(arena, U64, name_block_count),
|
||||
.block_bases = push_array_no_zero(arena, U32, name_block_count),
|
||||
.name_sizes = push_array_no_zero(arena, U32, primary_symbol_count),
|
||||
U64 symbol_block_count = CeilIntegerDiv(header.symbol_count, 64);
|
||||
LNK_ObjSymbolArray symbols = {
|
||||
.count = primary_symbol_count,
|
||||
.primary_masks = push_array(arena, U64, symbol_block_count),
|
||||
.block_bases = push_array_no_zero(arena, U32, symbol_block_count),
|
||||
.values = push_array_no_zero(arena, U64, primary_symbol_count),
|
||||
.section_numbers = push_array_no_zero(arena, U32, primary_symbol_count),
|
||||
.types = push_array_no_zero(arena, COFF_SymbolType, primary_symbol_count),
|
||||
.storage_classes = push_array_no_zero(arena, COFF_SymStorageClass, primary_symbol_count),
|
||||
.aux_counts = push_array_no_zero(arena, U8, primary_symbol_count),
|
||||
.name_offsets = push_array_no_zero(arena, U32, primary_symbol_count),
|
||||
.name_sizes = push_array_no_zero(arena, U32, primary_symbol_count),
|
||||
};
|
||||
{
|
||||
COFF_SectionHeader *section_table = (COFF_SectionHeader *)str8_substr(input->data, header.section_table_range).str;
|
||||
U64 next_block = 0;
|
||||
U32 name_count = 0;
|
||||
U32 primary_idx = 0;
|
||||
COFF_ParsedSymbol symbol;
|
||||
for (U64 symbol_idx = 0; symbol_idx < header.symbol_count; symbol_idx += (1 + symbol.aux_symbol_count)) {
|
||||
symbol = coff_parse_symbol(header, raw_coff_string_table, raw_coff_symbol_table, symbol_idx);
|
||||
U64 block_idx = symbol_idx >> 6;
|
||||
while (next_block <= block_idx) {
|
||||
symbol_name_cache.block_bases[next_block++] = name_count;
|
||||
}
|
||||
if (symbol.name.size) {
|
||||
symbol_name_cache.masks[block_idx] |= 1ull << (symbol_idx & 63);
|
||||
symbol_name_cache.name_sizes[name_count++] = safe_cast_u32(symbol.name.size);
|
||||
symbols.block_bases[next_block++] = primary_idx;
|
||||
}
|
||||
symbols.primary_masks[block_idx] |= 1ull << (symbol_idx & 63);
|
||||
symbols.values[primary_idx] = symbol.value;
|
||||
symbols.section_numbers[primary_idx] = symbol.section_number;
|
||||
symbols.types[primary_idx] = symbol.type;
|
||||
symbols.storage_classes[primary_idx] = symbol.storage_class;
|
||||
symbols.aux_counts[primary_idx] = symbol.aux_symbol_count;
|
||||
symbols.name_offsets[primary_idx] = symbol.name.size ? safe_cast_u32(symbol.name.str - input->data.str) : 0;
|
||||
symbols.name_sizes[primary_idx] = safe_cast_u32(symbol.name.size);
|
||||
primary_idx += 1;
|
||||
COFF_SymbolValueInterpType interp = coff_interp_symbol(symbol.section_number, symbol.value, symbol.storage_class);
|
||||
if (interp == COFF_SymbolValueInterp_Regular) {
|
||||
if (symbol.section_number == 0 || symbol.section_number > header.section_count_no_null) {
|
||||
@@ -203,9 +214,10 @@ THREAD_POOL_TASK_FUNC(lnk_obj_initer)
|
||||
}
|
||||
}
|
||||
}
|
||||
while (next_block < name_block_count) {
|
||||
symbol_name_cache.block_bases[next_block++] = name_count;
|
||||
while (next_block < symbol_block_count) {
|
||||
symbols.block_bases[next_block++] = primary_idx;
|
||||
}
|
||||
Assert(primary_idx == primary_symbol_count);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -370,7 +382,7 @@ THREAD_POOL_TASK_FUNC(lnk_obj_initer)
|
||||
obj->path = push_str8_copy(arena, input->path);
|
||||
obj->header = header;
|
||||
obj->section_flags = section_flags;
|
||||
obj->symbol_name_cache = symbol_name_cache;
|
||||
obj->symbols = symbols;
|
||||
obj->comdats = comdats;
|
||||
obj->exclude_from_debug_info = input->exclude_from_debug_info;
|
||||
obj->hotpatch = hotpatch;
|
||||
@@ -765,32 +777,37 @@ lnk_coff_section_header_from_section_number(LNK_Obj *obj, U64 section_number)
|
||||
return §ion_table[sect_idx];
|
||||
}
|
||||
|
||||
internal force_inline U64
|
||||
lnk_obj_primary_symbol_idx_from_coff_symbol_idx(LNK_Obj *obj, U64 symbol_idx)
|
||||
{
|
||||
U64 block_idx = symbol_idx >> 6;
|
||||
U64 bit = 1ull << (symbol_idx & 63);
|
||||
U64 block_mask = obj->symbols.primary_masks[block_idx];
|
||||
Assert(block_mask & bit);
|
||||
return obj->symbols.block_bases[block_idx] + count_bits_set64(block_mask & (bit - 1));
|
||||
}
|
||||
|
||||
internal force_inline COFF_ParsedSymbol
|
||||
lnk_parsed_symbol_from_coff_symbol_idx_no_name(LNK_Obj *obj, U64 symbol_idx)
|
||||
{
|
||||
return coff_parse_symbol_no_name(obj->header, lnk_coff_symbol_table_from_obj(obj), safe_cast_u32(symbol_idx));
|
||||
U64 primary_idx = lnk_obj_primary_symbol_idx_from_coff_symbol_idx(obj, symbol_idx);
|
||||
U64 symbol_size = obj->header.is_big_obj ? sizeof(COFF_Symbol32) : sizeof(COFF_Symbol16);
|
||||
COFF_ParsedSymbol result = {
|
||||
.value = obj->symbols.values[primary_idx],
|
||||
.section_number = obj->symbols.section_numbers[primary_idx],
|
||||
.type = obj->symbols.types[primary_idx],
|
||||
.storage_class = obj->symbols.storage_classes[primary_idx],
|
||||
.aux_symbol_count = obj->symbols.aux_counts[primary_idx],
|
||||
.raw_symbol = lnk_coff_symbol_table_from_obj(obj).str + symbol_idx * symbol_size,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
internal force_inline String8
|
||||
lnk_symbol_name_from_coff_symbol_idx(LNK_Obj *obj, U64 symbol_idx)
|
||||
{
|
||||
String8 result = {0};
|
||||
U64 block_idx = symbol_idx >> 6;
|
||||
U64 bit = 1ull << (symbol_idx & 63);
|
||||
U64 mask = obj->symbol_name_cache.masks[block_idx];
|
||||
if (mask & bit) {
|
||||
U64 name_idx = obj->symbol_name_cache.block_bases[block_idx] + count_bits_set64(mask & (bit - 1));
|
||||
U64 name_size = obj->symbol_name_cache.name_sizes[name_idx];
|
||||
|
||||
String8 symbol_table = lnk_coff_symbol_table_from_obj(obj);
|
||||
COFF_SymbolName *name = obj->header.is_big_obj ? &((COFF_Symbol32 *)symbol_table.str)[symbol_idx].name
|
||||
: &((COFF_Symbol16 *)symbol_table.str)[symbol_idx].name;
|
||||
U8 *name_ptr = name->long_name.zeroes == 0
|
||||
? obj->data.str + obj->header.string_table_range.min + name->long_name.string_table_offset
|
||||
: name->short_name;
|
||||
result = str8(name_ptr, name_size);
|
||||
}
|
||||
return result;
|
||||
U64 primary_idx = lnk_obj_primary_symbol_idx_from_coff_symbol_idx(obj, symbol_idx);
|
||||
return str8(obj->data.str + obj->symbols.name_offsets[primary_idx], obj->symbols.name_sizes[primary_idx]);
|
||||
}
|
||||
|
||||
internal force_inline COFF_ParsedSymbol
|
||||
@@ -801,6 +818,21 @@ lnk_parsed_symbol_from_coff_symbol_idx(LNK_Obj *obj, U64 symbol_idx)
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void
|
||||
lnk_obj_symbol_patch(LNK_Obj *obj, U64 symbol_idx, COFF_ParsedSymbol patch, LNK_ObjSymbolPatchFlags flags)
|
||||
{
|
||||
U64 primary_idx = lnk_obj_primary_symbol_idx_from_coff_symbol_idx(obj, symbol_idx);
|
||||
if (flags & LNK_ObjSymbolPatch_Value) {
|
||||
obj->symbols.values[primary_idx] = patch.value;
|
||||
}
|
||||
if (flags & LNK_ObjSymbolPatch_Section) {
|
||||
obj->symbols.section_numbers[primary_idx] = patch.section_number;
|
||||
}
|
||||
if (flags & LNK_ObjSymbolPatch_StorageClass) {
|
||||
obj->symbols.storage_classes[primary_idx] = patch.storage_class;
|
||||
}
|
||||
}
|
||||
|
||||
internal
|
||||
THREAD_POOL_TASK_FUNC(lnk_collect_obj_chunks_task)
|
||||
{
|
||||
|
||||
+22
-6
@@ -5,12 +5,27 @@
|
||||
|
||||
// --- Input -------------------------------------------------------------------
|
||||
|
||||
typedef struct LNK_SymbolNameCache
|
||||
typedef struct LNK_ObjSymbolArray
|
||||
{
|
||||
U64 *masks;
|
||||
U32 *block_bases;
|
||||
U32 *name_sizes;
|
||||
} LNK_SymbolNameCache;
|
||||
U64 count;
|
||||
U64 *primary_masks;
|
||||
U32 *block_bases;
|
||||
U64 *values;
|
||||
U32 *section_numbers;
|
||||
COFF_SymbolType *types;
|
||||
COFF_SymStorageClass *storage_classes;
|
||||
U8 *aux_counts;
|
||||
U32 *name_offsets;
|
||||
U32 *name_sizes;
|
||||
} LNK_ObjSymbolArray;
|
||||
|
||||
typedef U32 LNK_ObjSymbolPatchFlags;
|
||||
enum
|
||||
{
|
||||
LNK_ObjSymbolPatch_Value = (1 << 0),
|
||||
LNK_ObjSymbolPatch_Section = (1 << 1),
|
||||
LNK_ObjSymbolPatch_StorageClass = (1 << 2),
|
||||
};
|
||||
|
||||
typedef struct LNK_Obj
|
||||
{
|
||||
@@ -19,7 +34,7 @@ typedef struct LNK_Obj
|
||||
|
||||
COFF_FileHeaderInfo header;
|
||||
COFF_SectionFlags *section_flags;
|
||||
LNK_SymbolNameCache symbol_name_cache;
|
||||
LNK_ObjSymbolArray symbols;
|
||||
|
||||
// flags
|
||||
B8 hotpatch;
|
||||
@@ -223,6 +238,7 @@ internal U32List lnk_obj_collect_associated_sections(Arena *arena, LNK_
|
||||
internal force_inline COFF_ParsedSymbol lnk_parsed_symbol_from_coff_symbol_idx(LNK_Obj *obj, U64 symbol_idx);
|
||||
internal force_inline COFF_ParsedSymbol lnk_parsed_symbol_from_coff_symbol_idx_no_name(LNK_Obj *obj, U64 symbol_idx);
|
||||
internal force_inline String8 lnk_symbol_name_from_coff_symbol_idx(LNK_Obj *obj, U64 symbol_idx);
|
||||
internal void lnk_obj_symbol_patch(LNK_Obj *obj, U64 symbol_idx, COFF_ParsedSymbol patch, LNK_ObjSymbolPatchFlags flags);
|
||||
|
||||
internal COFF_SectionHeader * lnk_coff_section_header_from_section_number(LNK_Obj *obj, U64 section_number);
|
||||
internal U64 lnk_obj_sect_idx_from_section_number(LNK_Obj *obj, U64 section_number);
|
||||
|
||||
@@ -826,18 +826,10 @@ THREAD_POOL_TASK_FUNC(lnk_replace_weak_with_default_symbol_task)
|
||||
COFF_ParsedSymbol resolve_parsed = lnk_parsed_symbol_from_coff_symbol_idx_no_name(resolve.obj, resolve.symbol_idx);
|
||||
COFF_SymbolValueInterpType resolve_interp = coff_interp_from_parsed_symbol(resolve_parsed);
|
||||
if (resolve_interp == COFF_SymbolValueInterp_Weak) {
|
||||
COFF_SymbolWeakExt *weak_ext = coff_parse_weak_tag(resolve_parsed, symbol_ref.obj->header.is_big_obj);
|
||||
if (symbol_ref.obj->header.is_big_obj) {
|
||||
COFF_Symbol32 *symbol32 = symbol_parsed.raw_symbol;
|
||||
symbol32->section_number = COFF_Symbol_UndefinedSection;
|
||||
symbol32->value = 0;
|
||||
symbol32->storage_class = COFF_SymStorageClass_External;
|
||||
} else {
|
||||
COFF_Symbol16 *symbol16 = symbol_parsed.raw_symbol;
|
||||
symbol16->section_number = COFF_Symbol_UndefinedSection;
|
||||
symbol16->value = 0;
|
||||
symbol16->storage_class = COFF_SymStorageClass_External;
|
||||
}
|
||||
symbol_parsed.section_number = COFF_Symbol_UndefinedSection;
|
||||
symbol_parsed.value = 0;
|
||||
symbol_parsed.storage_class = COFF_SymStorageClass_External;
|
||||
lnk_obj_symbol_patch(symbol_ref.obj, symbol_ref.symbol_idx, symbol_parsed, LNK_ObjSymbolPatch_Section | LNK_ObjSymbolPatch_Value | LNK_ObjSymbolPatch_StorageClass);
|
||||
lnk_symbol_set_search_type(symbol, LNK_SymbolSearch_Undefined);
|
||||
} else {
|
||||
symbol->first_ref->v = resolve;
|
||||
|
||||
@@ -2521,27 +2521,17 @@ psi_push(PDB_PsiContext *psi, CV_Pub32Flags flags, U32 offset, U16 isect, String
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
internal void
|
||||
dbi_sec_contrib_list_push_node(PDB_DbiSCList *list, PDB_DbiSCNode *node)
|
||||
internal PDB_DbiSC *
|
||||
dbi_sec_contrib_array_push(Arena *arena, PDB_DbiSCArray *array)
|
||||
{
|
||||
node->next = 0;
|
||||
SLLQueuePush(list->first, list->last, node);
|
||||
list->count += 1;
|
||||
}
|
||||
|
||||
internal PDB_DbiSCNode *
|
||||
dbi_sec_contrib_list_push(Arena *arena, PDB_DbiSCList *list)
|
||||
{
|
||||
PDB_DbiSCNode *node = push_array_no_zero(arena, PDB_DbiSCNode, 1);
|
||||
node->next = 0;
|
||||
dbi_sec_contrib_list_push_node(list, node);
|
||||
return node;
|
||||
}
|
||||
|
||||
internal void
|
||||
dbi_sec_list_concat_arr(PDB_DbiSCList *list, U64 count, PDB_DbiSCList *to_concat)
|
||||
{
|
||||
SLLConcatInPlaceArray(list, to_concat, count);
|
||||
if (array->count >= array->cap) {
|
||||
U64 new_cap = Max(16, array->cap * 2);
|
||||
PDB_DbiSC *new_v = push_array_no_zero(arena, PDB_DbiSC, new_cap);
|
||||
MemoryCopyTyped(new_v, array->v, array->count);
|
||||
array->v = new_v;
|
||||
array->cap = new_cap;
|
||||
}
|
||||
return &array->v[array->count++];
|
||||
}
|
||||
|
||||
internal PDB_DbiContext *
|
||||
@@ -2664,12 +2654,12 @@ dbi_open_module_info(Arena *arena, MSF_Context *msf, MSF_StreamNumber sn, PDB_Db
|
||||
return list;
|
||||
}
|
||||
|
||||
internal PDB_DbiSCList
|
||||
internal PDB_DbiSCArray
|
||||
dbi_open_sec_contrib(Arena *arena, MSF_Context *msf, MSF_StreamNumber sn, PDB_DbiHeader *dbi_header)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
|
||||
PDB_DbiSCList sec_contrib = {0};
|
||||
PDB_DbiSCArray sec_contribs = {0};
|
||||
|
||||
if (dbi_header->sec_con_size > sizeof(PDB_DbiSC)) {
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
@@ -2686,16 +2676,11 @@ dbi_open_sec_contrib(Arena *arena, MSF_Context *msf, MSF_StreamNumber sn, PDB_Db
|
||||
switch (version) {
|
||||
case PDB_DbiSCVersion_1: {
|
||||
U64 contrib_count = dbi_header->sec_con_size / sizeof(PDB_DbiSC);
|
||||
PDB_DbiSC *src_contrib_array = push_array(scratch.arena, PDB_DbiSC, contrib_count);
|
||||
MSF_UInt sec_con_read = msf_stream_read_array(msf, sn, &src_contrib_array[0], contrib_count);
|
||||
Assert(sec_con_read == sizeof(src_contrib_array[0]) * contrib_count);
|
||||
|
||||
PDB_DbiSCNode *dst_contrib_array = push_array_no_zero(arena, PDB_DbiSCNode, contrib_count);
|
||||
for (U64 icontrib = 0; icontrib < contrib_count; icontrib += 1) {
|
||||
dst_contrib_array[icontrib].next = 0;
|
||||
dst_contrib_array[icontrib].data = src_contrib_array[icontrib];
|
||||
dbi_sec_contrib_list_push_node(&sec_contrib, &dst_contrib_array[icontrib]);
|
||||
}
|
||||
sec_contribs.v = push_array_no_zero(arena, PDB_DbiSC, contrib_count);
|
||||
sec_contribs.count = contrib_count;
|
||||
sec_contribs.cap = contrib_count;
|
||||
MSF_UInt sec_con_read = msf_stream_read_array(msf, sn, sec_contribs.v, contrib_count);
|
||||
Assert(sec_con_read == sizeof(sec_contribs.v[0]) * contrib_count);
|
||||
} break;
|
||||
case PDB_DbiSCVersion_2: {
|
||||
NotImplemented;
|
||||
@@ -2709,7 +2694,7 @@ dbi_open_sec_contrib(Arena *arena, MSF_Context *msf, MSF_StreamNumber sn, PDB_Db
|
||||
}
|
||||
|
||||
ProfEnd();
|
||||
return sec_contrib;
|
||||
return sec_contribs;
|
||||
}
|
||||
|
||||
internal void
|
||||
@@ -3138,21 +3123,18 @@ dbi_build_sec_con(Arena *arena, TP_Context *tp, PDB_DbiContext *dbi)
|
||||
*version = PDB_DbiSCVersion_1;
|
||||
|
||||
// push section contribs V1
|
||||
ProfBegin("Push sect contribs [Count %llu]", dbi->sec_contrib_list.count);
|
||||
PDB_DbiSC *sc_array = push_array_no_zero(arena, PDB_DbiSC, dbi->sec_contrib_list.count);
|
||||
PDB_DbiSC *dst = &sc_array[0];
|
||||
for (PDB_DbiSCNode *src = dbi->sec_contrib_list.first; src != 0; src = src->next, dst += 1) {
|
||||
*dst = src->data;
|
||||
}
|
||||
ProfBegin("Push sect contribs [Count %llu]", dbi->sec_contribs.count);
|
||||
PDB_DbiSC *sc_array = push_array_no_zero(arena, PDB_DbiSC, dbi->sec_contribs.count);
|
||||
MemoryCopyTyped(sc_array, dbi->sec_contribs.v, dbi->sec_contribs.count);
|
||||
ProfEnd();
|
||||
|
||||
// sort section contribs so they are binary searchable
|
||||
lnk_radix_sort_dbi_sc_array(tp, sc_array, dbi->sec_contrib_list.count, dbi->section_list.count + 1);
|
||||
lnk_radix_sort_dbi_sc_array(tp, sc_array, dbi->sec_contribs.count, dbi->section_list.count + 1);
|
||||
|
||||
// DBI contribution maps an address range to its module, so adjacent same-module runs can share one record
|
||||
ProfBegin("Coalesce sect contribs");
|
||||
U64 sc_count = 0;
|
||||
for EachIndex(read_idx, dbi->sec_contrib_list.count) {
|
||||
for EachIndex(read_idx, dbi->sec_contribs.count) {
|
||||
PDB_DbiSC *current = &sc_array[read_idx];
|
||||
if (sc_count > 0) {
|
||||
PDB_DbiSC *previous = &sc_array[sc_count - 1];
|
||||
@@ -3363,9 +3345,7 @@ dbi_module_push_section_contrib(PDB_DbiContext *dbi,
|
||||
sc.data_crc = data_crc;
|
||||
sc.reloc_crc = reloc_crc;
|
||||
|
||||
PDB_DbiSCNode *node = push_array_no_zero(dbi->arena, PDB_DbiSCNode, 1);
|
||||
node->data = sc;
|
||||
dbi_sec_contrib_list_push_node(&dbi->sec_contrib_list, node);
|
||||
*dbi_sec_contrib_array_push(dbi->arena, &dbi->sec_contribs) = sc;
|
||||
|
||||
// Mod1::fUpdateSecContrib
|
||||
if (mod->first_sc.base.mod == 0) {
|
||||
|
||||
@@ -255,18 +255,12 @@ typedef struct PDB_DbiModuleList
|
||||
U64 count;
|
||||
} PDB_DbiModuleList;
|
||||
|
||||
typedef struct PDB_DbiSCNode
|
||||
typedef struct PDB_DbiSCArray
|
||||
{
|
||||
struct PDB_DbiSCNode *next;
|
||||
PDB_DbiSC data;
|
||||
} PDB_DbiSCNode;
|
||||
|
||||
typedef struct PDB_DbiSCList
|
||||
{
|
||||
PDB_DbiSCNode *first;
|
||||
PDB_DbiSCNode *last;
|
||||
U64 count;
|
||||
} PDB_DbiSCList;
|
||||
PDB_DbiSC *v;
|
||||
U64 count;
|
||||
U64 cap;
|
||||
} PDB_DbiSCArray;
|
||||
|
||||
typedef struct PDB_DbiSectionNode
|
||||
{
|
||||
@@ -290,7 +284,7 @@ typedef struct PDB_DbiContext
|
||||
MSF_StreamNumber publics_sn;
|
||||
MSF_StreamNumber symbols_sn;
|
||||
PDB_DbiModuleList module_list;
|
||||
PDB_DbiSCList sec_contrib_list;
|
||||
PDB_DbiSCArray sec_contribs;
|
||||
PDB_DbiSectionList section_list;
|
||||
PDB_StringTable ec_names;
|
||||
MSF_StreamNumber dbg_streams[PDB_DbiStream_COUNT];
|
||||
@@ -403,7 +397,7 @@ internal String8 dbi_module_read_c13_data(Arena *arena, MSF_Context *
|
||||
internal void dbi_module_push_section_contrib(PDB_DbiContext *dbi, PDB_DbiModule *mod, ISectOff isect_off, U32 size, U32 data_crc, U32 reloc_crc, COFF_SectionFlags flags);
|
||||
internal String8List * dbi_open_file_info(Arena *arena, MSF_Context *msf, MSF_StreamNumber sn, PDB_DbiHeader *dbi_header);
|
||||
internal PDB_DbiModuleList dbi_open_module_info(Arena *arena, MSF_Context *msf, MSF_StreamNumber sn, PDB_DbiHeader *dbi_header, String8List *file_info);
|
||||
internal PDB_DbiSCList dbi_open_sec_contrib(Arena *arena, MSF_Context *msf, MSF_StreamNumber sn, PDB_DbiHeader *dbi_header);
|
||||
internal PDB_DbiSCArray dbi_open_sec_contrib(Arena *arena, MSF_Context *msf, MSF_StreamNumber sn, PDB_DbiHeader *dbi_header);
|
||||
internal PDB_StringTable dbi_open_ec_names(Arena *arena, MSF_Context *msf, MSF_StreamNumber sn, PDB_DbiHeader *dbi_header);
|
||||
internal void dbi_open_dbg_streams(MSF_StreamNumber *dbg_streams, MSF_Context *msf, MSF_StreamNumber sn, PDB_DbiHeader *dbi_header);
|
||||
internal PDB_DbiSectionList dbi_open_section_headers(Arena *arena, MSF_Context *msf, MSF_StreamNumber sn);
|
||||
|
||||
Reference in new issue
Block a user