diff options
author | barsolo2000 <barsolo@meta.com> | 2025-08-27 17:58:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-27 19:58:08 -0500 |
commit | c2be0351a725c95e3841a8d59ee432f5b205763f (patch) | |
tree | d385365d57c639674085b0b851eb148882b32a9a /lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp | |
parent | 9c9e56b81cdfd42ddb0de4f5efb3bf787978894e (diff) | |
download | llvm-c2be0351a725c95e3841a8d59ee432f5b205763f.zip llvm-c2be0351a725c95e3841a8d59ee432f5b205763f.tar.gz llvm-c2be0351a725c95e3841a8d59ee432f5b205763f.tar.bz2 |
[LLDB] Omit loading local symbols in LLDB symbol table (#154809)
https://discourse.llvm.org/t/rfc-should-we-omit-local-symbols-in-eekciihgtfvflvnbieicunjlrtnufhuelf-files-from-the-lldb-symbol-table/87384
Improving symbolication by excluding local symbols that are typically
not useful for debugging or symbol lookups. This aligns with the
discussion that local symbols, especially those with STB_LOCAL binding
and STT_NOTYPE type (including .L-prefixed symbols), often interfere
with symbol resolution and can be safely omitted.
---------
Co-authored-by: Bar Soloveychik <barsolo@fb.com>
Diffstat (limited to 'lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp')
-rw-r--r-- | lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index f69358d..931baf5 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -2037,6 +2037,19 @@ static char FindArmAarch64MappingSymbol(const char *symbol_name) { return '\0'; } +static char FindRISCVMappingSymbol(const char *symbol_name) { + if (!symbol_name) + return '\0'; + + if (strcmp(symbol_name, "$d") == 0) { + return 'd'; + } + if (strcmp(symbol_name, "$x") == 0) { + return 'x'; + } + return '\0'; +} + #define STO_MIPS_ISA (3 << 6) #define STO_MICROMIPS (2 << 6) #define IS_MICROMIPS(ST_OTHER) (((ST_OTHER)&STO_MIPS_ISA) == STO_MICROMIPS) @@ -2102,6 +2115,12 @@ ObjectFileELF::ParseSymbols(Symtab *symtab, user_id_t start_id, if (!symbol_name) symbol_name = ""; + // Skip local symbols starting with ".L" because these are compiler + // generated local labels used for internal purposes (e.g. debugging, + // optimization) and are not relevant for symbol resolution or external + // linkage. + if (llvm::StringRef(symbol_name).starts_with(".L")) + continue; // No need to add non-section symbols that have no names if (symbol.getType() != STT_SECTION && (symbol_name == nullptr || symbol_name[0] == '\0')) @@ -2190,7 +2209,6 @@ ObjectFileELF::ParseSymbols(Symtab *symtab, user_id_t start_id, int64_t symbol_value_offset = 0; uint32_t additional_flags = 0; - if (arch.IsValid()) { if (arch.GetMachine() == llvm::Triple::arm) { if (symbol.getBinding() == STB_LOCAL) { @@ -2235,6 +2253,27 @@ ObjectFileELF::ParseSymbols(Symtab *symtab, user_id_t start_id, if (mapping_symbol) continue; } + } else if (arch.GetTriple().isRISCV()) { + if (symbol.getBinding() == STB_LOCAL) { + char mapping_symbol = FindRISCVMappingSymbol(symbol_name); + if (symbol_type == eSymbolTypeCode) { + // Only handle $d and $x mapping symbols. + // Other mapping symbols are ignored as they don't affect address + // classification. + switch (mapping_symbol) { + case 'x': + // $x - marks a RISCV instruction sequence + address_class_map[symbol.st_value] = AddressClass::eCode; + break; + case 'd': + // $d - marks a RISCV data item sequence + address_class_map[symbol.st_value] = AddressClass::eData; + break; + } + } + if (mapping_symbol) + continue; + } } if (arch.GetMachine() == llvm::Triple::arm) { |