[lld] [lld] Warn for missing needed sections by --gdb-index (PR #166626)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 5 12:10:17 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld-elf

Author: None (aury6623)

<details>
<summary>Changes</summary>

Issue a warning when lld is passed `--gdb-index` and some object files have general debug info but not the specific debug  sections generated by `-ggnu-pubnames` or `-gsplit-dwarf`. Missing those sections on all inputs leads to an empty index, which gdb ignores. Missing those sections on only some sources leads to a partially complete index, which confuses gdb.

Addresses https://github.com/llvm/llvm-project/issues/156732 and https://github.com/llvm/llvm-project/issues/34168

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


1 Files Affected:

- (modified) lld/ELF/SyntheticSections.cpp (+10) 


``````````diff
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index a4150ebfa1653..77487de805960 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -3566,6 +3566,16 @@ std::unique_ptr<GdbIndexSection> GdbIndexSection::create(Ctx &ctx) {
     DWARFContext dwarf(std::make_unique<LLDDwarfObj<ELFT>>(file));
     auto &dobj = static_cast<const LLDDwarfObj<ELFT> &>(dwarf.getDWARFObj());
 
+    if (dobj.getGnuPubnamesSection().sec == nullptr &&
+        dobj.getGnuPubtypesSection().sec == nullptr) {
+      Warn(ctx)
+          << files[i]
+          << ": file contains debug info but is missing .debug_gnu_pubnames or "
+             ".debug_gnu_pubtypes sections required by --gdb-index. Compile "
+             "the file using -gsplit-dwarf or -ggnu-pubnames to generate these "
+             "sections.";
+    }
+
     // If the are multiple compile units .debug_info (very rare ld -r --unique),
     // this only picks the last one. Other address ranges are lost.
     chunks[i].sec = dobj.getInfoSection();

``````````

</details>


https://github.com/llvm/llvm-project/pull/166626


More information about the llvm-commits mailing list