[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:09:23 PST 2025
https://github.com/aury6623 created https://github.com/llvm/llvm-project/pull/166626
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
>From 027279a7ef2bedffcd0d23f605fc0e135ad77e37 Mon Sep 17 00:00:00 2001
From: Aury Shafran <aury.shafran at intel.com>
Date: Wed, 5 Nov 2025 08:35:37 -0800
Subject: [PATCH] [lld] Warn when missing needed sections for --gdb-index
---
lld/ELF/SyntheticSections.cpp | 10 ++++++++++
1 file changed, 10 insertions(+)
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();
More information about the llvm-commits
mailing list