improve memory usage when reporting unresolved symbols

This commit is contained in:
Nikita Smith
2026-02-11 15:28:13 -08:00
parent e8ca3e0d5c
commit aa25570904
+14 -4
View File
@@ -2077,6 +2077,9 @@ lnk_link_image(TP_Context *tp, TP_Arena *arena, LNK_Config *config, LNK_Inputer
radsort(unresolved_symbols, unresolved_symbols_count, lnk_symbol_ptr_is_before); radsort(unresolved_symbols, unresolved_symbols_count, lnk_symbol_ptr_is_before);
} }
if (unresolved_symbols_count) {
Temp debug_scratch = scratch_begin(&scratch.arena, 1);
for EachIndex(i, unresolved_symbols_count) { for EachIndex(i, unresolved_symbols_count) {
LNK_Symbol *symbol = unresolved_symbols[i]; LNK_Symbol *symbol = unresolved_symbols[i];
@@ -2095,6 +2098,7 @@ lnk_link_image(TP_Context *tp, TP_Arena *arena, LNK_Config *config, LNK_Inputer
COFF_SectionHeader *section_table = lnk_coff_section_table_from_obj(obj); COFF_SectionHeader *section_table = lnk_coff_section_table_from_obj(obj);
String8 string_table = lnk_coff_string_table_from_obj(obj); String8 string_table = lnk_coff_string_table_from_obj(obj);
Temp debug_temp = temp_begin(debug_scratch.arena);
CV_DebugS debug_s = {0}; CV_DebugS debug_s = {0};
CV_LinesAccel *debug_lines = 0; CV_LinesAccel *debug_lines = 0;
String8 debug_checksums = {0}; String8 debug_checksums = {0};
@@ -2110,6 +2114,7 @@ lnk_link_image(TP_Context *tp, TP_Arena *arena, LNK_Config *config, LNK_Inputer
for EachIndex(reloc_idx, relocs.count) { for EachIndex(reloc_idx, relocs.count) {
if (supp_info.node_count > config->unresolved_symbol_ref_limit) { if (supp_info.node_count > config->unresolved_symbol_ref_limit) {
str8_list_pushf(scratch.arena, &supp_info, "too many unresolved symbol references reported, stopping now"); str8_list_pushf(scratch.arena, &supp_info, "too many unresolved symbol references reported, stopping now");
temp_end(debug_temp);
goto next_undefined_symbol; goto next_undefined_symbol;
} }
COFF_Reloc *reloc = &relocs.v[reloc_idx]; COFF_Reloc *reloc = &relocs.v[reloc_idx];
@@ -2118,10 +2123,10 @@ lnk_link_image(TP_Context *tp, TP_Arena *arena, LNK_Config *config, LNK_Inputer
CV_Line *line_matches = 0; CV_Line *line_matches = 0;
if (config->map_lines_for_unresolved_symbols == LNK_SwitchState_Yes) { if (config->map_lines_for_unresolved_symbols == LNK_SwitchState_Yes) {
if (debug_lines == 0) { if (debug_lines == 0) {
debug_s = lnk_debug_s_from_obj(scratch.arena, obj); debug_s = lnk_debug_s_from_obj(debug_temp.arena, obj);
String8List raw_checksums = cv_sub_section_from_debug_s(debug_s, CV_C13SubSectionKind_FileChksms); String8List raw_checksums = cv_sub_section_from_debug_s(debug_s, CV_C13SubSectionKind_FileChksms);
String8List raw_strings = cv_sub_section_from_debug_s(debug_s, CV_C13SubSectionKind_StringTable); String8List raw_strings = cv_sub_section_from_debug_s(debug_s, CV_C13SubSectionKind_StringTable);
debug_lines = cv_lines_accel_from_debug_s(scratch.arena, debug_s); debug_lines = cv_lines_accel_from_debug_s(debug_temp.arena, debug_s);
debug_checksums = str8_list_first(&raw_checksums); debug_checksums = str8_list_first(&raw_checksums);
debug_strings = str8_list_first(&raw_strings); debug_strings = str8_list_first(&raw_strings);
} }
@@ -2136,14 +2141,16 @@ lnk_link_image(TP_Context *tp, TP_Arena *arena, LNK_Config *config, LNK_Inputer
String8 file_name = {0}; String8 file_name = {0};
str8_deserial_read_struct(debug_checksums, line.file_off, &checksum); str8_deserial_read_struct(debug_checksums, line.file_off, &checksum);
str8_deserial_read_cstr(debug_strings, checksum.name_off, &file_name); str8_deserial_read_cstr(debug_strings, checksum.name_off, &file_name);
str8_list_pushf(scratch.arena, &supp_info, "%S: %S:%u", lnk_loc_from_obj(scratch.arena, obj), file_name, line.line_num); str8_list_pushf(scratch.arena, &supp_info, "%S: %S:%u", lnk_loc_from_obj(debug_temp.arena, obj), file_name, line.line_num);
} }
} else { } else {
str8_list_pushf(scratch.arena, &supp_info, "%S: %S(%llx)+%x", lnk_loc_from_obj(scratch.arena, obj), section_name, section_number, reloc->apply_off); str8_list_pushf(scratch.arena, &supp_info, "%S: %S(%llx)+%x", lnk_loc_from_obj(debug_temp.arena, obj), section_name, section_number, reloc->apply_off);
} }
} }
} }
} }
temp_end(debug_temp);
} }
next_undefined_symbol:; next_undefined_symbol:;
} }
@@ -2152,6 +2159,9 @@ lnk_link_image(TP_Context *tp, TP_Arena *arena, LNK_Config *config, LNK_Inputer
lnk_supplement_error_list(supp_info); lnk_supplement_error_list(supp_info);
} }
scratch_end(debug_scratch);
}
// TODO: /FORCE // TODO: /FORCE
if (unresolved_symbols_count) { if (unresolved_symbols_count) {
lnk_exit(LNK_Error_UnresolvedSymbol); lnk_exit(LNK_Error_UnresolvedSymbol);