Skip to content

Commit

Permalink
DebugInfo: Add the ability to disable DWARF name tables entirely
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dwblaikie committed Aug 20, 2018
1 parent a25e206 commit 6586452
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 21 deletions.
4 changes: 0 additions & 4 deletions clang/include/clang/Driver/CC1Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,6 @@ def dwarf_column_info : Flag<["-"], "dwarf-column-info">,
HelpText<"Turn on column location information.">;
def split_dwarf : Flag<["-"], "split-dwarf">,
HelpText<"Split out the dwarf .dwo sections">;
def gnu_pubnames : Flag<["-"], "gnu-pubnames">,
HelpText<"Emit newer GNU style pubnames">;
def arange_sections : Flag<["-"], "arange_sections">,
HelpText<"Emit DWARF .debug_arange sections">;
def dwarf_ext_refs : Flag<["-"], "dwarf-ext-refs">,
HelpText<"Generate debug info with external references to clang modules"
" or precompiled headers">;
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,8 @@ def gno_column_info : Flag<["-"], "gno-column-info">, Group<g_flags_Group>, Flag
def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, Group<g_flags_Group>;
def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group<g_flags_Group>, Flags<[CC1Option]>;
def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group<g_flags_Group>, Flags<[CC1Option]>;
def gpubnames : Flag<["-"], "gpubnames">, Group<g_flags_Group>, Flags<[CC1Option]>;
def gno_pubnames : Flag<["-"], "gno-pubnames">, Group<g_flags_Group>, Flags<[CC1Option]>;
def gdwarf_aranges : Flag<["-"], "gdwarf-aranges">, Group<g_flags_Group>;
def gmodules : Flag <["-"], "gmodules">, Group<gN_Group>,
HelpText<"Generate debug info with external references to clang modules"
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Frontend/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ CODEGENOPT(DebugInfoForProfiling, 1, 0)
CODEGENOPT(PreserveVec3Type, 1, 0)

/// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
CODEGENOPT(GnuPubnames, 1, 0)
CODEGENOPT(DebugNameTable, 2, 0)

CODEGENOPT(NoPLT, 1, 0)

Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,8 @@ void CGDebugInfo::CreateCompileUnit() {
0 /* DWOid */, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
CGM.getTarget().getTriple().isNVPTX()
? llvm::DICompileUnit::DebugNameTableKind::None
: CGOpts.GnuPubnames
? llvm::DICompileUnit::DebugNameTableKind::GNU
: llvm::DICompileUnit::DebugNameTableKind::Default);
: static_cast<llvm::DICompileUnit::DebugNameTableKind>(
CGOpts.DebugNameTable));
}

llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
Expand Down
17 changes: 12 additions & 5 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3060,11 +3060,18 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
CmdArgs.push_back("-debug-info-macro");

// -ggnu-pubnames turns on gnu style pubnames in the backend.
if (Args.hasFlag(options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames,
false))
if (checkDebugInfoOption(Args.getLastArg(options::OPT_ggnu_pubnames), Args,
D, TC))
CmdArgs.push_back("-ggnu-pubnames");
const auto *PubnamesArg =
Args.getLastArg(options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames,
options::OPT_gpubnames, options::OPT_gno_pubnames);
if (SplitDWARFArg ||
(PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC)))
if (!PubnamesArg ||
(!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
!PubnamesArg->getOption().matches(options::OPT_gno_pubnames)))
CmdArgs.push_back(PubnamesArg && PubnamesArg->getOption().matches(
options::OPT_gpubnames)
? "-gpubnames"
: "-ggnu-pubnames");

// -gdwarf-aranges turns on the emission of the aranges section in the
// backend.
Expand Down
8 changes: 7 additions & 1 deletion clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/Linker/Linker.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Option/Arg.h"
Expand Down Expand Up @@ -643,7 +644,12 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
Opts.DebugInfoForProfiling = Args.hasFlag(
OPT_fdebug_info_for_profiling, OPT_fno_debug_info_for_profiling, false);
Opts.GnuPubnames = Args.hasArg(OPT_ggnu_pubnames);
Opts.DebugNameTable = static_cast<unsigned>(
Args.hasArg(OPT_ggnu_pubnames)
? llvm::DICompileUnit::DebugNameTableKind::GNU
: Args.hasArg(OPT_gpubnames)
? llvm::DICompileUnit::DebugNameTableKind::Default
: llvm::DICompileUnit::DebugNameTableKind::None);

setPGOInstrumentor(Opts, Args, Diags);
Opts.InstrProfileOutput =
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGen/debug-info-global-constant.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// CHECK: @i = internal constant i32 1, align 4, !dbg ![[I:[0-9]+]]
// CHECK: ![[I]] = !DIGlobalVariableExpression(var: ![[VAR:.*]], expr: !DIExpression(DW_OP_constu, 1, DW_OP_stack_value))
// CHECK: ![[VAR]] = distinct !DIGlobalVariable(name: "i",
// CHECK: !DICompileUnit({{.*}}globals: ![[GLOBALS:[0-9]+]])
// CHECK: !DICompileUnit({{.*}}globals: ![[GLOBALS:[0-9]+]]
// CHECK: ![[GLOBALS]] = !{![[I]]}
static const int i = 1;

Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGen/debug-info-macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// NO_MACRO-NOT: DIMacro
// NO_MACRO-NOT: DIMacroFile

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

// NO_PCH: [[Macros]] = !{[[MainMacroFile:![0-9]+]], [[BuiltinMacro:![0-9]+]], {{.*}}, [[DefineC1:![0-9]+]], [[DefineA:![0-9]+]], [[UndefC1:![0-9]+]]}
Expand Down
10 changes: 10 additions & 0 deletions clang/test/CodeGen/debug-info-names.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -gpubnames | FileCheck --check-prefix=DEFAULT %s
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -ggnu-pubnames | FileCheck --check-prefix=GNU %s

// CHECK: !DICompileUnit({{.*}}, nameTableKind: None
// DEFAULT-NOT: !DICompileUnit({{.*}}, nameTableKind:
// GNU: !DICompileUnit({{.*}}, nameTableKind: GNU

void f1() {
}
22 changes: 17 additions & 5 deletions clang/test/Driver/debug-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,18 @@
// RUN: %clang -### -c -gstrict-dwarf -gno-strict-dwarf %s 2>&1 \
// RUN: | FileCheck -check-prefix=GIGNORE %s
//
// RUN: %clang -### -c -ggnu-pubnames %s 2>&1 | FileCheck -check-prefix=GOPT %s
// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOGOPT %s
// RUN: %clang -### -c -ggnu-pubnames -gno-gnu-pubnames %s 2>&1 | FileCheck -check-prefix=NOGOPT %s
// RUN: %clang -### -c -ggnu-pubnames %s 2>&1 | FileCheck -check-prefix=GPUB %s
// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOPUB %s
// RUN: %clang -### -c -ggnu-pubnames -gno-gnu-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
// RUN: %clang -### -c -ggnu-pubnames -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
//
// RUN: %clang -### -c -gpubnames %s 2>&1 | FileCheck -check-prefix=PUB %s
// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOPUB %s
// RUN: %clang -### -c -gpubnames -gno-gnu-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
// RUN: %clang -### -c -gpubnames -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
//
// RUN: %clang -### -c -gsplit-dwarf %s 2>&1 | FileCheck -check-prefix=GPUB %s
// RUN: %clang -### -c -gsplit-dwarf -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
//
// RUN: %clang -### -c -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=GARANGE %s
//
Expand Down Expand Up @@ -229,8 +238,11 @@
//
// GIGNORE-NOT: "argument unused during compilation"
//
// GOPT: -ggnu-pubnames
// NOGOPT-NOT: -ggnu-pubnames
// GPUB: -ggnu-pubnames
// NOPUB-NOT: -ggnu-pubnames
// NOPUB-NOT: -gpubnames
//
// PUB: -gpubnames
//
// GARANGE: -generate-arange-section
//
Expand Down

0 comments on commit 6586452

Please sign in to comment.