Skip to content

Commit 6586452

Browse files
committed
DebugInfo: Add the ability to disable DWARF name tables entirely
This changes the current default behavior (from emitting pubnames by default, to not emitting them by default) & moves to matching GCC's behavior* with one significant difference: -gno(-gnu)-pubnames disables pubnames even in the presence of -gsplit-dwarf (though -gsplit-dwarf still by default enables -ggnu-pubnames). This allows users to disable pubnames (& the new DWARF5 accelerated access tables) when they might not be worth the size overhead. * GCC's behavior is that -ggnu-pubnames and -gpubnames override each other, and that -gno-gnu-pubnames and -gno-pubnames act as synonyms and disable either kind of pubnames if they come last. (eg: -gpubnames -gno-gnu-pubnames causes no pubnames (neither gnu or standard) to be emitted) llvm-svn: 340206
1 parent a25e206 commit 6586452

File tree

10 files changed

+53
-21
lines changed

10 files changed

+53
-21
lines changed

clang/include/clang/Driver/CC1Options.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,6 @@ def dwarf_column_info : Flag<["-"], "dwarf-column-info">,
197197
HelpText<"Turn on column location information.">;
198198
def split_dwarf : Flag<["-"], "split-dwarf">,
199199
HelpText<"Split out the dwarf .dwo sections">;
200-
def gnu_pubnames : Flag<["-"], "gnu-pubnames">,
201-
HelpText<"Emit newer GNU style pubnames">;
202-
def arange_sections : Flag<["-"], "arange_sections">,
203-
HelpText<"Emit DWARF .debug_arange sections">;
204200
def dwarf_ext_refs : Flag<["-"], "dwarf-ext-refs">,
205201
HelpText<"Generate debug info with external references to clang modules"
206202
" or precompiled headers">;

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,8 @@ def gno_column_info : Flag<["-"], "gno-column-info">, Group<g_flags_Group>, Flag
18071807
def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, Group<g_flags_Group>;
18081808
def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group<g_flags_Group>, Flags<[CC1Option]>;
18091809
def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group<g_flags_Group>, Flags<[CC1Option]>;
1810+
def gpubnames : Flag<["-"], "gpubnames">, Group<g_flags_Group>, Flags<[CC1Option]>;
1811+
def gno_pubnames : Flag<["-"], "gno-pubnames">, Group<g_flags_Group>, Flags<[CC1Option]>;
18101812
def gdwarf_aranges : Flag<["-"], "gdwarf-aranges">, Group<g_flags_Group>;
18111813
def gmodules : Flag <["-"], "gmodules">, Group<gN_Group>,
18121814
HelpText<"Generate debug info with external references to clang modules"

clang/include/clang/Frontend/CodeGenOptions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ CODEGENOPT(DebugInfoForProfiling, 1, 0)
326326
CODEGENOPT(PreserveVec3Type, 1, 0)
327327

328328
/// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
329-
CODEGENOPT(GnuPubnames, 1, 0)
329+
CODEGENOPT(DebugNameTable, 2, 0)
330330

331331
CODEGENOPT(NoPLT, 1, 0)
332332

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,8 @@ void CGDebugInfo::CreateCompileUnit() {
581581
0 /* DWOid */, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
582582
CGM.getTarget().getTriple().isNVPTX()
583583
? llvm::DICompileUnit::DebugNameTableKind::None
584-
: CGOpts.GnuPubnames
585-
? llvm::DICompileUnit::DebugNameTableKind::GNU
586-
: llvm::DICompileUnit::DebugNameTableKind::Default);
584+
: static_cast<llvm::DICompileUnit::DebugNameTableKind>(
585+
CGOpts.DebugNameTable));
587586
}
588587

589588
llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,11 +3060,18 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
30603060
CmdArgs.push_back("-debug-info-macro");
30613061

30623062
// -ggnu-pubnames turns on gnu style pubnames in the backend.
3063-
if (Args.hasFlag(options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames,
3064-
false))
3065-
if (checkDebugInfoOption(Args.getLastArg(options::OPT_ggnu_pubnames), Args,
3066-
D, TC))
3067-
CmdArgs.push_back("-ggnu-pubnames");
3063+
const auto *PubnamesArg =
3064+
Args.getLastArg(options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames,
3065+
options::OPT_gpubnames, options::OPT_gno_pubnames);
3066+
if (SplitDWARFArg ||
3067+
(PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC)))
3068+
if (!PubnamesArg ||
3069+
(!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
3070+
!PubnamesArg->getOption().matches(options::OPT_gno_pubnames)))
3071+
CmdArgs.push_back(PubnamesArg && PubnamesArg->getOption().matches(
3072+
options::OPT_gpubnames)
3073+
? "-gpubnames"
3074+
: "-ggnu-pubnames");
30683075

30693076
// -gdwarf-aranges turns on the emission of the aranges section in the
30703077
// backend.

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "llvm/ADT/StringSwitch.h"
5656
#include "llvm/ADT/Triple.h"
5757
#include "llvm/ADT/Twine.h"
58+
#include "llvm/IR/DebugInfoMetadata.h"
5859
#include "llvm/Linker/Linker.h"
5960
#include "llvm/MC/MCTargetOptions.h"
6061
#include "llvm/Option/Arg.h"
@@ -643,7 +644,12 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
643644
Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
644645
Opts.DebugInfoForProfiling = Args.hasFlag(
645646
OPT_fdebug_info_for_profiling, OPT_fno_debug_info_for_profiling, false);
646-
Opts.GnuPubnames = Args.hasArg(OPT_ggnu_pubnames);
647+
Opts.DebugNameTable = static_cast<unsigned>(
648+
Args.hasArg(OPT_ggnu_pubnames)
649+
? llvm::DICompileUnit::DebugNameTableKind::GNU
650+
: Args.hasArg(OPT_gpubnames)
651+
? llvm::DICompileUnit::DebugNameTableKind::Default
652+
: llvm::DICompileUnit::DebugNameTableKind::None);
647653

648654
setPGOInstrumentor(Opts, Args, Diags);
649655
Opts.InstrProfileOutput =

clang/test/CodeGen/debug-info-global-constant.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// CHECK: @i = internal constant i32 1, align 4, !dbg ![[I:[0-9]+]]
88
// CHECK: ![[I]] = !DIGlobalVariableExpression(var: ![[VAR:.*]], expr: !DIExpression(DW_OP_constu, 1, DW_OP_stack_value))
99
// CHECK: ![[VAR]] = distinct !DIGlobalVariable(name: "i",
10-
// CHECK: !DICompileUnit({{.*}}globals: ![[GLOBALS:[0-9]+]])
10+
// CHECK: !DICompileUnit({{.*}}globals: ![[GLOBALS:[0-9]+]]
1111
// CHECK: ![[GLOBALS]] = !{![[I]]}
1212
static const int i = 1;
1313

clang/test/CodeGen/debug-info-macro.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// NO_MACRO-NOT: DIMacro
2424
// NO_MACRO-NOT: DIMacroFile
2525

26-
// CHECK: !DICompileUnit({{.*}} macros: [[Macros:![0-9]+]])
26+
// CHECK: !DICompileUnit({{.*}} macros: [[Macros:![0-9]+]]
2727
// CHECK: [[EmptyMD:![0-9]+]] = !{}
2828

2929
// NO_PCH: [[Macros]] = !{[[MainMacroFile:![0-9]+]], [[BuiltinMacro:![0-9]+]], {{.*}}, [[DefineC1:![0-9]+]], [[DefineA:![0-9]+]], [[UndefC1:![0-9]+]]}

clang/test/CodeGen/debug-info-names.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
2+
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -gpubnames | FileCheck --check-prefix=DEFAULT %s
3+
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -ggnu-pubnames | FileCheck --check-prefix=GNU %s
4+
5+
// CHECK: !DICompileUnit({{.*}}, nameTableKind: None
6+
// DEFAULT-NOT: !DICompileUnit({{.*}}, nameTableKind:
7+
// GNU: !DICompileUnit({{.*}}, nameTableKind: GNU
8+
9+
void f1() {
10+
}

clang/test/Driver/debug-options.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,18 @@
133133
// RUN: %clang -### -c -gstrict-dwarf -gno-strict-dwarf %s 2>&1 \
134134
// RUN: | FileCheck -check-prefix=GIGNORE %s
135135
//
136-
// RUN: %clang -### -c -ggnu-pubnames %s 2>&1 | FileCheck -check-prefix=GOPT %s
137-
// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOGOPT %s
138-
// RUN: %clang -### -c -ggnu-pubnames -gno-gnu-pubnames %s 2>&1 | FileCheck -check-prefix=NOGOPT %s
136+
// RUN: %clang -### -c -ggnu-pubnames %s 2>&1 | FileCheck -check-prefix=GPUB %s
137+
// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOPUB %s
138+
// RUN: %clang -### -c -ggnu-pubnames -gno-gnu-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
139+
// RUN: %clang -### -c -ggnu-pubnames -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
140+
//
141+
// RUN: %clang -### -c -gpubnames %s 2>&1 | FileCheck -check-prefix=PUB %s
142+
// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOPUB %s
143+
// RUN: %clang -### -c -gpubnames -gno-gnu-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
144+
// RUN: %clang -### -c -gpubnames -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
145+
//
146+
// RUN: %clang -### -c -gsplit-dwarf %s 2>&1 | FileCheck -check-prefix=GPUB %s
147+
// RUN: %clang -### -c -gsplit-dwarf -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
139148
//
140149
// RUN: %clang -### -c -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=GARANGE %s
141150
//
@@ -229,8 +238,11 @@
229238
//
230239
// GIGNORE-NOT: "argument unused during compilation"
231240
//
232-
// GOPT: -ggnu-pubnames
233-
// NOGOPT-NOT: -ggnu-pubnames
241+
// GPUB: -ggnu-pubnames
242+
// NOPUB-NOT: -ggnu-pubnames
243+
// NOPUB-NOT: -gpubnames
244+
//
245+
// PUB: -gpubnames
234246
//
235247
// GARANGE: -generate-arange-section
236248
//

0 commit comments

Comments
 (0)