test stripped PDB

This commit is contained in:
Nikita Smith
2026-04-20 10:39:50 -07:00
parent aefd73e551
commit e6f49aaded
5 changed files with 146 additions and 35 deletions
+3 -1
View File
@@ -196,11 +196,13 @@ cv_write_symbol_buf(String8Node *buf, U64 *buf_pos, CV_Symbol *symbol, U64 align
{
CV_SymbolHeader header = { .size = sizeof(CV_SymKind) + symbol->data.size, .kind = symbol->kind };
U64 pad_size = AlignPadPow2(header.size + sizeof(CV_SymSize), align);
header.size += pad_size;
U64 write_size = 0;
write_size += str8_buffer_write(buf, buf_pos, str8_struct(&header));
write_size += str8_buffer_write(buf, buf_pos, symbol->data);
write_size += str8_buffer_write_zeroes(buf, buf_pos, pad_size);
Assert(write_size == header.size + sizeof(CV_SymSize) + pad_size);
return write_size;
}
+6 -8
View File
@@ -5320,7 +5320,8 @@ lnk_run(TP_Context *tp, TP_Arena *arena, LNK_Config *config)
if (symbol.kind == CV_SymKind_SKIP) { continue; }
if (cv_is_lproc(symbol)) {
proc_count += 1;
proc_size += AlignPow2(symbol.data.size, CV_SymbolAlign);
proc_size += AlignPow2(sizeof(CV_SymbolHeader) + symbol.data.size, CV_SymbolAlign);
proc_size += AlignPow2(sizeof(CV_SymbolHeader), CV_SymbolAlign); // S_END
}
}
section += 1;
@@ -5329,7 +5330,7 @@ lnk_run(TP_Context *tp, TP_Arena *arena, LNK_Config *config)
if (proc_count) {
U64 end_count = proc_count;
U64 symbol_count = proc_count + end_count;
U64 buffer_size = proc_size + sizeof(CV_SymbolHeader) * symbol_count;
U64 buffer_size = proc_size;
U8 *buffer = push_array(scratch.arena, U8, buffer_size);
U64 buffer_cursor = 0;
@@ -5339,13 +5340,10 @@ lnk_run(TP_Context *tp, TP_Arena *arena, LNK_Config *config)
TryReadBreak(cv_read_symbol(n->string, cursor, CV_SymbolAlign, &symbol), cursor);
if (symbol.kind == CV_SymKind_SKIP) { continue; }
if (cv_is_lproc(symbol)) {
CV_SymProc32 *src_proc = (CV_SymProc32 *)symbol.data.str;
src_proc->itype = 0;
CV_Symbol end_symbol = { .kind = CV_SymKind_END };
CV_SymProc32 *src_proc = str8_deserial_get_raw_ptr(symbol.data, 0, sizeof(*src_proc));
memory_write32(&src_proc->itype, 0); // strip type index
buffer_cursor += cv_write_symbol(buffer, buffer_cursor, buffer_size, &symbol, CV_SymbolAlign);
buffer_cursor += cv_write_symbol(buffer, buffer_cursor, buffer_size, &end_symbol, CV_SymbolAlign);
buffer_cursor += cv_write_symbol(buffer, buffer_cursor, buffer_size, &(CV_Symbol){ .kind = CV_SymKind_END }, CV_SymbolAlign);
}
}
}
+13 -12
View File
@@ -2411,18 +2411,19 @@ lnk_build_pdb(TP_Context *tp, TP_Arena *tp_arena, String8 image_data, LNK_Config
cv_string_hash_table_assign_buffer_offsets(tp, task.string_ht);
ProfEnd();
ProfScope ("Alloc Modules") for EachIndex(obj_idx, cv->obj_count) { task.mod_arr[obj_idx] = dbi_push_module(task.pdb->dbi, cv->obj_arr[obj_idx]->path, lnk_obj_get_lib_path(cv->obj_arr[obj_idx])); }
ProfScope("Move Global Symbols") tp_for_parallel(tp, 0, tp->worker_count, lnk_move_global_symbols_to_gsi, &task);
{
PDB_Context *pdb = task.pdb;
PDB_DbiContext *dbi = pdb->dbi;
dbi->globals_sn = msf_stream_alloc(pdb->msf);
dbi->publics_sn = msf_stream_alloc(pdb->msf);
dbi->symbols_sn = msf_stream_alloc(pdb->msf);
psi_build(tp, pdb->psi, pdb->msf, dbi->publics_sn, dbi->symbols_sn);
gsi_build(tp, pdb->gsi, pdb->msf, dbi->globals_sn, dbi->symbols_sn);
}
ProfScope("Write Modules") tp_for_parallel(tp, 0, tp->worker_count, lnk_write_pdb_modules, &task);
ProfScope ("Alloc Modules")
for EachIndex(obj_idx, cv->obj_count) {
task.mod_arr[obj_idx] = dbi_push_module(task.pdb->dbi, cv->obj_arr[obj_idx]->path, lnk_obj_get_lib_path(cv->obj_arr[obj_idx]));
}
ProfScope("Move Global Symbols")
tp_for_parallel(tp, 0, tp->worker_count, lnk_move_global_symbols_to_gsi, &task);
ProfScope("Build GSI and PSI")
pdb_build_gsi_psi(tp, task.pdb);
ProfScope("Write Modules")
tp_for_parallel(tp, 0, tp->worker_count, lnk_write_pdb_modules, &task);
ProfBegin("Add string tables");
pdb_strtab_add_cv_string_hash_table(&task.pdb->info->strtab, task.string_ht);
+19 -11
View File
@@ -3134,6 +3134,24 @@ pdb_get_guid(PDB_Context *pdb)
return pdb->info->guid;
}
internal void
pdb_build_gsi_psi(TP_Context *tp, PDB_Context *pdb)
{
PDB_DbiContext *dbi = pdb->dbi;
if (pdb->psi->gsi->symbol_count) {
if (dbi->publics_sn == MSF_INVALID_STREAM_NUMBER) { dbi->publics_sn = msf_stream_alloc(pdb->msf); }
if (dbi->symbols_sn == MSF_INVALID_STREAM_NUMBER) { dbi->symbols_sn = msf_stream_alloc(pdb->msf); }
psi_build(tp, pdb->psi, pdb->msf, dbi->publics_sn, dbi->symbols_sn);
}
if (pdb->gsi->symbol_count) {
if (dbi->globals_sn == MSF_INVALID_STREAM_NUMBER) { dbi->globals_sn = msf_stream_alloc(pdb->msf); }
if (dbi->symbols_sn == MSF_INVALID_STREAM_NUMBER) { dbi->symbols_sn = msf_stream_alloc(pdb->msf); }
gsi_build(tp, pdb->gsi, pdb->msf, dbi->globals_sn, dbi->symbols_sn);
}
}
internal void
pdb_build(TP_Context *tp, TP_Arena *pool_temp, PDB_Context *pdb, CV_StringHashTable string_ht, B32 build_gsi, B32 is_stripped)
{
@@ -3151,17 +3169,7 @@ pdb_build(TP_Context *tp, TP_Arena *pool_temp, PDB_Context *pdb, CV_StringHashTa
}
if (build_gsi) {
if (dbi->globals_sn == MSF_INVALID_STREAM_NUMBER) {
dbi->globals_sn = msf_stream_alloc(pdb->msf);
}
if (dbi->publics_sn == MSF_INVALID_STREAM_NUMBER) {
dbi->publics_sn = msf_stream_alloc(pdb->msf);
}
if (dbi->symbols_sn == MSF_INVALID_STREAM_NUMBER) {
dbi->symbols_sn = msf_stream_alloc(pdb->msf);
}
psi_build(tp, pdb->psi, pdb->msf, dbi->publics_sn, dbi->symbols_sn);
gsi_build(tp, pdb->gsi, pdb->msf, dbi->globals_sn, dbi->symbols_sn);
pdb_build_gsi_psi(tp, pdb);
}
dbi_build(tp, pdb->dbi, pdb->msf, PDB_FixedStream_Dbi, string_ht, is_stripped);