From eff693244b34eb77cdf325097e5850b1e91599cc Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Wed, 11 Mar 2026 12:04:29 -0700 Subject: [PATCH] sketch out first part of new unified symbol table baking pass, sketch out new simplified sections --- src/lib_rdi/rdi.c | 15 +- src/lib_rdi/rdi.h | 120 +++++++++----- src/lib_rdi_make/rdi_make.h | 4 +- src/rdi/rdi.mdesk | 120 ++++++++++---- src/rdi_from_dwarf/rdi_from_dwarf.c | 238 ++++++++++++++-------------- src/rdi_from_pdb/rdi_from_pdb.c | 22 +-- src/rdi_make/rdi_make_local.c | 78 ++++++++- 7 files changed, 385 insertions(+), 212 deletions(-) diff --git a/src/lib_rdi/rdi.c b/src/lib_rdi/rdi.c index 8ae9131e..5a777206 100644 --- a/src/lib_rdi/rdi.c +++ b/src/lib_rdi/rdi.c @@ -10,7 +10,7 @@ #ifndef RDI_C #define RDI_C -RDI_U16 rdi_section_element_size_table[53] = +RDI_U16 rdi_section_element_size_table[58] = { sizeof(RDI_U8), sizeof(RDI_TopLevelInfo), @@ -36,20 +36,25 @@ sizeof(RDI_UDT), sizeof(RDI_Member), sizeof(RDI_EnumMember), sizeof(RDI_GlobalVariable), -sizeof(RDI_VMapEntry), sizeof(RDI_ThreadVariable), sizeof(RDI_Constant), sizeof(RDI_Procedure), +sizeof(RDI_Local), +sizeof(RDI_VMapEntry), sizeof(RDI_Scope), sizeof(RDI_U64), sizeof(RDI_VMapEntry), sizeof(RDI_InlineSite), -sizeof(RDI_Local), sizeof(RDI_LocationBlock), sizeof(RDI_U8), +sizeof(RDI_Symbol), +sizeof(RDI_Symbol), +sizeof(RDI_Symbol), +sizeof(RDI_Symbol), +sizeof(RDI_Symbol), sizeof(RDI_U8), -sizeof(RDI_LocationRegPlusU16), -sizeof(RDI_LocationReg), +sizeof(RDI_RegAndOffsetU16), +sizeof(RDI_RegCode), sizeof(RDI_U64), sizeof(RDI_U32), sizeof(RDI_U64), diff --git a/src/lib_rdi/rdi.h b/src/lib_rdi/rdi.h index 91d02591..eeab41d9 100644 --- a/src/lib_rdi/rdi.h +++ b/src/lib_rdi/rdi.h @@ -99,35 +99,40 @@ RDI_SectionKind_UDTs = 0x0014, RDI_SectionKind_Members = 0x0015, RDI_SectionKind_EnumMembers = 0x0016, RDI_SectionKind_GlobalVariables = 0x0017, -RDI_SectionKind_GlobalVMap = 0x0018, -RDI_SectionKind_ThreadVariables = 0x0019, -RDI_SectionKind_Constants = 0x001A, -RDI_SectionKind_Procedures = 0x001B, -RDI_SectionKind_Scopes = 0x001C, -RDI_SectionKind_ScopeVOffData = 0x001D, -RDI_SectionKind_ScopeVMap = 0x001E, -RDI_SectionKind_InlineSites = 0x001F, -RDI_SectionKind_Locals = 0x0020, +RDI_SectionKind_ThreadVariables = 0x0018, +RDI_SectionKind_Constants = 0x0019, +RDI_SectionKind_Procedures = 0x001A, +RDI_SectionKind_Locals = 0x001B, +RDI_SectionKind_GlobalVMap = 0x001C, +RDI_SectionKind_Scopes = 0x001D, +RDI_SectionKind_ScopeVOffData = 0x001E, +RDI_SectionKind_ScopeVMap = 0x001F, +RDI_SectionKind_InlineSites = 0x0020, RDI_SectionKind_LocationBlocks = 0x0021, RDI_SectionKind_LocationData = 0x0022, -RDI_SectionKind_LocationsBytecodeData = 0x0023, -RDI_SectionKind_LocationsRegPlusU16 = 0x0024, -RDI_SectionKind_LocationsReg = 0x0025, -RDI_SectionKind_LocationsModuleOff = 0x0026, -RDI_SectionKind_LocationsTLSOff = 0x0027, -RDI_SectionKind_LocationsConstantDataOff = 0x0028, -RDI_SectionKind_LocationsSet = 0x0029, -RDI_SectionKind_LocationsSetElements = 0x002A, -RDI_SectionKind_ConstantValueData = 0x002B, -RDI_SectionKind_ConstantValueTable = 0x002C, -RDI_SectionKind_MD5Checksums = 0x002D, -RDI_SectionKind_SHA1Checksums = 0x002E, -RDI_SectionKind_SHA256Checksums = 0x002F, -RDI_SectionKind_Timestamps = 0x0030, -RDI_SectionKind_NameMaps = 0x0031, -RDI_SectionKind_NameMapBuckets = 0x0032, -RDI_SectionKind_NameMapNodes = 0x0033, -RDI_SectionKind_COUNT = 0x0034, +RDI_SectionKind_GlobalVariableSymbols = 0x0023, +RDI_SectionKind_ThreadVariableSymbols = 0x0024, +RDI_SectionKind_ConstantSymbols = 0x0025, +RDI_SectionKind_ProcedureSymbols = 0x0026, +RDI_SectionKind_LocalSymbols = 0x0027, +RDI_SectionKind_LocationsBytecodeData = 0x0028, +RDI_SectionKind_LocationsRegPlusU16 = 0x0029, +RDI_SectionKind_LocationsReg = 0x002A, +RDI_SectionKind_LocationsModuleOff = 0x002B, +RDI_SectionKind_LocationsTLSOff = 0x002C, +RDI_SectionKind_LocationsConstantDataOff = 0x002D, +RDI_SectionKind_LocationsSet = 0x002E, +RDI_SectionKind_LocationsSetElements = 0x002F, +RDI_SectionKind_ConstantValueData = 0x0030, +RDI_SectionKind_ConstantValueTable = 0x0031, +RDI_SectionKind_MD5Checksums = 0x0032, +RDI_SectionKind_SHA1Checksums = 0x0033, +RDI_SectionKind_SHA256Checksums = 0x0034, +RDI_SectionKind_Timestamps = 0x0035, +RDI_SectionKind_NameMaps = 0x0036, +RDI_SectionKind_NameMapBuckets = 0x0037, +RDI_SectionKind_NameMapNodes = 0x0038, +RDI_SectionKind_COUNT = 0x0039, } RDI_SectionKindEnum; typedef RDI_U32 RDI_SectionEncoding; @@ -564,20 +569,25 @@ X(UDTs, udts, RDI_UDT)\ X(Members, members, RDI_Member)\ X(EnumMembers, enum_members, RDI_EnumMember)\ X(GlobalVariables, global_variables, RDI_GlobalVariable)\ -X(GlobalVMap, global_vmap, RDI_VMapEntry)\ X(ThreadVariables, thread_variables, RDI_ThreadVariable)\ X(Constants, constants, RDI_Constant)\ X(Procedures, procedures, RDI_Procedure)\ +X(Locals, locals, RDI_Local)\ +X(GlobalVMap, global_vmap, RDI_VMapEntry)\ X(Scopes, scopes, RDI_Scope)\ X(ScopeVOffData, scope_voff_data, RDI_U64)\ X(ScopeVMap, scope_vmap, RDI_VMapEntry)\ X(InlineSites, inline_sites, RDI_InlineSite)\ -X(Locals, locals, RDI_Local)\ X(LocationBlocks, location_blocks, RDI_LocationBlock)\ X(LocationData, location_data, RDI_U8)\ +X(GlobalVariableSymbols, global_variable_symbols, RDI_Symbol)\ +X(ThreadVariableSymbols, thread_variable_symbols, RDI_Symbol)\ +X(ConstantSymbols, constant_symbols, RDI_Symbol)\ +X(ProcedureSymbols, procedure_symbols, RDI_Symbol)\ +X(LocalSymbols, local_symbols, RDI_Symbol)\ X(LocationsBytecodeData, locations_bytecode_data, RDI_U8)\ -X(LocationsRegPlusU16, locations_reg_plus_u16, RDI_LocationRegPlusU16)\ -X(LocationsReg, locations_reg, RDI_LocationReg)\ +X(LocationsRegPlusU16, locations_reg_plus_u16, RDI_RegAndOffsetU16)\ +X(LocationsReg, locations_reg, RDI_RegCode)\ X(LocationsModuleOff, locations_module_off, RDI_U64)\ X(LocationsTLSOff, locations_tls_off, RDI_U32)\ X(LocationsConstantDataOff, locations_constant_data_off, RDI_U64)\ @@ -1006,13 +1016,21 @@ X(RDI_U16, offset)\ X(RDI_LocationKind, kind)\ X(RDI_RegCode, reg_code)\ +#define RDI_RegAndOffsetU16_XList \ +X(RDI_RegCode, reg_code)\ +X(RDI_U16, offset)\ + #define RDI_LocationSet_XList \ X(RDI_U32, set_element_idx_first)\ X(RDI_U32, set_element_idx_opl)\ #define RDI_LocationSetElement_XList \ X(RDI_LocationKind, kind)\ +X(RDI_U8, reserved_0)\ +X(RDI_U16, reserved_1)\ X(RDI_U32, idx)\ +X(RDI_U32, scope_off_first)\ +X(RDI_U32, scope_off_opl)\ #define RDI_EvalOp_XList \ X(Stop)\ @@ -1134,12 +1152,17 @@ typedef struct RDI_U32_GlobalVariables { RDI_U32 v; } RDI_U32_Global typedef struct RDI_U32_ThreadVariables { RDI_U32 v; } RDI_U32_ThreadVariables; typedef struct RDI_U32_Constants { RDI_U32 v; } RDI_U32_Constants; typedef struct RDI_U32_Procedures { RDI_U32 v; } RDI_U32_Procedures; +typedef struct RDI_U32_Locals { RDI_U32 v; } RDI_U32_Locals; typedef struct RDI_U32_Scopes { RDI_U32 v; } RDI_U32_Scopes; typedef struct RDI_U32_ScopeVOffData { RDI_U32 v; } RDI_U32_ScopeVOffData; typedef struct RDI_U32_InlineSites { RDI_U32 v; } RDI_U32_InlineSites; -typedef struct RDI_U32_Locals { RDI_U32 v; } RDI_U32_Locals; typedef struct RDI_U32_LocationBlocks { RDI_U32 v; } RDI_U32_LocationBlocks; typedef struct RDI_U32_LocationData { RDI_U32 v; } RDI_U32_LocationData; +typedef struct RDI_U32_GlobalVariableSymbols { RDI_U32 v; } RDI_U32_GlobalVariableSymbols; +typedef struct RDI_U32_ThreadVariableSymbols { RDI_U32 v; } RDI_U32_ThreadVariableSymbols; +typedef struct RDI_U32_ConstantSymbols { RDI_U32 v; } RDI_U32_ConstantSymbols; +typedef struct RDI_U32_ProcedureSymbols { RDI_U32 v; } RDI_U32_ProcedureSymbols; +typedef struct RDI_U32_LocalSymbols { RDI_U32 v; } RDI_U32_LocalSymbols; typedef struct RDI_U32_LocationsBytecodeData { RDI_U32 v; } RDI_U32_LocationsBytecodeData; typedef struct RDI_U32_LocationsRegPlusU16 { RDI_U32 v; } RDI_U32_LocationsRegPlusU16; typedef struct RDI_U32_LocationsReg { RDI_U32 v; } RDI_U32_LocationsReg; @@ -1183,12 +1206,17 @@ typedef RDI_U32_Table RDI_U32_GlobalVariables; typedef RDI_U32_Table RDI_U32_ThreadVariables; typedef RDI_U32_Table RDI_U32_Constants; typedef RDI_U32_Table RDI_U32_Procedures; +typedef RDI_U32_Table RDI_U32_Locals; typedef RDI_U32_Table RDI_U32_Scopes; typedef RDI_U32_Table RDI_U32_ScopeVOffData; typedef RDI_U32_Table RDI_U32_InlineSites; -typedef RDI_U32_Table RDI_U32_Locals; typedef RDI_U32_Table RDI_U32_LocationBlocks; typedef RDI_U32_Table RDI_U32_LocationData; +typedef RDI_U32_Table RDI_U32_GlobalVariableSymbols; +typedef RDI_U32_Table RDI_U32_ThreadVariableSymbols; +typedef RDI_U32_Table RDI_U32_ConstantSymbols; +typedef RDI_U32_Table RDI_U32_ProcedureSymbols; +typedef RDI_U32_Table RDI_U32_LocalSymbols; typedef RDI_U32_Table RDI_U32_LocationsBytecodeData; typedef RDI_U32_Table RDI_U32_LocationsRegPlusU16; typedef RDI_U32_Table RDI_U32_LocationsReg; @@ -1538,6 +1566,13 @@ RDI_LocationKind kind; RDI_RegCode reg_code; }; +typedef struct RDI_RegAndOffsetU16 RDI_RegAndOffsetU16; +struct RDI_RegAndOffsetU16 +{ +RDI_RegCode reg_code; +RDI_U16 offset; +}; + typedef struct RDI_LocationSet RDI_LocationSet; struct RDI_LocationSet { @@ -1549,7 +1584,11 @@ typedef struct RDI_LocationSetElement RDI_LocationSetElement; struct RDI_LocationSetElement { RDI_LocationKind kind; +RDI_U8 reserved_0; +RDI_U16 reserved_1; RDI_U32 idx; +RDI_U32 scope_off_first; +RDI_U32 scope_off_opl; }; typedef struct RDI_NameMap RDI_NameMap; @@ -1599,20 +1638,25 @@ typedef RDI_UDT RDI_SectionElementType_UDTs; typedef RDI_Member RDI_SectionElementType_Members; typedef RDI_EnumMember RDI_SectionElementType_EnumMembers; typedef RDI_GlobalVariable RDI_SectionElementType_GlobalVariables; -typedef RDI_VMapEntry RDI_SectionElementType_GlobalVMap; typedef RDI_ThreadVariable RDI_SectionElementType_ThreadVariables; typedef RDI_Constant RDI_SectionElementType_Constants; typedef RDI_Procedure RDI_SectionElementType_Procedures; +typedef RDI_Local RDI_SectionElementType_Locals; +typedef RDI_VMapEntry RDI_SectionElementType_GlobalVMap; typedef RDI_Scope RDI_SectionElementType_Scopes; typedef RDI_U64 RDI_SectionElementType_ScopeVOffData; typedef RDI_VMapEntry RDI_SectionElementType_ScopeVMap; typedef RDI_InlineSite RDI_SectionElementType_InlineSites; -typedef RDI_Local RDI_SectionElementType_Locals; typedef RDI_LocationBlock RDI_SectionElementType_LocationBlocks; typedef RDI_U8 RDI_SectionElementType_LocationData; +typedef RDI_Symbol RDI_SectionElementType_GlobalVariableSymbols; +typedef RDI_Symbol RDI_SectionElementType_ThreadVariableSymbols; +typedef RDI_Symbol RDI_SectionElementType_ConstantSymbols; +typedef RDI_Symbol RDI_SectionElementType_ProcedureSymbols; +typedef RDI_Symbol RDI_SectionElementType_LocalSymbols; typedef RDI_U8 RDI_SectionElementType_LocationsBytecodeData; -typedef RDI_LocationRegPlusU16 RDI_SectionElementType_LocationsRegPlusU16; -typedef RDI_LocationReg RDI_SectionElementType_LocationsReg; +typedef RDI_RegAndOffsetU16 RDI_SectionElementType_LocationsRegPlusU16; +typedef RDI_RegCode RDI_SectionElementType_LocationsReg; typedef RDI_U64 RDI_SectionElementType_LocationsModuleOff; typedef RDI_U32 RDI_SectionElementType_LocationsTLSOff; typedef RDI_U64 RDI_SectionElementType_LocationsConstantDataOff; @@ -1636,7 +1680,7 @@ RDI_PROC RDI_EvalConversionKind rdi_eval_conversion_kind_from_typegroups(RDI_Eva RDI_PROC RDI_S32 rdi_eval_op_typegroup_are_compatible(RDI_EvalOp op, RDI_EvalTypeGroup group); RDI_PROC RDI_U8 *rdi_explanation_string_from_eval_conversion_kind(RDI_EvalConversionKind kind, RDI_U64 *size_out); -extern RDI_U16 rdi_section_element_size_table[53]; +extern RDI_U16 rdi_section_element_size_table[58]; extern RDI_U16 rdi_eval_op_ctrlbits_table[54]; #endif // RDI_H diff --git a/src/lib_rdi_make/rdi_make.h b/src/lib_rdi_make/rdi_make.h index 6329e602..acd9f510 100644 --- a/src/lib_rdi_make/rdi_make.h +++ b/src/lib_rdi_make/rdi_make.h @@ -737,9 +737,9 @@ struct RDIM_TypeNode typedef struct RDIM_TypeList RDIM_TypeList; struct RDIM_TypeList { - U64 count; RDIM_TypeNode *first; RDIM_TypeNode *last; + U64 count; }; typedef struct RDIM_TypeChunkNode RDIM_TypeChunkNode; @@ -919,7 +919,7 @@ struct RDIM_Symbol RDIM_String8 link_name; RDIM_Type *type; RDI_U64 offset; - RDIM_Symbol *container_symbol; + struct RDIM_Scope *container_scope; RDIM_Type *container_type; struct RDIM_Scope *root_scope; RDIM_LocationCaseList location_cases; diff --git a/src/rdi/rdi.mdesk b/src/rdi/rdi.mdesk index ac9e0fce..d6921efe 100644 --- a/src/rdi/rdi.mdesk +++ b/src/rdi/rdi.mdesk @@ -136,62 +136,99 @@ RDI_HeaderMemberTable: RDI_SectionTable: { {NULL null RDI_U8 0x0000 - ""} + + //- rjf: top-level-info {TopLevelInfo top_level_info RDI_TopLevelInfo 0x0001 - ""} + + //- rjf: strings {StringData string_data RDI_U8 0x0002 - ""} {StringTable string_table RDI_U32 0x0003 U32 ""} + + //- rjf: index runs {IndexRuns index_runs RDI_U32 0x0004 U32 ""} + + //- rjf: binary sections {BinarySections binary_sections RDI_BinarySection 0x0005 U32 ""} + + //- rjf: filesystem / source files {FilePathNodes file_path_nodes RDI_FilePathNode 0x0006 U32 ""} {SourceFiles source_files RDI_SourceFile 0x0007 U32 ""} + + //- rjf: voff -> line info {LineTables line_tables RDI_LineTable 0x0008 U32 ""} {LineInfoVOffs line_info_voffs RDI_U64 0x0009 U32 ""} {LineInfoLines line_info_lines RDI_Line 0x000A U32 ""} {LineInfoColumns line_info_columns RDI_Column 0x000B U32 ""} + + //- rjf: line -> voff info {SourceLineMaps source_line_maps RDI_SourceLineMap 0x000C U32 ""} {SourceLineMapNumbers source_line_map_numbers RDI_U32 0x000D U32 ""} {SourceLineMapRanges source_line_map_ranges RDI_U32 0x000E U32 ""} {SourceLineMapVOffs source_line_map_voffs RDI_U64 0x000F U32 ""} + + //- rjf: units {Units units RDI_Unit 0x0010 U32 ""} {UnitVMap unit_vmap RDI_VMapEntry 0x0011 - ""} + + //- rjf: namespaces {Namespaces namespaces RDI_Namespace 0x0012 U32 ""} + + //- rjf: type info {TypeNodes type_nodes RDI_TypeNode 0x0013 U32 ""} {UDTs udts RDI_UDT 0x0014 U32 ""} {Members members RDI_Member 0x0015 U32 ""} {EnumMembers enum_members RDI_EnumMember 0x0016 U32 ""} + + //- TODO(rjf): vvv old story for symbols {GlobalVariables global_variables RDI_GlobalVariable 0x0017 U32 ""} - {GlobalVMap global_vmap RDI_VMapEntry 0x0018 - ""} - {ThreadVariables thread_variables RDI_ThreadVariable 0x0019 U32 ""} - {Constants constants RDI_Constant 0x001A U32 ""} - {Procedures procedures RDI_Procedure 0x001B U32 ""} - {Scopes scopes RDI_Scope 0x001C U32 ""} - {ScopeVOffData scope_voff_data RDI_U64 0x001D U32 ""} - {ScopeVMap scope_vmap RDI_VMapEntry 0x001E - ""} - {InlineSites inline_sites RDI_InlineSite 0x001F U32 ""} - {Locals locals RDI_Local 0x0020 U32 ""} + {ThreadVariables thread_variables RDI_ThreadVariable 0x0018 U32 ""} + {Constants constants RDI_Constant 0x0019 U32 ""} + {Procedures procedures RDI_Procedure 0x001A U32 ""} + {Locals locals RDI_Local 0x001B U32 ""} + {GlobalVMap global_vmap RDI_VMapEntry 0x001C - ""} + + //- rjf: scope info + {Scopes scopes RDI_Scope 0x001D U32 ""} + {ScopeVOffData scope_voff_data RDI_U64 0x001E U32 ""} + {ScopeVMap scope_vmap RDI_VMapEntry 0x001F - ""} + {InlineSites inline_sites RDI_InlineSite 0x0020 U32 ""} + + //- TODO(rjf): vvv old story for locations {LocationBlocks location_blocks RDI_LocationBlock 0x0021 U32 ""} {LocationData location_data RDI_U8 0x0022 U32 ""} - //- NOTE(rjf): vvv new story for locations - {LocationsBytecodeData locations_bytecode_data RDI_U8 0x0023 U32 ""} - {LocationsRegPlusU16 locations_reg_plus_u16 RDI_LocationRegPlusU16 0x0024 U32 ""} - {LocationsReg locations_reg RDI_LocationReg 0x0025 U32 ""} - {LocationsModuleOff locations_module_off RDI_U64 0x0026 U32 ""} - {LocationsTLSOff locations_tls_off RDI_U32 0x0027 U32 ""} - {LocationsConstantDataOff locations_constant_data_off RDI_U64 0x0028 U32 ""} - {LocationsSet locations_set RDI_LocationSet 0x0029 U32 ""} - {LocationsSetElements locations_set_elements RDI_LocationSetElement 0x002A U32 ""} - //- NOTE(rjf): ^^^ + //- NOTE(rjf): vvv new story for symbols + {GlobalVariableSymbols global_variable_symbols RDI_Symbol 0x0023 U32 ""} + {ThreadVariableSymbols thread_variable_symbols RDI_Symbol 0x0024 U32 ""} + {ConstantSymbols constant_symbols RDI_Symbol 0x0025 U32 ""} + {ProcedureSymbols procedure_symbols RDI_Symbol 0x0026 U32 ""} + {LocalSymbols local_symbols RDI_Symbol 0x0027 U32 ""} - {ConstantValueData constant_value_data RDI_U8 0x002B U32 ""} - {ConstantValueTable constant_value_table RDI_U32 0x002C U32 ""} - {MD5Checksums md5_checksums RDI_MD5 0x002D U32 ""} - {SHA1Checksums sha1_checksums RDI_SHA1 0x002E U32 ""} - {SHA256Checksums sha256_checksums RDI_SHA256 0x002F U32 ""} - {Timestamps timestamps RDI_U64 0x0030 U32 ""} - {NameMaps name_maps RDI_NameMap 0x0031 U32 ""} - {NameMapBuckets name_map_buckets RDI_NameMapBucket 0x0032 U32 ""} - {NameMapNodes name_map_nodes RDI_NameMapNode 0x0033 U32 ""} - {COUNT count RDI_U8 0x0034 - ""} + //- NOTE(rjf): vvv new story for locations + {LocationsBytecodeData locations_bytecode_data RDI_U8 0x0028 U32 ""} + {LocationsRegPlusU16 locations_reg_plus_u16 RDI_RegAndOffsetU16 0x0029 U32 ""} + {LocationsReg locations_reg RDI_RegCode 0x002A U32 ""} + {LocationsModuleOff locations_module_off RDI_U64 0x002B U32 ""} + {LocationsTLSOff locations_tls_off RDI_U32 0x002C U32 ""} + {LocationsConstantDataOff locations_constant_data_off RDI_U64 0x002D U32 ""} + {LocationsSet locations_set RDI_LocationSet 0x002E U32 ""} + {LocationsSetElements locations_set_elements RDI_LocationSetElement 0x002F U32 ""} + + //- TODO(rjf): vvv old story for locations (constants) + {ConstantValueData constant_value_data RDI_U8 0x0030 U32 ""} + {ConstantValueTable constant_value_table RDI_U32 0x0031 U32 ""} + + //- rjf: checksums / timestamps + {MD5Checksums md5_checksums RDI_MD5 0x0032 U32 ""} + {SHA1Checksums sha1_checksums RDI_SHA1 0x0033 U32 ""} + {SHA256Checksums sha256_checksums RDI_SHA256 0x0034 U32 ""} + {Timestamps timestamps RDI_U64 0x0035 U32 ""} + + //- rjf: name maps + {NameMaps name_maps RDI_NameMap 0x0036 U32 ""} + {NameMapBuckets name_map_buckets RDI_NameMapBucket 0x0037 U32 ""} + {NameMapNodes name_map_nodes RDI_NameMapNode 0x0038 U32 ""} + {COUNT count RDI_U8 0x0039 - ""} } @table(name value) @@ -1137,6 +1174,13 @@ RDI_LocationRegMemberTable: {reg_code RDI_RegCode } } +@table(name type desc) +RDI_RegAndOffsetU16MemberTable: +{ + {reg_code RDI_RegCode } + {offset RDI_U16 } +} + @table(name type desc) RDI_LocationSetMemberTable: { @@ -1147,8 +1191,12 @@ RDI_LocationSetMemberTable: @table(name type desc) RDI_LocationSetElementMemberTable: { - {kind RDI_LocationKind ""} - {idx RDI_U32 ""} + {kind RDI_LocationKind ""} + {reserved_0 RDI_U8 ""} + {reserved_1 RDI_U16 ""} + {idx RDI_U32 ""} + {scope_off_first RDI_U32 ""} + {scope_off_opl RDI_U32 ""} } //- rjf: enums @@ -1260,6 +1308,11 @@ RDI_LocationSetElementMemberTable: @expand(RDI_LocationRegMemberTable a) `$(a.type), $(a.name)` } +@xlist RDI_RegAndOffsetU16_XList: +{ + @expand(RDI_RegAndOffsetU16MemberTable a) `$(a.type), $(a.name)` +} + @xlist RDI_LocationSet_XList: { @expand(RDI_LocationSetMemberTable a) `$(a.type), $(a.name)` @@ -1337,6 +1390,11 @@ RDI_LocationSetElementMemberTable: @expand(RDI_LocationRegMemberTable a) `$(a.type) $(a.name)` } +@struct RDI_RegAndOffsetU16: +{ + @expand(RDI_RegAndOffsetU16MemberTable a) `$(a.type) $(a.name)` +} + @struct RDI_LocationSet: { @expand(RDI_LocationSetMemberTable a) `$(a.type) $(a.name)` diff --git a/src/rdi_from_dwarf/rdi_from_dwarf.c b/src/rdi_from_dwarf/rdi_from_dwarf.c index 1919a722..6ca1235e 100644 --- a/src/rdi_from_dwarf/rdi_from_dwarf.c +++ b/src/rdi_from_dwarf/rdi_from_dwarf.c @@ -395,7 +395,7 @@ rdim_static_eval_bytecode_to_voff(RDIM_EvalBytecode bc, U64 image_base, U64 *vof } is_ok = 1; -exit:; + exit:; scratch_end(scratch); return is_ok; } @@ -563,13 +563,13 @@ d2r_size_from_value_type(U64 addr_size, D2R_ValueType value_type) if (value_type == D2R_ValueType_Address) { return addr_size; } - + switch (value_type) { #define X(_N, _AT, _S) case D2R_ValueType_##_N: return _S; D2R_ValueType_XList #undef X } - + return 0; } @@ -642,19 +642,19 @@ d2r_value_type_to_rdi(D2R_ValueType v) if (v == D2R_ValueType_Generic) { return RDI_EvalTypeGroup_Other; } - + if (v == D2R_ValueType_Address) { return RDI_EvalTypeGroup_U; } - + if (d2r_is_value_type_unsigned(v)) { return RDI_EvalTypeGroup_U; } - + if (d2r_is_value_type_signed(v)) { return RDI_EvalTypeGroup_S; } - + if (d2r_is_value_type_float(v)) { if (v == D2R_ValueType_F16) { NotImplemented; } else if (v == D2R_ValueType_F32) { return RDI_EvalTypeGroup_F32; } @@ -665,7 +665,7 @@ d2r_value_type_to_rdi(D2R_ValueType v) else if (v == D2R_ValueType_F128) { return RDI_EvalTypeGroup_F128; } else { InvalidPath; } } - + InvalidPath; return RDI_EvalTypeGroup_Other; } @@ -728,7 +728,7 @@ d2r_bytecode_from_expression(Arena *arena, Temp scratch = scratch_begin(&arena, 1); Temp temp = temp_begin(arena); B32 is_ok = 0; - + RDIM_EvalBytecode bc = {0}; DW_Expr expr = dw_expr_from_data(scratch.arena, cu->format, cu->address_size, raw_expr); @@ -805,7 +805,7 @@ d2r_bytecode_from_expression(Arena *arena, Assert(!"invalid address"); goto exit; } - + U64 voff = inst->operands[0].u64 - image_base; rdim_bytecode_push_op(arena, &bc, RDI_EvalOp_ModuleOff, voff); d2r_value_type_stack_push(scratch.arena, stack, D2R_ValueType_Address); @@ -914,7 +914,7 @@ d2r_bytecode_from_expression(Arena *arena, cursor += i->size; inst_count += 1; } - + if (cursor != delta) { Assert(!"skip landed in middle of an instruction"); goto exit; } if (inst_count > min_S16) { Assert(!"operand overflow"); goto exit; } if (inst_idx > max_U32) { Assert(!"index overflow"); goto exit; } @@ -931,11 +931,11 @@ d2r_bytecode_from_expression(Arena *arena, cursor += i->size; inst_count += 1; } - + if (cursor != delta) { Assert(!"cond landed in middle of an instruction"); goto exit; } if (inst_count > min_S16) { Assert(!"operand overflow"); goto exit; } if (inst_idx > max_U32) { Assert(!"index overflow"); goto exit; } - + U64 imm = Compose64Bit(inst_idx, skip_fwd ? inst_count : (U16)(-(S16)inst_count)); rdim_bytecode_push_op(arena, &bc, RDI_EvalOp_Cond, imm); } break; @@ -1042,38 +1042,38 @@ d2r_bytecode_from_expression(Arena *arena, Assert(!"invalid .debug_info offset"); goto exit; } - + DW_Tag tag = tag_node->tag; if (tag.kind == DW_TagKind_BaseType) { // extract encoding attribute DW_ATE encoding = dw_const_u64_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Encoding); - + // DW_ATE -> RDI_EvalTypeGroup switch (encoding) { - case DW_ATE_Null: { - out = D2R_ValueType_Generic; - } break; - case DW_ATE_Address: { - out = D2R_ValueType_Address; - } break; - case DW_ATE_Boolean: { - out = D2R_ValueType_S8; - } break; - case DW_ATE_SignedChar: - case DW_ATE_Signed: { - U64 byte_size = dw_const_u64_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_ByteSize); - out = d2r_signed_value_type_from_bit_size(byte_size * 8); - } break; - case DW_ATE_UnsignedChar: - case DW_ATE_Unsigned: { - U64 byte_size = dw_const_u64_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_ByteSize); - out = d2r_unsigned_value_type_from_bit_size(byte_size * 8); - } break; - case DW_ATE_Float: { - U64 byte_size = dw_const_u64_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_ByteSize); - out = d2r_float_type_from_bit_size(byte_size * 8); - } break; - default: InvalidPath; break; + case DW_ATE_Null: { + out = D2R_ValueType_Generic; + } break; + case DW_ATE_Address: { + out = D2R_ValueType_Address; + } break; + case DW_ATE_Boolean: { + out = D2R_ValueType_S8; + } break; + case DW_ATE_SignedChar: + case DW_ATE_Signed: { + U64 byte_size = dw_const_u64_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_ByteSize); + out = d2r_signed_value_type_from_bit_size(byte_size * 8); + } break; + case DW_ATE_UnsignedChar: + case DW_ATE_Unsigned: { + U64 byte_size = dw_const_u64_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_ByteSize); + out = d2r_unsigned_value_type_from_bit_size(byte_size * 8); + } break; + case DW_ATE_Float: { + U64 byte_size = dw_const_u64_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_ByteSize); + out = d2r_float_type_from_bit_size(byte_size * 8); + } break; + default: InvalidPath; break; } } else { Assert(!"unexpected tag"); @@ -1300,9 +1300,9 @@ d2r_bytecode_from_expression(Arena *arena, if (result_type_out) { *result_type_out = d2r_value_type_stack_peek(stack); } - + is_ok = 1; -exit:; + exit:; if (!is_ok) { MemoryZeroStruct(&bc); temp_end(temp); @@ -1584,13 +1584,13 @@ d2r_find_or_convert_type(Arena *arena, D2R_TypeTable *type_table, DW_Input *inpu if (ref.cu == cu) { // find type type = d2r_type_from_offset(type_table, ref.info_off); - + // was type converted? if (type == 0) { // issue type conversion DW_TagNode *ref_node = dw_tag_node_from_info_off(cu, ref.info_off); d2r_convert_types(arena, type_table, input, cu, cu_lang, arch, ref_node); - + // if we do not have a converted type at this point then debug info is malformed type = d2r_type_from_offset(type_table, ref.info_off); if (type == 0) { @@ -1726,7 +1726,7 @@ d2r_convert_types(Arena *arena, log_user_errorf("unexpected tag @ .debug_info+%llx", tag.info_off); } } - + DW_TagNode *parent = d2r_tag_iterator_parent_tag_node(it); B32 is_method = parent->tag.kind == DW_TagKind_StructureType || parent->tag.kind == DW_TagKind_ClassType; @@ -1759,7 +1759,7 @@ d2r_convert_types(Arena *arena, // convert base type encoding to RDI version RDI_TypeKind kind = RDI_TypeKind_NULL; - #define X(t,g,s) case s: kind = RDI_TypeKind_##t; break; +#define X(t,g,s) case s: kind = RDI_TypeKind_##t; break; switch (encoding) { case DW_ATE_Null: kind = RDI_TypeKind_NULL; break; case DW_ATE_Address: kind = RDI_TypeKind_Void; break; @@ -1787,19 +1787,19 @@ d2r_convert_types(Arena *arena, } if (kind != RDI_TypeKind_NULL) { break; } } - + switch (byte_size) { D2R_ValueType_Float_XList - default: log_user_errorf("unexpected size"); break; + default: log_user_errorf("unexpected size"); break; } } break; case DW_ATE_Signed: { String8 name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Name); if (str8_match(name, str8_lit("wchar_t"), 0)) { goto do_signed_char; } - + switch (byte_size) { D2R_ValueType_Signed_XList - default: log_user_errorf("unexpected size"); break; + default: log_user_errorf("unexpected size"); break; } } break; do_signed_char:; @@ -1814,7 +1814,7 @@ d2r_convert_types(Arena *arena, case DW_ATE_Unsigned: { switch (byte_size) { D2R_ValueType_Unsigned_XList - default: log_user_errorf("unexpected size"); break; + default: log_user_errorf("unexpected size"); break; } } break; case DW_ATE_Utf: @@ -1828,10 +1828,10 @@ d2r_convert_types(Arena *arena, } break; case DW_ATE_DecimalFloat: { switch (byte_size) { - case 4: kind = RDI_TypeKind_Decimal32; break; - case 8: kind = RDI_TypeKind_Decimal64; break; - case 16: kind = RDI_TypeKind_Decimal128; break; - default: log_user_errorf("unexpected size"); break; + case 4: kind = RDI_TypeKind_Decimal32; break; + case 8: kind = RDI_TypeKind_Decimal64; break; + case 16: kind = RDI_TypeKind_Decimal128; break; + default: log_user_errorf("unexpected size"); break; } } break; case DW_ATE_ImaginaryFloat: { @@ -1860,7 +1860,7 @@ d2r_convert_types(Arena *arena, } break; default: log_user_errorf("unexpected base type encoding"); break; } - #undef X +#undef X RDIM_Type *type = d2r_create_type_from_offset(arena, type_table, tag.info_off); type->kind = RDI_TypeKind_Alias; @@ -1946,9 +1946,9 @@ d2r_convert_types(Arena *arena, // and convert to U256, U512, S256 and S512 B32 is_vector = dw_flag_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_GNU_Vector); if (is_vector) { NotImplemented; } - + B32 error = 1; - + // * DWARF vs RDI Array Type Graph * // // For example lets take following decl: @@ -2035,13 +2035,13 @@ d2r_convert_types(Arena *arena, error = 0; array_type_exit:; - + // in case of an error, assign null to the array type if (error) { Assert(d2r_type_from_offset(type_table, tag.info_off) == 0); // this should the first time this type is being parsed hash_table_push_u64_raw(arena, type_table->ht, tag.info_off, type_table->builtin_types[RDI_TypeKind_NULL]); } - + d2r_tag_iterator_skip_children(it); } break; case DW_TagKind_SubrangeType: { @@ -2101,18 +2101,18 @@ d2r_convert_udts(Arena *arena, DW_TagNode *root) { Temp scratch = scratch_begin(&arena, 1); - + for (D2R_TagIterator *it = d2r_tag_iterator_init(scratch.arena, root); it->tag_node != 0; d2r_tag_iterator_next(scratch.arena, it)) { DW_TagNode *tag_node = it->tag_node; DW_Tag tag = tag_node->tag; - + // skip converted tags if (d2r_is_udt_tag_converted(tag_node)) { d2r_tag_iterator_skip_children(it); continue; } d2r_flag_converted_udt_tag(tag_node); - + if (tag.kind == DW_TagKind_ClassType || tag.kind == DW_TagKind_StructureType || tag.kind == DW_TagKind_UnionType) { B32 is_decl = dw_flag_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Declaration); if (is_decl) { @@ -2136,8 +2136,8 @@ d2r_convert_udts(Arena *arena, } else if (tag.kind == DW_TagKind_Member) { DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it); B32 is_parent_udt = parent_tag.kind == DW_TagKind_StructureType || - parent_tag.kind == DW_TagKind_ClassType || - parent_tag.kind == DW_TagKind_UnionType; + parent_tag.kind == DW_TagKind_ClassType || + parent_tag.kind == DW_TagKind_UnionType; if (is_parent_udt) { RDIM_Type *parent_type = d2r_type_from_offset(type_table, parent_tag.info_off); RDIM_Type *type = d2r_type_from_attrib(type_table, input, cu, tag, DW_AttribKind_Type); @@ -2293,7 +2293,7 @@ d2r_range_list_from_tag(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 imag } } else if ((lo_pc_attrib->attrib_kind == DW_AttribKind_Null && hi_pc_attrib->attrib_kind != DW_AttribKind_Null) || (lo_pc_attrib->attrib_kind != DW_AttribKind_Null && hi_pc_attrib->attrib_kind == DW_AttribKind_Null)) { - log_user_errorf("invalid range @ .debug_info+%llx", tag.info_off); + log_user_errorf("invalid range @ .debug_info+%llx", tag.info_off); } } @@ -2343,7 +2343,7 @@ d2r_convert_symbols(Arena *arena, d2r_tag_iterator_skip_children(it); break; } - + DW_InlKind inl = DW_Inl_NotInlined; if (dw_tag_has_attrib(input, cu, tag, DW_AttribKind_Inline)) { inl = dw_const_u64_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Inline); } @@ -2392,7 +2392,7 @@ d2r_convert_symbols(Arena *arena, proc->name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Name); proc->link_name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_LinkageName); proc->type = proc_type; - proc->container_symbol = 0; + proc->container_scope = 0; proc->container_type = container_type; proc->root_scope = root_scope; proc->location_cases = d2r_locset_from_attrib(arena, &g_d2r_shared.scopes, root_scope, &g_d2r_shared.locations, input, cu, image_base, arch, tag, DW_AttribKind_FrameBase); @@ -2407,10 +2407,10 @@ d2r_convert_symbols(Arena *arena, if (dw_tag_has_attrib(input, cu, tag, DW_AttribKind_Virtuality)) { virtuality = dw_const_u64_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Virtuality); switch (virtuality) { - case DW_VirtualityKind_None: member_kind = RDI_MemberKind_Method; break; - case DW_VirtualityKind_Virtual: member_kind = RDI_MemberKind_VirtualMethod; break; - case DW_VirtualityKind_PureVirtual: member_kind = RDI_MemberKind_VirtualMethod; break; // TODO: create kind for pure virutal - default: { log_user_errorf("unhandled virtuality kind"); } break; + case DW_VirtualityKind_None: member_kind = RDI_MemberKind_Method; break; + case DW_VirtualityKind_Virtual: member_kind = RDI_MemberKind_VirtualMethod; break; + case DW_VirtualityKind_PureVirtual: member_kind = RDI_MemberKind_VirtualMethod; break; // TODO: create kind for pure virutal + default: { log_user_errorf("unhandled virtuality kind"); } break; } } } @@ -2485,7 +2485,7 @@ d2r_convert_symbols(Arena *arena, // NOTE: due to a bug in clang in stb_sprintf.h local variables // are declared in global scope without a name if (name.size == 0) { break; } - + // decls do not have location info B32 is_decl = dw_flag_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Declaration); if (is_decl) { break; } @@ -2529,7 +2529,7 @@ d2r_convert_symbols(Arena *arena, var->link_name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_LinkageName); var->type = type; var->offset = voff; - var->container_symbol = 0; + var->container_scope = 0; } } break; case DW_TagKind_FormalParameter: { @@ -2641,14 +2641,14 @@ d2r_cu_contrib_map_from_aranges(Arena *arena, DW_Input *input, U64 image_base) for EachNode(range_n, Rng1U64Node, unit_range_list.first) { String8 unit_data = str8_substr(input->sec[DW_Section_ARanges].data, range_n->v); U64 unit_cursor = 0; - + U32 first_four_bytes = 0; if (str8_deserial_read_struct(input->sec[DW_Section_Info].data, 0, &first_four_bytes) != sizeof(first_four_bytes)) { goto exit; } DW_Format unit_format = first_four_bytes == max_U32 ? DW_Format_64Bit : DW_Format_32Bit; - + U64 unit_length; TryRead(str8_deserial_read_dwarf_packed_size(unit_data, unit_cursor, &unit_length), unit_cursor, exit); - + DW_Version version; TryRead(str8_deserial_read_struct(unit_data, unit_cursor, &version), unit_cursor, exit); @@ -2656,10 +2656,10 @@ d2r_cu_contrib_map_from_aranges(Arena *arena, DW_Input *input, U64 image_base) log_user_errorf("unknown .debug_aranges version %u @ 0x%llx", version, range_n->v.min); continue; } - + U64 cu_info_off; TryRead(str8_deserial_read_dwarf_uint(unit_data, unit_cursor, unit_format, &cu_info_off), unit_cursor, exit); - + U8 address_size = 0; TryRead(str8_deserial_read_struct(unit_data, unit_cursor, &address_size), unit_cursor, exit); @@ -2726,7 +2726,7 @@ internal RDIM_BakeParams d2r_convert(Arena *arena, D2R_ConvertParams *params) { Temp scratch = scratch_begin(&arena, 1); - + if (lane_idx() == 0) { //////////////////////////////// @@ -2742,30 +2742,30 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) String8 raw_sections = str8_substr(params->exe_data, pe.section_table_range); COFF_SectionHeader *section_table = str8_deserial_get_raw_ptr(raw_sections, 0, sizeof(COFF_SectionHeader) * pe.section_count); String8 string_table = str8_substr(params->exe_data, pe.string_table_range); - + arch = pe.arch; image_base = pe.image_base; input = dw_input_from_coff_section_table(scratch.arena, params->exe_data, string_table, pe.section_count, section_table); path_style = PathStyle_WindowsAbsolute; - + g_d2r_shared.binary_sections = c2r_rdi_binary_sections_from_coff_sections(arena, params->exe_data, string_table, pe.section_count, section_table); } break; case ExecutableImageKind_Elf32: case ExecutableImageKind_Elf64: { ELF_Bin bin = elf_bin_from_data(scratch.arena, params->dbg_data); - + arch = arch_from_elf_machine(bin.hdr.e_machine); image_base = elf_base_addr_from_bin(&bin); input = dw_input_from_elf_bin(scratch.arena, params->dbg_data, &bin); path_style = PathStyle_UnixAbsolute; - + g_d2r_shared.binary_sections = e2r_rdi_binary_sections_from_elf_section_table(arena, bin.shdrs); } break; default: { InvalidPath; } break; } //////////////////////////////// - + ProfBegin("compute exe hash"); U64 exe_hash = rdi_hash(params->exe_data.str, params->exe_data.size); ProfEnd(); @@ -2797,12 +2797,12 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) ProfEnd(); //////////////////////////////// - + ProfBeginV("Convert Line Tables [Count: %llu]", cu_ranges.count); RDIM_LineTable **cu_line_tables_rdi = push_array(scratch.arena, RDIM_LineTable *, cu_ranges.count); { Temp temp = temp_begin(scratch.arena); - + // TODO: per thread task ProfBegin("Up front parse line VM headers"); DW_LineVM **line_vms = push_array(temp.arena, DW_LineVM *, cu_ranges.count); @@ -2810,18 +2810,18 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) line_vms[cu_idx] = dw_line_vm_init(&input, &cu_arr[cu_idx]); } ProfEnd(); - + // TODO: sync // // sum all source files (including duplicates) U64 total_file_count = 0; for EachIndex(cu_idx, cu_ranges.count) { total_file_count += line_vms[cu_idx]->header.file_table.count; } - + // TODO: sync ProfBeginV("Dedup source files [Count: %llu]", total_file_count); LFHT_NodeChunkList *src_file_lfht_nodes = push_array(temp.arena, LFHT_NodeChunkList, lane_count()); LFHT_Node *src_file_lfht = 0; - + // TODO: per thread { D2R_SrcFileLookup *lookup = 0; @@ -2829,11 +2829,11 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) DW_LineVM *vm = line_vms[cu_idx]; for EachIndex(file_idx, vm->header.file_table.count) { DW_LineFile *file = &vm->header.file_table.v[file_idx]; - + if (lookup == 0) { lookup = push_array(temp.arena, D2R_SrcFileLookup, 1); } lookup->vm = vm; lookup->file = file; - + LFHT_NodeChunkList *node_chunks = &src_file_lfht_nodes[lane_idx()]; U64 hash = d2r_hash_line_file(vm->header.dir_table.v[file->dir_idx], file); B32 was_inserted = lfht_insert(temp.arena, node_chunks, &src_file_lfht, hash, lookup, d2r_src_file_lookup_is_equal, 0); @@ -2844,26 +2844,26 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) } } ProfEnd(); - + // TODO: sync ProfBegin("Extract source file lookups"); U64 unique_file_count = lfht_total_count_from_node_chunk_lists(lane_count(), src_file_lfht_nodes); void **lookups = lfht_data_from_node_chunk_lists(temp.arena, unique_file_count, lane_count(), src_file_lfht_nodes); ProfEnd(); - + // TODO: sync ProfBeginV("Sort unique source files [Count: %llu]", unique_file_count); d2r_sort_ptrs(lookups, unique_file_count, d2r_src_file_lfht_key_value_is_before); ProfEnd(); - + // TODO: per thread task ProfBegin("Convert source files"); for EachIndex(i, unique_file_count) { D2R_SrcFileLookup *lookup = lookups[i]; - + DW_LineFile *src = lookup->file; RDIM_SrcFile *dst = rdim_src_file_chunk_list_push(arena, &g_d2r_shared.src_files, D2R_SRC_FILE_CAP); - + // make file path String8 path; { @@ -2872,7 +2872,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) str8_list_push_node(&path_list, &(String8Node){ .string = src->path }); path = str8_path_list_join_by_style(arena, &path_list, path_style); } - + // fill out source file dst->path = path; if ( ! u128_match(src->md5, u128_zero())) { @@ -2882,30 +2882,30 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) dst->checksum_kind = RDI_ChecksumKind_Timestamp; dst->checksum = str8_copy(arena, str8_struct(&src->time_stamp)); } - + lookup->src_file = dst; } ProfEnd(); // TODO: sync RDIM_LineTableChunkList *lane_line_table_chunks = push_array(temp.arena, RDIM_LineTableChunkList, lane_count()); - + // TODO: per thread task ProfBegin("Convert line sequences"); U64 *line_seq_counts_per_lane = push_array(scratch.arena, U64, lane_count()); for EachIndex(cu_idx, cu_ranges.count) { RDIM_LineTableChunkList *lane_line_table_chunk_list = &lane_line_table_chunks[lane_idx()]; - + // push new line table for the compile unit RDIM_LineTable *line_table = rdim_line_table_chunk_list_push(arena, lane_line_table_chunk_list, D2R_LINE_TABLE_CAP); cu_line_tables_rdi[cu_idx] = line_table; - + // push line buffer #define D2R_LineBufferMax 1024 struct LineBuffer { U64 file_index; U64 voffs[D2R_LineBufferMax]; U32 line_nums[D2R_LineBufferMax]; U32 col_nums[D2R_LineBufferMax]; } LineBuffer; struct LineBuffer *line_buffer = push_array(temp.arena, struct LineBuffer, 1); U64 line_buffer_size = 0; - + // decode line sequences DW_LineVM *vm = line_vms[cu_idx]; U64 *line_seq_counts_per_file = push_array(temp.arena, U64, vm->header.file_table.count); @@ -2913,32 +2913,32 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) if (vm->new_line) { // lazy defined files are not supported if (vm->state.file_index >= vm->header.file_table.count) { continue; } - + // time to flush the buffer? if (((vm->opcode == DW_StdOpcode_ExtendedOpcode && vm->ext_opcode == DW_ExtOpcode_EndSequence) || - (line_buffer_size >= D2R_LineBufferMax || line_buffer->file_index != vm->state.file_index)) + (line_buffer_size >= D2R_LineBufferMax || line_buffer->file_index != vm->state.file_index)) && line_buffer_size > 0) { // lookup source file DW_LineFile *file = &vm->header.file_table.v[line_buffer->file_index]; U64 hash = d2r_hash_line_file(vm->header.dir_table.v[file->dir_idx], file); D2R_SrcFileLookup *lookup = lfht_search(src_file_lfht, hash, &(D2R_SrcFileLookup){ .file = file, .vm = vm }, d2r_src_file_lookup_is_equal, 0); RDIM_SrcFile *src_file = lookup->src_file; - + // copy line info U64 *voffs = push_array_no_zero(arena, U64, line_buffer_size + 1); U32 *line_nums = push_array_no_zero(arena, U32, line_buffer_size); voffs[line_buffer_size] = vm->state.address - image_base; MemoryCopyTyped(voffs, line_buffer->voffs, line_buffer_size); MemoryCopyTyped(line_nums, line_buffer->line_nums, line_buffer_size); - + RDIM_LineSequence *line_seq = rdim_line_table_push_sequence(arena, lane_line_table_chunk_list, line_table, src_file, voffs, line_nums, 0, line_buffer_size); - + // atomic implementation of @rdim_src_file_push_line_sequence { // associate line fragment with source file RDIM_SrcFileLineMapFragment *line_frag = push_array(arena, RDIM_SrcFileLineMapFragment, 1); line_frag->seq = line_seq; - + // insert line fragment node for (;;) { RDIM_SrcFileLineMapFragment *next = src_file->first_line_map_fragment; @@ -2949,18 +2949,18 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) } if (curr == next) { break; } } - + // accumulate line sequence counts per file line_seq_counts_per_file[vm->state.file_index] += line_seq->line_count; - + // accumulate line sequence counts per lane line_seq_counts_per_lane[lane_idx()] += line_seq->line_count; } - + // reset line buffer size tracker line_buffer_size = 0; } - + if (line_buffer_size > 0 && line_buffer->voffs[line_buffer_size - 1] == vm->state.address) { line_buffer->line_nums[line_buffer_size - 1] = Min(line_buffer->line_nums[line_buffer_size - 1], safe_cast_u32(vm->state.line)); } else { @@ -2972,7 +2972,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) } } } - + // update line sequence counts per source file @rdim_src_file_push_line_sequence for EachIndex(file_idx, vm->header.file_table.count) { if (line_seq_counts_per_file[file_idx] > 0) { @@ -2984,26 +2984,26 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) } } } - + // TODO: sync // // update total line sequences count in shared @rdim_src_file_push_line_sequence for EachIndex(i, lane_count()) { g_d2r_shared.src_files.total_line_count += line_seq_counts_per_lane[i]; } - + // TODO: sync for EachIndex(i, lane_count()) { rdim_line_table_chunk_list_concat_in_place(&g_d2r_shared.line_tables, &lane_line_table_chunks[i]); } - + // TODO: per thread task ProfBegin("Relase line VMs"); for EachIndex(i, cu_ranges.count) { dw_line_vm_release(line_vms[i]); } ProfEnd(); - + temp_end(temp); } ProfEnd(); @@ -3022,7 +3022,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) type->byte_size = rdi_size_from_basic_type_kind(type_kind); builtin_types[type_kind] = type; } - + // fixup float80 size if (arch == Arch_x64 || arch == Arch_arm64) { builtin_types[RDI_TypeKind_F80]->byte_size = 16; @@ -3041,7 +3041,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) Temp comp_temp = temp_begin(scratch.arena); DW_CompUnit *cu = &cu_arr[cu_idx]; - + // skip DWO { if (cu->dwo_id) { goto next_cu; } diff --git a/src/rdi_from_pdb/rdi_from_pdb.c b/src/rdi_from_pdb/rdi_from_pdb.c index c777f199..4d76106f 100644 --- a/src/rdi_from_pdb/rdi_from_pdb.c +++ b/src/rdi_from_pdb/rdi_from_pdb.c @@ -3460,11 +3460,11 @@ p2r_convert(Arena *arena, P2R_ConvertParams *params) container_type = p2r_type_ptr_from_itype(cv_type_id); } - // rjf: unpack global's container symbol - RDIM_Symbol *container_symbol = 0; + // rjf: unpack global's container scope + RDIM_Scope *container_scope = 0; if(container_type == 0 && top_scope_node != 0) { - container_symbol = top_scope_node->scope->symbol; + container_scope = top_scope_node->scope; } // rjf: build symbol @@ -3473,7 +3473,7 @@ p2r_convert(Arena *arena, P2R_ConvertParams *params) symbol->name = name; symbol->type = type; symbol->offset = voff; - symbol->container_symbol = container_symbol; + symbol->container_scope = container_scope; symbol->container_type = container_type; } }break; @@ -3516,11 +3516,11 @@ p2r_convert(Arena *arena, P2R_ConvertParams *params) container_type = p2r_type_ptr_from_itype(cv_type_id); } - // rjf: unpack proc's container symbol - RDIM_Symbol *container_symbol = 0; + // rjf: unpack proc's container scope + RDIM_Scope *container_scope = 0; if(container_type == 0 && top_scope_node != 0) { - container_symbol = top_scope_node->scope->symbol; + container_scope = top_scope_node->scope; } // rjf: build procedure's root scope @@ -3571,7 +3571,7 @@ p2r_convert(Arena *arena, P2R_ConvertParams *params) curr_proc_symbol->name = name; curr_proc_symbol->link_name = link_name; curr_proc_symbol->type = type; - curr_proc_symbol->container_symbol = container_symbol; + curr_proc_symbol->container_scope = container_scope; curr_proc_symbol->container_type = container_type; curr_proc_symbol->root_scope = procedure_root_scope; if(procedure_root_scope != 0) @@ -3716,10 +3716,10 @@ p2r_convert(Arena *arena, P2R_ConvertParams *params) } // rjf: unpack thread variable's container symbol - RDIM_Symbol *container_symbol = 0; + RDIM_Scope *container_scope = 0; if(container_type == 0 && top_scope_node != 0) { - container_symbol = top_scope_node->scope->symbol; + container_scope = top_scope_node->scope; } // rjf: build symbol @@ -3729,7 +3729,7 @@ p2r_convert(Arena *arena, P2R_ConvertParams *params) tvar->is_extern = (iter.kind == CV_SymKind_GTHREAD32); tvar->offset = tls_off; tvar->container_type = container_type; - tvar->container_symbol = container_symbol; + tvar->container_scope = container_scope; }break; //- rjf: LOCAL diff --git a/src/rdi_make/rdi_make_local.c b/src/rdi_make/rdi_make_local.c index 9a3a669b..a99b54a2 100644 --- a/src/rdi_make/rdi_make_local.c +++ b/src/rdi_make/rdi_make_local.c @@ -2999,10 +2999,10 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) dst->link_flags |= RDI_LinkFlag_TypeScoped; dst->container_idx = src->container_type ? (RDI_U32)rdim_idx_from_udt(src->container_type->udt) : 0; // TODO(rjf): @u64_to_u32 } - else if(src->container_symbol != 0) + else if(src->container_scope != 0) { dst->link_flags |= RDI_LinkFlag_ProcScoped; - dst->container_idx = (RDI_U32)rdim_idx_from_symbol(src->container_symbol); // TODO(rjf): @u64_to_u32 + dst->container_idx = (RDI_U32)rdim_idx_from_symbol(src->container_scope->symbol); // TODO(rjf): @u64_to_u32 } dst->type_idx = (RDI_U32)rdim_idx_from_type(src->type); // TODO(rjf): @u64_to_u32 dst->root_scope_idx = (RDI_U32)rdim_idx_from_scope(src->root_scope); // TODO(rjf): @u64_to_u32 @@ -3294,10 +3294,10 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) dst->link_flags |= RDI_LinkFlag_TypeScoped; dst->container_idx = src->container_type ? (RDI_U32)rdim_idx_from_udt(src->container_type->udt) : 0; // TODO(rjf): @u64_to_u32 } - else if(src->container_symbol != 0) + else if(src->container_scope != 0) { dst->link_flags |= RDI_LinkFlag_ProcScoped; - dst->container_idx = (RDI_U32)rdim_idx_from_symbol(src->container_symbol); // TODO(rjf): @u64_to_u32 + dst->container_idx = (RDI_U32)rdim_idx_from_symbol(src->container_scope->symbol); // TODO(rjf): @u64_to_u32 } } } @@ -3325,10 +3325,10 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) dst->link_flags |= RDI_LinkFlag_TypeScoped; dst->container_idx = src->container_type ? (RDI_U32)rdim_idx_from_udt(src->container_type->udt) : 0; // TODO(rjf): @u64_to_u32 } - else if(src->container_symbol != 0) + else if(src->container_scope != 0) { dst->link_flags |= RDI_LinkFlag_ProcScoped; - dst->container_idx = (RDI_U32)rdim_idx_from_symbol(src->container_symbol); // TODO(rjf): @u64_to_u32 + dst->container_idx = (RDI_U32)rdim_idx_from_symbol(src->container_scope->symbol); // TODO(rjf): @u64_to_u32 } } } @@ -3354,6 +3354,72 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) } lane_sync(); + ////////////////////////////////////////////////////////////// + //- rjf: @rdim_bake_stage bake symbols (NEW) + // + ProfScope("bake symbols") + { + //////////////////////////// + //- rjf: set up all symbol table baking tasks + // + struct + { + RDIM_SymbolChunkList *symbols; + } + tasks[] = + { + {¶ms->global_variables}, + {¶ms->thread_variables}, + }; + + //////////////////////////// + //- rjf: bake flat symbol tables + // + for EachElement(task_idx, tasks) + { + RDIM_SymbolChunkList *src_symbols = tasks[task_idx].symbols; + U64 dst_symbols_count = src_symbols->total_count + 1; + RDI_Symbol *dst_symbols = 0; + if(lane_idx() == 0) + { + dst_symbols = push_array(arena, RDI_Symbol, dst_symbols_count); + } + lane_sync_u64(&dst_symbols, 0); + for EachNode(n, RDIM_SymbolChunkNode, src_symbols->first) + { + Rng1U64 range = lane_range(n->count); + for EachInRange(n_idx, range) + { + RDIM_Symbol *src = &n->v[n_idx]; + RDI_Symbol *dst = &dst_symbols[n->base_idx + n_idx + 1]; + + // rjf: fill basics + dst->name_string_idx = rdim_bake_idx_from_string(bake_strings, src->name); + dst->type_idx = (RDI_U32)rdim_idx_from_type(src->type); // TODO(rjf): @u64_to_u32 + dst->root_scope_idx = (RDI_U32)rdim_idx_from_scope(src->root_scope); // TODO(rjf): @u64_to_u32 + dst->link_name_string_idx = rdim_bake_idx_from_string(bake_strings, src->link_name); + + // rjf: fill container info + if(src->is_extern) + { + dst->container_flags |= RDI_ContainerFlag_External; + } + if(src->container_scope != 0) + { + dst->container_flags |= RDI_ContainerKind_Scope; + dst->container_idx = rdim_idx_from_scope(src->container_scope); + } + else if(src->container_type != 0) + { + dst->container_flags |= RDI_ContainerKind_Type; + dst->container_idx = rdim_idx_from_udt(src->container_type->udt); + } + } + } + } + } + lane_sync(); + ////////////////////////////////////////////////////////////// //- rjf: @rdim_bake_stage bake file paths //