Skip to content

Conversation

@aury6623
Copy link

@aury6623 aury6623 commented Nov 5, 2025

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 #156732 and #34168

@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2025

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-elf

Author: None (aury6623)

Changes

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 #156732 and #34168


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

1 Files Affected:

  • (modified) lld/ELF/SyntheticSections.cpp (+10)
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(); 
@aury6623
Copy link
Author

aury6623 commented Nov 5, 2025

This edit is a solution for Issue #156732 I posted a few months ago. Having this warning would have saved me a day or two of debugging! In particular, when only some files are compiled with -ggnu-pubnames, but --gdb-index is still used, gdb can act in strange ways. E.g. in one case, gdb would only acknowledge the existence of a global type within certain scopes of the same function!

Now knowing what the issue is, I found this forum post where someone is running into a similar issue:
https://groups.google.com/g/llvm-dev/c/hxnPll-6de0
and this feature request asking for --gdb-index to work without -ggnu-pubnames:
#34168

which suggests that other people may find this warning to be helpful too.


This is my first time contributing to llvm-project. I know adding new tests for a change is normally expected, but I'm not sure what test changes (if any) are expected for only an addition of a warning message, or where that test should be added. Please advise. Thanks!

Copy link
Member

@lenary lenary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you add a test?

@aury6623
Copy link
Author

@lenary

Please can you add a test?

Sure, happy to! This is my first contribution to llvm-project, so I'm not quite familiar with the testing infrastructure. I've read this page:
https://llvm.org/docs/TestingGuide.html
But I can't tell which category of test this edit fits into. Based on the guide, and that this issue is best tested by compiling a whole program (it requires submitting multiple .o files to lld), it seems like the external test-suite repo is best suited. However, I don't see anywhere in that repo dedicated to lld tests.

If you could let me know where a test for an edit like this should go, that would be helpful! Thanks!

@lenary
Copy link
Member

lenary commented Nov 10, 2025

Yeah, that guide is good at the higher level, but I can see why you need more guidance :)

I think what we'd want is an assembly + linker test. This would consist of 1 (maybe 2) assembly files, which are assembled with llvm-mc, and then linked. These can be written all in the same file using the split-file utility, and the approach documented in "Extra Files" in that document.

The core assertion behind the test would be to invoke LLD, and then run FileCheck on its output. FileCheck would then check for the warnings in LLD's output. This tends to be done something like:

# REQUIRES: <target you chose> # RUN: rm -rf %t && split-file %s %t && cd %t # RUN: llvm-mc -filetype=obj -triple=<target you choose> input.s -o input.o # RUN: ld.lld input.o -o output.exe 2>&1 | FileCheck %s --check-prefix=WARNING --implicit-check-not=warning: # WARNING: <the text from your warning> #--- input.s <contents of your assembly file> 

It's fine to take a simple C example, and compile it on your own using clang -S -g file.c -o - to get some assembly to base your input on - I know assembling dwarf by hand isn't fun/easy.

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

3 participants