From: David Blaikie Date: Mon, 20 Aug 2018 20:14:08 +0000 (+0000) Subject: DebugInfo: Add the ability to disable DWARF name tables entirely X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6eed53ab5d3c252224d1df79d930d6ee04193195;p=clang 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) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340206 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 4a871b14cb..4f648dd958 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -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">; diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 42db773e9f..2dbf7c52eb 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -1807,6 +1807,8 @@ def gno_column_info : Flag<["-"], "gno-column-info">, Group, Flag def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, Group; def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group, Flags<[CC1Option]>; def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group, Flags<[CC1Option]>; +def gpubnames : Flag<["-"], "gpubnames">, Group, Flags<[CC1Option]>; +def gno_pubnames : Flag<["-"], "gno-pubnames">, Group, Flags<[CC1Option]>; def gdwarf_aranges : Flag<["-"], "gdwarf-aranges">, Group; def gmodules : Flag <["-"], "gmodules">, Group, HelpText<"Generate debug info with external references to clang modules" diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 02997d9a16..06aeea0ab8 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -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) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index dbf6ae5dc8..02d716abd6 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -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( + CGOpts.DebugNameTable)); } llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) { diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 66b9082b2a..68ad03d7ef 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -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. diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index a4beeabdae..ded2d42199 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -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" @@ -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( + 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 = diff --git a/test/CodeGen/debug-info-global-constant.c b/test/CodeGen/debug-info-global-constant.c index 8cb7f44ff3..7da33aedbb 100644 --- a/test/CodeGen/debug-info-global-constant.c +++ b/test/CodeGen/debug-info-global-constant.c @@ -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; diff --git a/test/CodeGen/debug-info-macro.c b/test/CodeGen/debug-info-macro.c index 889c7ffdba..7f7358d04b 100644 --- a/test/CodeGen/debug-info-macro.c +++ b/test/CodeGen/debug-info-macro.c @@ -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]+]]} diff --git a/test/CodeGen/debug-info-names.c b/test/CodeGen/debug-info-names.c new file mode 100644 index 0000000000..bcfc998609 --- /dev/null +++ b/test/CodeGen/debug-info-names.c @@ -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() { +} diff --git a/test/Driver/debug-options.c b/test/Driver/debug-options.c index 0dd32e983a..0435d3ab59 100644 --- a/test/Driver/debug-options.c +++ b/test/Driver/debug-options.c @@ -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 // @@ -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 //