checkpoint on multi-lane / simplified dwarf parsing/conversion; fix incorrect assumption of relative in radbin

This commit is contained in:
Ryan Fleury committed 2026-04-23 14:25:50 -07:00
1 parent 6f624c10ad
commit 2623141fd4
25 files changed
+3154 -2822

No files matched your search

+14 -14
View File
@@ -717,7 +717,7 @@ d2r_push_relational_op(Arena *arena, D2R_ValueTypeStack *stack, RDIM_EvalBytecod
internal RDIM_EvalBytecode
d2r_bytecode_from_expression(Arena *arena,
DW_Input *input,
DW_Raw *input,
U64 image_base,
Arch arch,
DW_ListUnit *addr_lu,
@@ -1312,7 +1312,7 @@ d2r_bytecode_from_expression(Arena *arena,
}
internal RDIM_Location
d2r_transpile_expression(Arena *arena, DW_Input *input, U64 image_base, Arch arch, DW_ListUnit *addr_lu, DW_CompUnit *cu, String8 expr)
d2r_transpile_expression(Arena *arena, DW_Raw *input, U64 image_base, Arch arch, DW_ListUnit *addr_lu, DW_CompUnit *cu, String8 expr)
{
RDIM_Location loc = {0};
if (expr.size) {
@@ -1325,7 +1325,7 @@ d2r_transpile_expression(Arena *arena, DW_Input *input, U64 image_base, Arch arc
}
internal RDIM_Location
d2r_location_from_attrib(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag, DW_AttribKind kind)
d2r_location_from_attrib(Arena *arena, DW_Raw *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag, DW_AttribKind kind)
{
String8 expr = dw_exprloc_from_tag_attrib_kind(input, cu, tag, kind);
RDIM_Location location = d2r_transpile_expression(arena, input, image_base, arch, cu->addr_lu, cu, expr);
@@ -1336,7 +1336,7 @@ internal RDIM_LocationCaseList
d2r_locset_from_attrib(Arena *arena,
RDIM_ScopeChunkList *scopes,
RDIM_Scope *curr_scope,
DW_Input *input,
DW_Raw *input,
DW_CompUnit *cu,
U64 image_base,
Arch arch,
@@ -1383,7 +1383,7 @@ internal RDIM_LocationCaseList
d2r_var_locset_from_tag(Arena *arena,
RDIM_ScopeChunkList *scopes,
RDIM_Scope *curr_scope,
DW_Input *input,
DW_Raw *input,
DW_CompUnit *cu,
U64 image_base,
Arch arch,
@@ -1450,7 +1450,7 @@ d2r_type_from_offset(D2R_TypeTable *type_table, U64 info_off)
}
internal RDIM_Type *
d2r_type_from_attrib(D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
d2r_type_from_attrib(D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{
RDIM_Type *type = type_table->builtin_types[RDI_TypeKind_Void];
@@ -1559,7 +1559,7 @@ d2r_is_type_tag_converted(DW_TagNode *tag_node)
}
internal RDIM_Type *
d2r_find_or_convert_type(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, Arch arch, DW_Tag tag, DW_AttribKind kind)
d2r_find_or_convert_type(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Language cu_lang, Arch arch, DW_Tag tag, DW_AttribKind kind)
{
RDIM_Type *type = type_table->builtin_types[RDI_TypeKind_Void];
@@ -1604,7 +1604,7 @@ d2r_find_or_convert_type(Arena *arena, D2R_TypeTable *type_table, DW_Input *inpu
internal void
d2r_convert_types(Arena *arena,
D2R_TypeTable *type_table,
DW_Input *input,
DW_Raw *input,
DW_CompUnit *cu,
DW_Language cu_lang,
Arch arch,
@@ -2088,7 +2088,7 @@ d2r_inline_anonymous_udt_member(Arena *arena, RDIM_UDT *top_udt, U64 base_off, R
internal void
d2r_convert_udts(Arena *arena,
D2R_TypeTable *type_table,
DW_Input *input,
DW_Raw *input,
DW_CompUnit *cu,
DW_Language cu_lang,
DW_TagNode *root)
@@ -2205,7 +2205,7 @@ d2r_push_scope(Arena *arena, RDIM_ScopeChunkList *scopes, U64 scope_chunk_cap, D
}
internal RDIM_Type **
d2r_collect_proc_params(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_TagNode *cur_node, U64 *param_count_out)
d2r_collect_proc_params(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_TagNode *cur_node, U64 *param_count_out)
{
Temp scratch = scratch_begin(&arena, 1);
@@ -2238,7 +2238,7 @@ d2r_collect_proc_params(Arena *arena, D2R_TypeTable *type_table, DW_Input *input
}
internal Rng1U64List
d2r_range_list_from_tag(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 image_base, DW_Tag tag)
d2r_range_list_from_tag(Arena *arena, DW_Raw *input, DW_CompUnit *cu, U64 image_base, DW_Tag tag)
{
// collect non-contiguous range
Rng1U64List raw_ranges = dw_rnglist_from_tag_attrib_kind(arena, input, cu, tag, DW_AttribKind_Ranges);
@@ -2296,7 +2296,7 @@ d2r_range_list_from_tag(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 imag
internal void
d2r_convert_symbols(Arena *arena,
D2R_TypeTable *type_table,
DW_Input *input,
DW_Raw *input,
DW_CompUnit *cu,
DW_Language cu_lang,
U64 image_base,
@@ -2620,7 +2620,7 @@ d2r_sort_ptrs(void **ptrs, U64 count, int (* is_before)(void *a, void *b))
}
internal D2R_CompUnitContribMap
d2r_cu_contrib_map_from_aranges(Arena *arena, DW_Input *input, U64 image_base)
d2r_cu_contrib_map_from_aranges(Arena *arena, DW_Raw *input, U64 image_base)
{
Temp scratch = scratch_begin(&arena, 1);
Temp temp = temp_begin(arena);
@@ -2726,7 +2726,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
Arch arch = Arch_Null;
U64 image_base = 0;
DW_Input input = {0};
DW_Raw input = {0};
PathStyle path_style = PathStyle_Null;
switch (params->exe_kind) {
+13 -13
View File
@@ -207,11 +207,11 @@ internal void d2r_push_relational_op(Arena *arena, D2R_ValueTypeStack *
////////////////////////////////
//~ Expression Conversion
internal RDIM_EvalBytecode d2r_bytecode_from_expression(Arena *arena, DW_Input *input, U64 image_base, Arch arch, DW_ListUnit *addr_lu, String8 expr, DW_CompUnit *cu, D2R_ValueType *result_type_out);
internal RDIM_Location d2r_transpile_expression (Arena *arena, DW_Input *input, U64 image_base, Arch arch, DW_ListUnit *addr_lu, DW_CompUnit *cu, String8 expr);
internal RDIM_Location d2r_location_from_attrib (Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag, DW_AttribKind kind);
internal RDIM_LocationCaseList d2r_locset_from_attrib (Arena *arena, RDIM_ScopeChunkList *scopes, RDIM_Scope *curr_scope, DW_Input *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag, DW_AttribKind kind);
internal RDIM_LocationCaseList d2r_var_locset_from_tag (Arena *arena, RDIM_ScopeChunkList *scopes, RDIM_Scope *curr_scope, DW_Input *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag);
internal RDIM_EvalBytecode d2r_bytecode_from_expression(Arena *arena, DW_Raw *input, U64 image_base, Arch arch, DW_ListUnit *addr_lu, String8 expr, DW_CompUnit *cu, D2R_ValueType *result_type_out);
internal RDIM_Location d2r_transpile_expression (Arena *arena, DW_Raw *input, U64 image_base, Arch arch, DW_ListUnit *addr_lu, DW_CompUnit *cu, String8 expr);
internal RDIM_Location d2r_location_from_attrib (Arena *arena, DW_Raw *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag, DW_AttribKind kind);
internal RDIM_LocationCaseList d2r_locset_from_attrib (Arena *arena, RDIM_ScopeChunkList *scopes, RDIM_Scope *curr_scope, DW_Raw *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag, DW_AttribKind kind);
internal RDIM_LocationCaseList d2r_var_locset_from_tag (Arena *arena, RDIM_ScopeChunkList *scopes, RDIM_Scope *curr_scope, DW_Raw *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag);
////////////////////////////////
//~ Type Table
@@ -219,7 +219,7 @@ internal RDIM_LocationCaseList d2r_var_locset_from_tag (Arena *arena, RDIM_S
internal RDIM_Type * d2r_create_type (Arena *arena, D2R_TypeTable *type_table);
internal RDIM_Type * d2r_create_type_from_offset(Arena *arena, D2R_TypeTable *type_table, U64 info_off);
internal RDIM_Type * d2r_type_from_offset(D2R_TypeTable *type_table, U64 info_off);
internal RDIM_Type * d2r_type_from_attrib(D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal RDIM_Type * d2r_type_from_attrib(D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
////////////////////////////////
//~ Tag Iterator
@@ -235,8 +235,8 @@ internal DW_Tag d2r_tag_iterator_parent_tag (D2R_TagIterator *ite
internal void d2r_flag_converted_tag(DW_TagNode *tag_node);
internal B8 d2r_is_tag_converted (DW_TagNode *tag_node);
internal RDIM_Type * d2r_find_or_convert_type(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, Arch arch, DW_Tag tag, DW_AttribKind kind);
internal void d2r_convert_types(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, Arch arch, DW_TagNode *root);
internal RDIM_Type * d2r_find_or_convert_type(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Language cu_lang, Arch arch, DW_Tag tag, DW_AttribKind kind);
internal void d2r_convert_types(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Language cu_lang, Arch arch, DW_TagNode *root);
////////////////////////////////
//~ UDT Conversion
@@ -244,15 +244,15 @@ internal void d2r_convert_types(Arena *arena, D2R_TypeTable *type_table,
internal B8 d2r_is_udt_tag_converted (DW_TagNode *tag_node);
internal void d2r_flag_converted_udt_tag(DW_TagNode *tag_node);
internal void d2r_inline_anonymous_udt_member(Arena *arena, RDIM_UDT *top_udt, U64 base_off, RDIM_UDT *udt);
internal void d2r_convert_udts(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, DW_TagNode *root);
internal void d2r_convert_udts(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Language cu_lang, DW_TagNode *root);
////////////////////////////////
//~ Symbol Conversion
internal RDIM_Scope * d2r_push_scope (Arena *arena, RDIM_ScopeChunkList *scopes, U64 scope_chunk_cap, D2R_TagFrame *tag_stack, Rng1U64List ranges);
internal RDIM_Type ** d2r_collect_proc_params(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_TagNode *cur_node, U64 *param_count_out);
internal Rng1U64List d2r_range_list_from_tag(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 image_base, DW_Tag tag);
internal void d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 image_base, Arch arch, DW_TagNode *root, RDIM_Unit *unit_rdi);
internal RDIM_Type ** d2r_collect_proc_params(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_TagNode *cur_node, U64 *param_count_out);
internal Rng1U64List d2r_range_list_from_tag(Arena *arena, DW_Raw *input, DW_CompUnit *cu, U64 image_base, DW_Tag tag);
internal void d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Language cu_lang, U64 image_base, Arch arch, DW_TagNode *root, RDIM_Unit *unit_rdi);
////////////////////////////////
//~ Line Table Conversion
@@ -263,7 +263,7 @@ internal void d2r_sort_ptrs(void **ptrs, U64 count, int (* is_before)(void *a, v
////////////////////////////////
//~ Contrib Map
internal D2R_CompUnitContribMap d2r_cu_contrib_map_from_aranges(Arena *arena, DW_Input *input, U64 image_base);
internal D2R_CompUnitContribMap d2r_cu_contrib_map_from_aranges(Arena *arena, DW_Raw *input, U64 image_base);
internal RDIM_Rng1U64ChunkList d2r_voff_ranges_from_cu_info_off(D2R_CompUnitContribMap map, U64 info_off);
////////////////////////////////
+173 -3
View File
@@ -299,9 +299,19 @@ d2r2_convert(Arena *arena, D2R2_ConvertParams *params)
lane_sync();
////////////////////////////
//- rjf: parse each unit's line table
//- rjf: parse each unit's line table header
//
DW2_LineTableHeader *unit_line_table_headers = 0;
U64 *unit_line_table_header_sizes = 0;
ProfScope("parse each unit's line table header")
{
if(lane_idx() == 0)
{
unit_line_table_headers = push_array(scratch.arena, DW2_LineTableHeader, unit_count);
unit_line_table_header_sizes = push_array(scratch.arena, U64, unit_count);
}
lane_sync_u64(&unit_line_table_headers, 0);
lane_sync_u64(&unit_line_table_header_sizes, 0);
U64 unit_take_idx = 0;
U64 *unit_take_idx_ptr = &unit_take_idx;
lane_sync_u64(&unit_take_idx_ptr, 0);
@@ -316,13 +326,173 @@ d2r2_convert(Arena *arena, D2R2_ConvertParams *params)
DW2_Tag *unit_root_tag = &unit_root_tags[unit_idx];
DW2_Attrib *stmt_list = dw2_attrib_from_kind(unit_root_tag, DW_AttribKind_StmtList);
U64 line_info_off = stmt_list->val.u128.u64[0];
DW2_LineTableHeader line_table_header = {0};
String8 line_info_data = raw->sec[DW_Section_Line].data;
dw2_read_line_table_header(scratch.arena, ctx, line_info_data, line_info_off, &line_table_header);
unit_line_table_header_sizes[unit_idx] = dw2_read_line_table_header(scratch.arena, ctx, line_info_data, line_info_off, &unit_line_table_headers[unit_idx]);
}
}
lane_sync();
////////////////////////////
//- rjf: deduplicate all source files
//
typedef struct UnitSrcFileMap UnitSrcFileMap;
struct UnitSrcFileMap
{
RDIM_SrcFile **v;
};
RDIM_SrcFileChunkList *all_src_files = 0;
UnitSrcFileMap *unit_src_file_maps = 0;
ProfScope("deduplicate all source files") if(lane_idx() == 0)
{
Temp scratch2 = scratch_begin(&scratch.arena, 1);
//- rjf: count all files in all units
U64 total_file_count = 0;
for EachIndex(unit_idx, unit_count)
{
total_file_count += unit_line_table_headers[unit_idx].files.count;
}
//- rjf: set up path -> src file map
typedef struct SrcFileNode SrcFileNode;
struct SrcFileNode
{
SrcFileNode *next;
String8 full_path;
RDIM_SrcFile *src_file;
};
all_src_files = push_array(scratch.arena, RDIM_SrcFileChunkList, 1);
U64 slots_count = 1 + (total_file_count * 3) / 4;
SrcFileNode **slots = push_array(scratch2.arena, SrcFileNode *, slots_count);
//- rjf: set up unit -> src file maps
unit_src_file_maps = push_array(scratch.arena, UnitSrcFileMap, unit_count);
for EachIndex(unit_idx, unit_count)
{
unit_src_file_maps[unit_idx].v = push_array(scratch.arena, RDIM_SrcFile *, unit_line_table_headers[unit_idx].files.count);
}
//- rjf: build path -> src file map
for EachIndex(unit_idx, unit_count)
{
DW2_LineTableHeader *hdr = &unit_line_table_headers[unit_idx];
for EachIndex(file_idx, hdr->files.count)
{
DW2_LineTableFile *f = &hdr->files.v[file_idx];
DW2_LineTableFile *dir = &hdr->dirs.v[f->dir_idx];
String8 full_file_path = str8f(scratch2.arena, "%S/%S", dir->file_name, f->file_name);
U64 hash = u64_hash_from_str8(full_file_path);
U64 slot_idx = hash%slots_count;
SrcFileNode *node = 0;
for(SrcFileNode *n = slots[slot_idx]; n != 0; n = n->next)
{
if(str8_match(n->full_path, full_file_path, 0))
{
node = n;
break;
}
}
if(!node)
{
node = push_array(scratch2.arena, SrcFileNode, 1);
node->full_path = full_file_path;
node->src_file = rdim_src_file_chunk_list_push(arena, all_src_files, slots_count);
node->src_file->path = str8_copy(arena, full_file_path);
if(f->flags & DW2_LineTableFileFlag_HasMD5)
{
node->src_file->checksum_kind = RDI_ChecksumKind_MD5;
node->src_file->checksum = str8_copy(arena, str8_struct(&f->md5));
}
else if(f->flags & DW2_LineTableFileFlag_HasModifyTime)
{
node->src_file->checksum_kind = RDI_ChecksumKind_Timestamp;
node->src_file->checksum = str8_copy(arena, str8_struct(&f->modify_time));
}
}
unit_src_file_maps[unit_idx].v[file_idx] = node->src_file;
}
}
scratch_end(scratch2);
}
lane_sync_u64(&all_src_files, 0);
////////////////////////////
//- rjf: parse each unit's line info; produce line tables
//
RDIM_LineTableChunkList *all_line_tables = 0;
RDIM_LineTable **unit_line_tables = 0;
ProfScope("parse each unit's line info; produce line tables")
{
//- rjf: prep all per-unit line tables
if(lane_idx() == 0)
{
all_line_tables = push_array(scratch.arena, RDIM_LineTableChunkList, 1);
unit_line_tables = push_array(scratch.arena, RDIM_LineTable *, unit_count);
for EachIndex(unit_idx, unit_count)
{
unit_line_tables[unit_idx] = rdim_line_table_chunk_list_push(arena, all_line_tables, unit_count);
}
}
lane_sync_u64(&all_line_tables, 0);
lane_sync_u64(&unit_line_tables, 0);
U64 unit_take_idx = 0;
U64 *unit_take_idx_ptr = &unit_take_idx;
lane_sync_u64(&unit_take_idx_ptr, 0);
for(;;)
{
//- rjf: take unit
U64 unit_idx = ins_atomic_u64_inc_eval(unit_take_idx_ptr) - 1;
if(unit_idx >= unit_count)
{
break;
}
//- rjf: unpack unit info
DW2_LineTableHeader *line_table_header = &unit_line_table_headers[unit_idx];
RDIM_LineTable *dst_line_table = unit_line_tables[unit_idx];
DW2_Tag *unit_root_tag = &unit_root_tags[unit_idx];
DW2_Attrib *stmt_list = dw2_attrib_from_kind(unit_root_tag, DW_AttribKind_StmtList);
U64 line_info_off = stmt_list->val.u128.u64[0];
String8 all_line_info_data = raw->sec[DW_Section_Line].data;
String8 unit_line_table_data = str8_substr(all_line_info_data, r1u64(line_info_off + unit_line_table_header_sizes[unit_idx], line_info_off + line_table_header->unit_length));
//- rjf: set up vm registers
DW2_LineVMRegs vm_regs = {0};
{
vm_regs.file_index = 1;
vm_regs.line = 1;
vm_regs.is_stmt = line_table_header->default_is_stmt;
}
//- rjf: run the line opcode program
for(U64 off = 0, next_off = 0; off < unit_line_table_data.size; off = next_off)
{
next_off = unit_line_table_data.size;
//- rjf: read next opcode
U8 opcode = 0;
str8_deserial_read_struct(unit_line_table_data, off, &opcode);
//- rjf: apply "special opcodes" (DWARF v5 6.2.5.1)
if(opcode >= line_table_header->opcode_base)
{
U32 adjusted_opcode = (U32)(opcode - line_table_header->opcode_base);
U32 op_advance = adjusted_opcode / line_table_header->line_range;
S64 line_advance = (S64)line_table_header->line_base + (S64)adjusted_opcode%(S64)line_table_header->line_range;
U64 addr_advance = line_table_header->min_inst_length + (vm_regs.vliw_op_index + op_advance) / line_table_header->max_ops_per_inst;
vm_regs.address += addr_advance;
vm_regs.vliw_op_index = (vm_regs.vliw_op_index + op_advance) % line_table_header->max_ops_per_inst;
vm_regs.line += line_advance;
vm_regs.basic_block = 0;
vm_regs.prologue_end = 0;
vm_regs.epilogue_begin = 0;
vm_regs.discriminator = 0;
}
}
}
}
////////////////////////////
//- rjf: fill result
//
+1
View File
@@ -16,6 +16,7 @@ struct D2R2_ConvertParams
U64 base_vaddr;
RDIM_BinarySectionList binary_sections;
DW_Raw raw;
PathStyle path_style;
RDIM_SubsetFlags subset_flags;
B32 deterministic;
};