]> granicus.if.org Git - clang/commitdiff
DebugInfo: Add a driver flag for DWARF debug_ranges base address specifier use.
authorDavid Blaikie <dblaikie@gmail.com>
Tue, 13 Nov 2018 20:08:13 +0000 (20:08 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Tue, 13 Nov 2018 20:08:13 +0000 (20:08 +0000)
Summary:
This saves a lot of relocations in optimized object files (at the cost
of some cost/increase in linked executable bytes), but gold's 32 bit
gdb-index support has a bug (
https://sourceware.org/bugzilla/show_bug.cgi?id=21894 ) so we can't
switch to this unconditionally. (& even if it weren't for that bug, one
might argue that some users would want to optimize in one direction or
the other - prioritizing object size or linked executable size)

Differential Revision: https://reviews.llvm.org/D54243

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346789 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Options.td
include/clang/Frontend/CodeGenOptions.def
lib/CodeGen/CGDebugInfo.cpp
lib/Driver/ToolChains/Clang.cpp
lib/Frontend/CompilerInvocation.cpp
test/CodeGen/debug-info-ranges-base-address.c [new file with mode: 0644]
test/Driver/debug-options.c

index cc9f21e2ad840683239fc29a0d6142adbb889b34..2463d7bb8d838cf044e9c6e0d04a0fac4f791ccb 100644 (file)
@@ -1780,6 +1780,10 @@ def fdebug_types_section: Flag <["-"], "fdebug-types-section">, Group<f_Group>,
   Flags<[CC1Option]>, HelpText<"Place debug types in their own section (ELF Only)">;
 def fno_debug_types_section: Flag<["-"], "fno-debug-types-section">, Group<f_Group>,
   Flags<[CC1Option]>;
+def fdebug_ranges_base_address: Flag <["-"], "fdebug-ranges-base-address">, Group<f_Group>,
+  Flags<[CC1Option]>, HelpText<"Use DWARF base address selection entries in debug_ranges">;
+def fno_debug_ranges_base_address: Flag <["-"], "fno-debug-ranges-base-address">, Group<f_Group>,
+  Flags<[CC1Option]>;
 def fsplit_dwarf_inlining: Flag <["-"], "fsplit-dwarf-inlining">, Group<f_Group>,
   Flags<[CC1Option]>, HelpText<"Provide minimal debug info in the object/executable to facilitate online symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF">;
 def fno_split_dwarf_inlining: Flag<["-"], "fno-split-dwarf-inlining">, Group<f_Group>,
index 3687c590767437ebf8d6ac83c001f57b8861ef64..510dd1c31c78f87ab4cf90fe67946f40bd1a04bb 100644 (file)
@@ -331,6 +331,9 @@ CODEGENOPT(PreserveVec3Type, 1, 0)
 /// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
 CODEGENOPT(DebugNameTable, 2, 0)
 
+/// Whether to use DWARF base address specifiers in .debug_ranges.
+CODEGENOPT(DebugRangesBaseAddress, 1, 0)
+
 CODEGENOPT(NoPLT, 1, 0)
 
 /// Whether to embed source in DWARF debug line section.
index 81cc07dddd1029d3ef903a29c0bfa2e98f264b46..24c76c2037fd64c8d931bbd3366093403efc6eea 100644 (file)
@@ -586,7 +586,8 @@ void CGDebugInfo::CreateCompileUnit() {
       CGM.getTarget().getTriple().isNVPTX()
           ? llvm::DICompileUnit::DebugNameTableKind::None
           : static_cast<llvm::DICompileUnit::DebugNameTableKind>(
-                CGOpts.DebugNameTable));
+                CGOpts.DebugNameTable),
+      CGOpts.DebugRangesBaseAddress);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
index 8de20f6e2e6f22af3577f4dc348eae592af5f6fd..0e23aae2183fad91829009b38a853ca5b1cf7bc7 100644 (file)
@@ -3188,6 +3188,11 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
                             ? "-gpubnames"
                             : "-ggnu-pubnames");
 
+  if (Args.hasFlag(options::OPT_fdebug_ranges_base_address,
+                   options::OPT_fno_debug_ranges_base_address, false)) {
+    CmdArgs.push_back("-fdebug-ranges-base-address");
+  }
+
   // -gdwarf-aranges turns on the emission of the aranges section in the
   // backend.
   // Always enabled for SCE tuning.
index 7be183f9701cb62274e06b77b9c09031a2076258..32937d83fb4167b866500bc204521d1eac78825b 100644 (file)
@@ -651,6 +651,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
           : Args.hasArg(OPT_gpubnames)
                 ? llvm::DICompileUnit::DebugNameTableKind::Default
                 : llvm::DICompileUnit::DebugNameTableKind::None);
+  Opts.DebugRangesBaseAddress = Args.hasArg(OPT_fdebug_ranges_base_address);
 
   setPGOInstrumentor(Opts, Args, Diags);
   Opts.InstrProfileOutput =
diff --git a/test/CodeGen/debug-info-ranges-base-address.c b/test/CodeGen/debug-info-ranges-base-address.c
new file mode 100644 (file)
index 0000000..dee7cc5
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck --check-prefix=NORNGBSE %s
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -fdebug-ranges-base-address | FileCheck --check-prefix=RNGBSE %s
+
+// NORNGBSE-NOT: rangesBaseAddress
+// RNGBSE: !DICompileUnit({{.*}}, rangesBaseAddress: true
+
+void f1() {
+}
+
index ea9b7e734683bb8d158f6e5c3fd251863961253e..e6382983623431d2ae14ff4d49bed63635446137 100644 (file)
 // 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 -fdebug-ranges-base-address %s 2>&1 | FileCheck -check-prefix=RNGBSE %s
+// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
+// RUN: %clang -### -c -fdebug-ranges-base-address -fno-debug-ranges-base-address %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
+//
 // RUN: %clang -### -c -glldb %s 2>&1 | FileCheck -check-prefix=GPUB %s
 // RUN: %clang -### -c -glldb -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
 //
 //
 // PUB: -gpubnames
 //
+// RNGBSE: -fdebug-ranges-base-address
+// NORNGBSE-NOT: -fdebug-ranges-base-address
+//
 // GARANGE: -generate-arange-section
 //
 // FDTS: "-mllvm" "-generate-type-units"