Skip to content

Conversation

zhaoqi5
Copy link
Contributor

@zhaoqi5 zhaoqi5 commented Sep 15, 2025

LoongArch64 always uses symbols for relocations, so temporary symbols starting with ".L" should be preserved so that relocations in .debug_info can be fixed correctly.

After this commit, three tests passed:

lldb-shell :: SymbolFile/DWARF/anon_class_w_and_wo_export_symbols.ll
lldb-shell :: SymbolFile/DWARF/clang-ast-from-dwarf-unamed-and-anon-structs.cpp
lldb-shell :: SymbolFile/DWARF/clang-gmodules-type-lookup.c

…db symbol table

LoongArch64 always uses symbols for relocations, so temporary symbols
starting with ".L" should be preserved so that relocations in
`.debug_info` can be fixed correctly.

After this commit, three tests passed:

```
lldb-shell :: SymbolFile/DWARF/anon_class_w_and_wo_export_symbols.ll
lldb-shell :: SymbolFile/DWARF/clang-ast-from-dwarf-unamed-and-anon-structs.cpp
lldb-shell :: SymbolFile/DWARF/clang-gmodules-type-lookup.c
```
@llvmbot
Copy link
Member

llvmbot commented Sep 15, 2025

@llvm/pr-subscribers-backend-loongarch

@llvm/pr-subscribers-lldb

Author: ZhaoQi (zhaoqi5)

Changes

LoongArch64 always uses symbols for relocations, so temporary symbols starting with ".L" should be preserved so that relocations in .debug_info can be fixed correctly.

After this commit, three tests passed:

lldb-shell :: SymbolFile/DWARF/anon_class_w_and_wo_export_symbols.ll
lldb-shell :: SymbolFile/DWARF/clang-ast-from-dwarf-unamed-and-anon-structs.cpp
lldb-shell :: SymbolFile/DWARF/clang-gmodules-type-lookup.c

Full diff: https://github.com/llvm/llvm-project/pull/158551.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (+6-2)
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 931baf5927a04..0f8bc5fc93e07 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2119,8 +2119,12 @@ ObjectFileELF::ParseSymbols(Symtab *symtab, user_id_t start_id,
     // 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;
+    // LoongArch64 always uses symbols for relocations, so temporary symbols
+    // starting with ".L" should be preserved.
+    if (arch.GetMachine() != llvm::Triple::loongarch64) {
+      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'))

@zhaoqi5 zhaoqi5 requested a review from SixWeining September 15, 2025 06:52
Co-authored-by: Lu Weining <[email protected]>
Copy link

github-actions bot commented Sep 15, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@SixWeining
Copy link
Contributor

cc @barsolo2000

@DavidSpickett
Copy link
Collaborator

I assume this is fallout from https://discourse.llvm.org/t/rfc-should-we-omit-local-symbols-in-elf-files-from-the-lldb-symbol-table/87384.

Which I have no context for but I'll add some of those folks on review.

@DavidSpickett DavidSpickett requested review from MaskRay and clayborg and removed request for DavidSpickett September 15, 2025 08:33
@MaskRay
Copy link
Member

MaskRay commented Sep 16, 2025

I assume this is fallout from discourse.llvm.org/t/rfc-should-we-omit-local-symbols-in-elf-files-from-the-lldb-symbol-table/87384.

Which I have no context for but I'll add some of those folks on review.

I am not familiar with lldb. When RISC-V and LoongArch linker relaxation is enabled for assemblers, there are typically a lot of .L0 symbols (#89693). These numerous symbols have an identical name. What does "preserve" in the context mean?

@zhaoqi5
Copy link
Contributor Author

zhaoqi5 commented Sep 17, 2025

I am not familiar with lldb. When RISC-V and LoongArch linker relaxation is enabled for assemblers, there are typically a lot of .L0 symbols (#89693). These numerous symbols have an identical name. What does "preserve" in the context mean?

There are .L0 symbols even linker relaxation is not enabled, because RISC-V and LoongArch always use symbols for relocations.

If these symbols are omitted from symbol table, lldb will fail to analyze the symbols info and fix the relocations in .debug_info, leading to the three tests mentioned earlier which test lldb-test symbols -dump-clang-ast ... failed (maybe both on riscv and loongarch). So we should preserve these symbols rather than omit them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants