Re: r346789 - DebugInfo: Add a driver flag for DWARF debug_ranges base address specifier use.

2018-12-11 Thread David Blaikie via cfe-commits
(tiny factoid: turns out gold's 64 bit gdb-index support is also broken in
a different, more subtle way... - so best folks don't use this flag except
with lld, it seems, if you're using gdb-index)

On Tue, Nov 13, 2018 at 12:10 PM David Blaikie via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: dblaikie
> Date: Tue Nov 13 12:08:13 2018
> New Revision: 346789
>
> URL: http://llvm.org/viewvc/llvm-project?rev=346789=rev
> Log:
> DebugInfo: Add a driver flag for DWARF debug_ranges base address specifier
> use.
>
> 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
>
> Added:
> cfe/trunk/test/CodeGen/debug-info-ranges-base-address.c
> Modified:
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/include/clang/Frontend/CodeGenOptions.def
> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> cfe/trunk/test/Driver/debug-options.c
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=346789=346788=346789=diff
>
> ==
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Tue Nov 13 12:08:13 2018
> @@ -1780,6 +1780,10 @@ def fdebug_types_section: Flag <["-"], "
>Flags<[CC1Option]>, HelpText<"Place debug types in their own section
> (ELF Only)">;
>  def fno_debug_types_section: Flag<["-"], "fno-debug-types-section">,
> Group,
>Flags<[CC1Option]>;
> +def fdebug_ranges_base_address: Flag <["-"],
> "fdebug-ranges-base-address">, 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,
> +  Flags<[CC1Option]>;
>  def fsplit_dwarf_inlining: Flag <["-"], "fsplit-dwarf-inlining">,
> 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,
>
> Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=346789=346788=346789=diff
>
> ==
> --- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
> +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Nov 13
> 12:08:13 2018
> @@ -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.
>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=346789=346788=346789=diff
>
> ==
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Nov 13 12:08:13 2018
> @@ -586,7 +586,8 @@ void CGDebugInfo::CreateCompileUnit() {
>CGM.getTarget().getTriple().isNVPTX()
>? llvm::DICompileUnit::DebugNameTableKind::None
>: static_cast(
> -CGOpts.DebugNameTable));
> +CGOpts.DebugNameTable),
> +  CGOpts.DebugRangesBaseAddress);
>  }
>
>  llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=346789=346788=346789=diff
>
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Nov 13 12:08:13 2018
> @@ -3188,6 +3188,11 @@ static void RenderDebugOptions(const Too
>  ? "-gpubnames"
>  : "-ggnu-pubnames");
>
> +  if (Args.hasFlag(options::OPT_fdebug_ranges_base_address,
> +   

r346789 - DebugInfo: Add a driver flag for DWARF debug_ranges base address specifier use.

2018-11-13 Thread David Blaikie via cfe-commits
Author: dblaikie
Date: Tue Nov 13 12:08:13 2018
New Revision: 346789

URL: http://llvm.org/viewvc/llvm-project?rev=346789=rev
Log:
DebugInfo: Add a driver flag for DWARF debug_ranges base address specifier use.

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

Added:
cfe/trunk/test/CodeGen/debug-info-ranges-base-address.c
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/debug-options.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=346789=346788=346789=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Nov 13 12:08:13 2018
@@ -1780,6 +1780,10 @@ def fdebug_types_section: Flag <["-"], "
   Flags<[CC1Option]>, HelpText<"Place debug types in their own section (ELF 
Only)">;
 def fno_debug_types_section: Flag<["-"], "fno-debug-types-section">, 
Group,
   Flags<[CC1Option]>;
+def fdebug_ranges_base_address: Flag <["-"], "fdebug-ranges-base-address">, 
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,
+  Flags<[CC1Option]>;
 def fsplit_dwarf_inlining: Flag <["-"], "fsplit-dwarf-inlining">, 
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,

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=346789=346788=346789=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Nov 13 12:08:13 2018
@@ -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.

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=346789=346788=346789=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Nov 13 12:08:13 2018
@@ -586,7 +586,8 @@ void CGDebugInfo::CreateCompileUnit() {
   CGM.getTarget().getTriple().isNVPTX()
   ? llvm::DICompileUnit::DebugNameTableKind::None
   : static_cast(
-CGOpts.DebugNameTable));
+CGOpts.DebugNameTable),
+  CGOpts.DebugRangesBaseAddress);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=346789=346788=346789=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Nov 13 12:08:13 2018
@@ -3188,6 +3188,11 @@ static void RenderDebugOptions(const Too
 ? "-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.

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=346789=346788=346789=diff
==
---