From e942dd0380b2c2347877acf3bf8c315863a649b8 Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Tue, 17 Feb 2026 17:40:06 -0800 Subject: [PATCH] checkpoint --- src/linker/lnk_debug_info.c | 109 ++++++++++++++---------------------- src/linker/lnk_debug_info.h | 2 +- 2 files changed, 42 insertions(+), 69 deletions(-) diff --git a/src/linker/lnk_debug_info.c b/src/linker/lnk_debug_info.c index fda7848f..9cc8d934 100644 --- a/src/linker/lnk_debug_info.c +++ b/src/linker/lnk_debug_info.c @@ -1245,10 +1245,12 @@ lnk_hash_cv_leaf_deep(Arena *arena, Rng1U64 *ti_ranges, CV_DebugT *leaves, LNK_LeafHashes *hashes, + CV_TypeIndexSource ti_source, + CV_TypeIndex ti, LNK_LeafLocType loc_type, U32 loc_idx, CV_TypeIndexInfoList ti_info_list, - String8 data) + CV_Leaf leaf) { Temp temp = temp_begin(arena); @@ -1257,20 +1259,17 @@ lnk_hash_cv_leaf_deep(Arena *arena, CV_TypeIndexInfoList ti_info_list; CV_TypeIndexInfo *ti_info; CV_Leaf leaf; - String8 data; CV_TypeIndex ti; CV_TypeIndexSource ti_source; }; // set up root frame - struct stack_s *root_frame = push_array_no_zero(temp.arena, struct stack_s, 1); - root_frame->next = 0; + struct stack_s *root_frame = push_array(temp.arena, struct stack_s, 1); root_frame->ti_info_list = ti_info_list; root_frame->ti_info = ti_info_list.first; - root_frame->data = data; - root_frame->ti = 0; - root_frame->ti_source = CV_TypeIndexSource_NULL; - MemoryZeroStruct(&root_frame->leaf); + root_frame->leaf = leaf; + root_frame->ti = ti; + root_frame->ti_source = ti_source; U64 **curr_hashes = hashes->v[loc_type][loc_idx]; @@ -1283,18 +1282,18 @@ lnk_hash_cv_leaf_deep(Arena *arena, stack->ti_info = stack->ti_info->next; // get type index info - CV_TypeIndex *ti_ptr = (CV_TypeIndex *) (stack->data.str + curr_ti_info->offset); + CV_TypeIndex *ti_ptr = (CV_TypeIndex *) (stack->leaf.data.str + curr_ti_info->offset); CV_TypeIndex ti = memory_read32(ti_ptr); // is index complex? if (ti >= ti_ranges[curr_ti_info->source].min) { // TODO: handle malformed index AssertAlways(ti < ti_ranges[curr_ti_info->source].max); - U64 ti_idx = (ti - ti_ranges[curr_ti_info->source].min); + U64 leaf_idx = (ti - ti_ranges[curr_ti_info->source].min); // was leaf hashed? - if (curr_hashes[curr_ti_info->source][ti_idx] == 0) { // :zero_hash_array - CV_Leaf leaf = cv_debug_t_get_leaf(leaves[curr_ti_info->source], ti_idx); + if (curr_hashes[curr_ti_info->source][leaf_idx] == 0) { // :zero_hash_array + CV_Leaf leaf = cv_debug_t_get_leaf(leaves[curr_ti_info->source], leaf_idx); // find index offsets CV_TypeIndexInfoList sub_ti_info_list = cv_get_leaf_type_index_offsets(temp.arena, leaf.kind, leaf.data); @@ -1302,12 +1301,10 @@ lnk_hash_cv_leaf_deep(Arena *arena, // do we have sub leaves? if (sub_ti_info_list.count) { // fill out new frame - struct stack_s *frame = push_array_no_zero(temp.arena, struct stack_s, 1); - frame->next = 0; + struct stack_s *frame = push_array(temp.arena, struct stack_s, 1); frame->ti_info_list = sub_ti_info_list; frame->ti_info = sub_ti_info_list.first; frame->leaf = leaf; - frame->data = leaf.data; frame->ti = ti; frame->ti_source = curr_ti_info->source; @@ -1315,14 +1312,7 @@ lnk_hash_cv_leaf_deep(Arena *arena, SLLStackPush(stack, frame); break; } else { - curr_hashes[curr_ti_info->source][ti_idx] = lnk_hash_cv_leaf(input, - hashes, - loc_type, - loc_idx, - ti_ranges, - CV_TypeIndex_Max, - leaf, - sub_ti_info_list); + curr_hashes[curr_ti_info->source][leaf_idx] = lnk_hash_cv_leaf(input, hashes, loc_type, loc_idx, ti_ranges, CV_TypeIndex_Max, leaf, sub_ti_info_list); } } } @@ -1330,24 +1320,17 @@ lnk_hash_cv_leaf_deep(Arena *arena, // no more type indices, pop frame if (!stack->ti_info) { - - if (stack != root_frame) { - // sub leaves are hashed we can now hash parent leaf - U64 leaf_idx = stack->ti - ti_ranges[stack->ti_source].min; - curr_hashes[stack->ti_source][leaf_idx] = lnk_hash_cv_leaf(input, - hashes, - loc_type, - loc_idx, - ti_ranges, - CV_TypeIndex_Max, - stack->leaf, - stack->ti_info_list); - } - SLLStackPop(stack); } } + // sub leaves are hashed we can now hash parent leaf + { + U64 leaf_idx = ti - ti_ranges[ti_source].min; + curr_hashes[ti_source][leaf_idx] = lnk_hash_cv_leaf(input, hashes, loc_type, loc_idx, ti_ranges, CV_TypeIndex_Max, leaf, ti_info_list); + Assert(curr_hashes[ti_source][leaf_idx] != 0); + } + temp_end(temp); } @@ -1502,39 +1485,25 @@ THREAD_POOL_TASK_FUNC(lnk_hash_debug_t_task) } internal -THREAD_POOL_TASK_FUNC(lnk_hash_type_server_leaves_task) +THREAD_POOL_TASK_FUNC(lnk_hash_debug_t_deep_task) { ProfBeginFunction(); - LNK_CvImportTypes *task = raw_task; - U64 obj_idx = task_id; + LNK_CvImportTypes *task = raw_task; + U64 ts_idx = task_id; + CV_TypeIndexSource ti_source = task->ti_source; + CV_DebugT debug_t = task->debug_t_arr [ts_idx]; + Rng1U64 *ti_ranges = task->input->external_ti_ranges[ts_idx]; + CV_DebugT *leaves = task->input->external_leaves [ts_idx]; - LNK_CodeViewInput *input = task->input; - LNK_LeafHashes *hashes = task->hashes; - - CV_SymbolListArray parsed_symbols = input->external_parsed_symbols[obj_idx]; - CV_DebugS debug_s = input->external_debug_s_arr[obj_idx]; - U64 ts_idx = input->external_obj_to_ts_idx_arr[obj_idx]; - CV_DebugT *leaves = input->external_leaves[ts_idx]; - Rng1U64 *ti_ranges = input->external_ti_ranges[ts_idx]; - - // hash leaves referenced in symbols - for EachIndex(i, parsed_symbols.count) { - CV_SymbolList symbol_list = parsed_symbols.v[i]; - for EachNode(symnode, CV_SymbolNode, symbol_list.first) { - Temp temp = temp_begin(task->fixed_arenas[worker_id]); - CV_TypeIndexInfoList ti_info_list = cv_get_symbol_type_index_offsets(temp.arena, symnode->data.kind, symnode->data.data); - lnk_hash_cv_leaf_deep(temp.arena, task->input, ti_ranges, leaves, hashes, LNK_LeafLocType_External, ts_idx, ti_info_list, symnode->data.data); - temp_end(temp); - } - } - - // hash leaves referenced in inlinees - String8List inline_data_list = cv_sub_section_from_debug_s(debug_s, CV_C13SubSectionKind_InlineeLines); - for EachNode(inline_data_node, String8Node, inline_data_list.first) { + for EachIndex(leaf_idx, debug_t.count) { + U64 hash = task->hashes->v[LNK_LeafLocType_External][ts_idx] [ti_source][leaf_idx]; + if (hash != 0) { continue; } Temp temp = temp_begin(task->fixed_arenas[worker_id]); - CV_TypeIndexInfoList ti_info_list = cv_get_inlinee_type_index_offsets(temp.arena, inline_data_node->string); - lnk_hash_cv_leaf_deep(temp.arena, task->input, ti_ranges, leaves, hashes, LNK_LeafLocType_External, ts_idx, ti_info_list, inline_data_node->string); + CV_Leaf leaf = cv_debug_t_get_leaf(debug_t, leaf_idx); + CV_TypeIndexInfoList ti_info_list = cv_get_leaf_type_index_offsets(temp.arena, leaf.kind, leaf.data); + CV_TypeIndex ti = ti_ranges[ti_source].min + leaf_idx; + lnk_hash_cv_leaf_deep(temp.arena, task->input, ti_ranges, leaves, task->hashes, ti_source, ti, LNK_LeafLocType_External, ts_idx, ti_info_list, leaf); temp_end(temp); } @@ -2239,9 +2208,13 @@ lnk_merge_types(TP_Context *tp, TP_Arena *tp_temp, LNK_CodeViewInput *input) tp_for_parallel(tp, 0, input->internal_count, lnk_hash_debug_t_task, &task); ProfEnd(); - ProfBegin("Hash Type Server Leaves [Count: %.*s]", str8_varg(str8_from_count(scratch.arena, input->external_count))); - tp_for_parallel(tp, 0, input->external_count, lnk_hash_type_server_leaves_task, &task); - ProfEnd(); + task.ti_source = CV_TypeIndexSource_IPI; + task.debug_t_arr = input->external_leaves[task.ti_source]; + tp_for_parallel_prof(tp, 0, input->type_server_count, lnk_hash_debug_t_deep_task, &task, "Hash IPI Type Servers"); + + task.ti_source = CV_TypeIndexSource_TPI; + task.debug_t_arr = input->external_leaves[task.ti_source]; + tp_for_parallel_prof(tp, 0, input->type_server_count, lnk_hash_debug_t_deep_task, &task, "Hash IPI Type Servers"); } ProfEnd(); diff --git a/src/linker/lnk_debug_info.h b/src/linker/lnk_debug_info.h index 1a039dc7..76449044 100644 --- a/src/linker/lnk_debug_info.h +++ b/src/linker/lnk_debug_info.h @@ -469,7 +469,7 @@ internal B32 lnk_match_leaf_ref (LNK_CodeViewInput *in // leaf hashing internal U64 lnk_hash_cv_leaf (LNK_CodeViewInput *input, LNK_LeafHashes *hashes, LNK_LeafLocType loc_type, U32 loc_idx, Rng1U64 *ti_ranges, CV_TypeIndex curr_ti, CV_Leaf leaf, CV_TypeIndexInfoList ti_info_list); -internal void lnk_hash_cv_leaf_deep(Arena *arena, LNK_CodeViewInput *input, Rng1U64 *ti_ranges, CV_DebugT *leaves, LNK_LeafHashes *hashes, LNK_LeafLocType loc_type, U32 loc_idx, CV_TypeIndexInfoList ti_info_list, String8 data); +internal void lnk_hash_cv_leaf_deep(Arena *arena, LNK_CodeViewInput *input, Rng1U64 *ti_ranges, CV_DebugT *leaves, LNK_LeafHashes *hashes, CV_TypeIndexSource ti_source, CV_TypeIndex ti, LNK_LeafLocType loc_type, U32 loc_idx, CV_TypeIndexInfoList ti_info_list, CV_Leaf leaf); internal U64 lnk_hash_from_leaf_ref(LNK_LeafHashes *hashes, LNK_LeafRef leaf_ref); // leaf hash table