From d7a87b7765e1a37fbf738d7028a695a697ea3ef9 Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Fri, 13 Feb 2026 16:06:54 -0800 Subject: [PATCH] share arena between type deduper and MSF --- src/linker/lnk_debug_info.c | 19 ++++++++++++++++--- src/linker/pdb_ext/msf_builder.c | 16 ++++++++++------ src/linker/pdb_ext/pdb_builder.c | 15 ++++++++++----- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/linker/lnk_debug_info.c b/src/linker/lnk_debug_info.c index 6c3f2511..74a53a95 100644 --- a/src/linker/lnk_debug_info.c +++ b/src/linker/lnk_debug_info.c @@ -1,6 +1,17 @@ // Copyright (c) Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) +static Arena *g_huge_arena = 0; + +internal Arena * +lnk_get_huge_arena(void) +{ + if (g_huge_arena == 0) { + g_huge_arena = arena_alloc(.name = "HUGE"); + } + return g_huge_arena; +} + internal THREAD_POOL_TASK_FUNC(lnk_parse_debug_s_task) { @@ -2158,7 +2169,7 @@ internal CV_DebugT * lnk_import_types(TP_Context *tp, TP_Arena *tp_temp, LNK_CodeViewInput *input) { ProfBegin("Import Types"); - Temp scratch = scratch_begin(tp_temp->v, tp_temp->count); + Temp scratch = temp_begin(lnk_get_huge_arena()); U64 max_ti_list_size = sizeof(CV_TypeIndexInfo) * (max_U16 / sizeof(CV_TypeIndex)); Arena **fixed_arenas = alloc_fixed_size_arena_array(scratch.arena, tp->worker_count, max_ti_list_size, max_ti_list_size); @@ -2366,7 +2377,7 @@ lnk_import_types(TP_Context *tp, TP_Arena *tp_temp, LNK_CodeViewInput *input) tp_for_parallel_prof(tp, 0, input->total_symbol_input_count, lnk_post_process_cv_symbols_task, &task, "Post Process CV Symbols"); - scratch_end(scratch); + temp_end(scratch); ProfEnd(); return task.types; } @@ -3013,13 +3024,14 @@ lnk_build_pdb(TP_Context *tp, { ProfBegin("PDB"); Temp scratch = scratch_begin(tp_arena->v, tp_arena->count); + Temp huge_arena_temp = temp_begin(lnk_get_huge_arena()); PE_BinInfo pe = pe_bin_info_from_data(scratch.arena, image_data); COFF_SectionHeader **image_section_table = coff_section_table_from_data(scratch.arena, image_data, pe.section_table_range); U64 image_section_table_count = pe.section_count+1; ProfBegin("Setup PDB Context"); - PDB_Context *pdb = pdb_alloc(config->pdb_page_size, config->machine, config->time_stamp, config->age, config->guid); + PDB_Context *pdb = pdb_alloc_(huge_arena_temp.arena, config->pdb_page_size, config->machine, config->time_stamp, config->age, config->guid); ProfEnd(); // move patched type data @@ -3243,6 +3255,7 @@ lnk_build_pdb(TP_Context *tp, ProfEnd(); #endif + temp_end(huge_arena_temp); scratch_end(scratch); ProfEnd(); return page_data_list; diff --git a/src/linker/pdb_ext/msf_builder.c b/src/linker/pdb_ext/msf_builder.c index b0e9bfc2..e3604285 100644 --- a/src/linker/pdb_ext/msf_builder.c +++ b/src/linker/pdb_ext/msf_builder.c @@ -1343,14 +1343,12 @@ msf_stream_align(MSF_Context *msf, MSF_StreamNumber sn, MSF_UInt align) //////////////////////////////// internal MSF_Context * -msf_alloc__(MSF_UInt page_size, MSF_PageNumber active_fpm) +msf_alloc__(Arena *arena, MSF_UInt page_size, MSF_PageNumber active_fpm) { ProfBeginFunction(); Assert(active_fpm == MSF_FPM0 || active_fpm == MSF_FPM1); Assert(IsPow2(page_size)); - Arena *arena = arena_alloc(); - MSF_Context *msf = push_array(arena, MSF_Context, 1); msf->arena = arena; msf->page_size = page_size; @@ -1361,9 +1359,9 @@ msf_alloc__(MSF_UInt page_size, MSF_PageNumber active_fpm) } internal MSF_Context * -msf_alloc(MSF_UInt page_size, MSF_UInt active_fpm) +msf_alloc_(Arena *arena, MSF_UInt page_size, MSF_UInt active_fpm) { - MSF_Context *msf = msf_alloc__(page_size, active_fpm); + MSF_Context *msf = msf_alloc__(arena, page_size, active_fpm); // reserve first page for header msf->header_page_list = msf_alloc_pages(msf, 1); @@ -1378,6 +1376,12 @@ msf_alloc(MSF_UInt page_size, MSF_UInt active_fpm) return msf; } +internal MSF_Context * +msf_alloc(MSF_UInt page_size, MSF_UInt active_fpm) +{ + return msf_alloc_(arena_alloc( .name = "MSF"), page_size, active_fpm); +} + internal MSF_StreamNode * msf_find_stream_node(MSF_Context *msf, MSF_StreamNumber sn) { @@ -1608,7 +1612,7 @@ msf_open(String8 data, MSF_Context **msf_out) } // allocate MSF context and don't reserve special pages - msf = msf_alloc__(header->page_size, header->active_fpm); + msf = msf_alloc__(arena_alloc(.name = "MSF"), header->page_size, header->active_fpm); // divide data into fixed size nodes (with 4KB page each node is 128MB) msf_set_page_data_list(msf->arena, &page_data_list, header->page_size, data); diff --git a/src/linker/pdb_ext/pdb_builder.c b/src/linker/pdb_ext/pdb_builder.c index 153bc759..28ea814c 100644 --- a/src/linker/pdb_ext/pdb_builder.c +++ b/src/linker/pdb_ext/pdb_builder.c @@ -3516,10 +3516,10 @@ dbi_push_section(PDB_DbiContext *dbi, COFF_SectionHeader *hdr) //////////////////////////////// internal MSF_Context * -pdb_alloc_msf(U64 page_size) +pdb_alloc_msf(Arena *arena, U64 page_size) { ProfBeginFunction(); - MSF_Context *msf = msf_alloc(page_size, MSF_DEFAULT_FPM); + MSF_Context *msf = msf_alloc_(arena, page_size, MSF_DEFAULT_FPM); MSF_StreamNumber null_sn = msf_stream_alloc(msf); MSF_StreamNumber info_sn = msf_stream_alloc(msf); MSF_StreamNumber tpi_sn = msf_stream_alloc(msf); @@ -3535,13 +3535,12 @@ pdb_alloc_msf(U64 page_size) } internal PDB_Context * -pdb_alloc(U64 page_size, COFF_MachineType machine, COFF_TimeStamp time_stamp, U32 age, Guid guid) +pdb_alloc_(Arena *arena, U64 page_size, COFF_MachineType machine, COFF_TimeStamp time_stamp, U32 age, Guid guid) { ProfBeginFunction(); - Arena *arena = arena_alloc(); PDB_Context *pdb = push_array(arena, PDB_Context, 1); pdb->arena = arena; - pdb->msf = pdb_alloc_msf(page_size); + pdb->msf = pdb_alloc_msf(arena, page_size); pdb->info = pdb_info_alloc(age, time_stamp, guid); pdb->dbi = dbi_alloc(machine, age); pdb->gsi = gsi_alloc(); @@ -3554,6 +3553,12 @@ pdb_alloc(U64 page_size, COFF_MachineType machine, COFF_TimeStamp time_stamp, U3 return pdb; } +internal PDB_Context * +pdb_alloc(U64 page_size, COFF_MachineType machine, COFF_TimeStamp time_stamp, U32 age, Guid guid) +{ + return pdb_alloc_(arena_alloc(.name = "PDB"), page_size, machine, time_stamp, age, guid); +} + internal PDB_Context * pdb_open(String8 data) {