Skip to content

Commit 16711b4

Browse files
cmticeMaskRay
andauthored
[lld][ELF] Add --debug-names to create merged .debug_names. (#86508)
`clang -g -gpubnames` (with optional -gsplit-dwarf) creates the `.debug_names` section ("per-CU" index). By default lld concatenates input `.debug_names` sections into an output `.debug_names` section. LLDB can consume the concatenated section but the lookup performance is not good. This patch adds --debug-names to create a per-module index by combining the per-CU indexes into a single index that covers the entire load module. The produced `.debug_names` is a replacement for `.gdb_index`. Type units (-fdebug-types-section) are not handled yet. Co-authored-by: Fangrui Song <[email protected]> --------- Co-authored-by: Fangrui Song <[email protected]>
1 parent 6e6da74 commit 16711b4

24 files changed

+5421
-1
lines changed

lld/ELF/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ struct Config {
229229
bool cref;
230230
llvm::SmallVector<std::pair<llvm::GlobPattern, uint64_t>, 0>
231231
deadRelocInNonAlloc;
232+
bool debugNames;
232233
bool demangle = true;
233234
bool dependentLibraries;
234235
bool disableVerify;

lld/ELF/DWARF.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ template <class ELFT> LLDDwarfObj<ELFT>::LLDDwarfObj(ObjFile<ELFT> *obj) {
4040
.Case(".debug_gnu_pubtypes", &gnuPubtypesSection)
4141
.Case(".debug_line", &lineSection)
4242
.Case(".debug_loclists", &loclistsSection)
43+
.Case(".debug_names", &namesSection)
4344
.Case(".debug_ranges", &rangesSection)
4445
.Case(".debug_rnglists", &rnglistsSection)
4546
.Case(".debug_str_offsets", &strOffsetsSection)

lld/ELF/DWARF.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject {
6262
const LLDDWARFSection &getGnuPubtypesSection() const override {
6363
return gnuPubtypesSection;
6464
}
65+
const LLDDWARFSection &getNamesSection() const override {
66+
return namesSection;
67+
}
6568

6669
StringRef getFileName() const override { return ""; }
6770
StringRef getAbbrevSection() const override { return abbrevSection; }
@@ -87,6 +90,7 @@ template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject {
8790
LLDDWARFSection infoSection;
8891
LLDDWARFSection lineSection;
8992
LLDDWARFSection loclistsSection;
93+
LLDDWARFSection namesSection;
9094
LLDDWARFSection rangesSection;
9195
LLDDWARFSection rnglistsSection;
9296
LLDDWARFSection strOffsetsSection;

lld/ELF/Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ static void checkOptions() {
442442
error("-r and -pie may not be used together");
443443
if (config->exportDynamic)
444444
error("-r and --export-dynamic may not be used together");
445+
if (config->debugNames)
446+
error("-r and --debug-names may not be used together");
445447
}
446448

447449
if (config->executeOnly) {
@@ -1234,6 +1236,7 @@ static void readConfigs(opt::InputArgList &args) {
12341236
config->cref = args.hasArg(OPT_cref);
12351237
config->optimizeBBJumps =
12361238
args.hasFlag(OPT_optimize_bb_jumps, OPT_no_optimize_bb_jumps, false);
1239+
config->debugNames = args.hasFlag(OPT_debug_names, OPT_no_debug_names, false);
12371240
config->demangle = args.hasFlag(OPT_demangle, OPT_no_demangle, true);
12381241
config->dependencyFile = args.getLastArgValue(OPT_dependency_file);
12391242
config->dependentLibraries = args.hasFlag(OPT_dependent_libraries, OPT_no_dependent_libraries, true);

lld/ELF/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ def : Flag<["--"], "no-color-diagnostics">, Alias<color_diagnostics>, AliasArgs<
153153
def cref: FF<"cref">,
154154
HelpText<"Output cross reference table. If -Map is specified, print to the map file">;
155155

156+
defm debug_names: BB<"debug-names",
157+
"Generate a merged .debug_names section",
158+
"Do not generate a merged .debug_names section (default)">;
159+
156160
defm demangle: B<"demangle",
157161
"Demangle symbol names (default)",
158162
"Do not demangle symbol names">;

0 commit comments

Comments
 (0)