[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-04-22 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert updated this revision to Diff 196149.
aaronpuchert added a comment.

Introduce -split-dwarf-output instead to mirror the behavior of llc, which 
already allows to set the attribute separately from the output file name.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59673/new/

https://reviews.llvm.org/D59673

Files:
  include/clang/Basic/CodeGenOptions.def
  include/clang/Basic/CodeGenOptions.h
  include/clang/Driver/CC1Options.td
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/split-debug-filename.c
  test/CodeGen/split-debug-output.c
  test/CodeGen/split-debug-single-file.c
  test/Driver/split-debug.c
  test/Misc/cc1as-split-dwarf.s
  tools/driver/cc1as_main.cpp

Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -98,7 +98,7 @@
   llvm::DebugCompressionType CompressDebugSections =
   llvm::DebugCompressionType::None;
   std::string MainFileName;
-  std::string SplitDwarfFile;
+  std::string SplitDwarfOutput;
 
   /// @}
   /// @name Frontend Options
@@ -258,7 +258,7 @@
   }
   Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
   Opts.OutputPath = Args.getLastArgValue(OPT_o);
-  Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
+  Opts.SplitDwarfOutput = Args.getLastArgValue(OPT_split_dwarf_output);
   if (Arg *A = Args.getLastArg(OPT_filetype)) {
 StringRef Name = A->getValue();
 unsigned OutputType = StringSwitch(Name)
@@ -367,8 +367,8 @@
   if (!FDOS)
 return true;
   std::unique_ptr DwoOS;
-  if (!Opts.SplitDwarfFile.empty())
-DwoOS = getOutputStream(Opts.SplitDwarfFile, Diags, IsBinary);
+  if (!Opts.SplitDwarfOutput.empty())
+DwoOS = getOutputStream(Opts.SplitDwarfOutput, Diags, IsBinary);
 
   // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
   // MCObjectFileInfo needs a MCContext reference in order to initialize itself.
@@ -527,8 +527,8 @@
   if (Failed) {
 if (Opts.OutputPath != "-")
   sys::fs::remove(Opts.OutputPath);
-if (!Opts.SplitDwarfFile.empty() && Opts.SplitDwarfFile != "-")
-  sys::fs::remove(Opts.SplitDwarfFile);
+if (!Opts.SplitDwarfOutput.empty() && Opts.SplitDwarfOutput != "-")
+  sys::fs::remove(Opts.SplitDwarfOutput);
   }
 
   return Failed;
Index: test/Misc/cc1as-split-dwarf.s
===
--- test/Misc/cc1as-split-dwarf.s
+++ test/Misc/cc1as-split-dwarf.s
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang -cc1as -triple x86_64-pc-linux-gnu %s -filetype obj -o %t1 -split-dwarf-file %t2
+// RUN: %clang -cc1as -triple x86_64-pc-linux-gnu %s -filetype obj -o %t1 -split-dwarf-output %t2
 // RUN: llvm-objdump -s %t1 | FileCheck --check-prefix=O %s
 // RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DWO %s
 
Index: test/Driver/split-debug.c
===
--- test/Driver/split-debug.c
+++ test/Driver/split-debug.c
@@ -3,7 +3,7 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
 //
-// CHECK-ACTIONS: "-split-dwarf-file" "split-debug.dwo"
+// CHECK-ACTIONS: "-split-dwarf-file" "split-debug.dwo" "-split-dwarf-output" "split-debug.dwo"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
@@ -13,13 +13,15 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=single -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ACTIONS-SINGLE-SPLIT < %t %s
 //
-// CHECK-ACTIONS-SINGLE-SPLIT: "-enable-split-dwarf=single"
+// CHECK-ACTIONS-SINGLE-SPLIT: "-enable-split-dwarf"
 // CHECK-ACTIONS-SINGLE-SPLIT: "-split-dwarf-file" "split-debug.o"
+// CHECK-ACTIONS-SINGLE-SPLIT-NOT: "-split-dwarf-output"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=single -c -### -o %tfoo.o %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-SINGLE-SPLIT-FILENAME < %t %s
 //
 // CHECK-SINGLE-SPLIT-FILENAME: "-split-dwarf-file" "{{.*}}foo.o"
+// CHECK-SINGLE-SPLIT-FILENAME-NOT: "-split-dwarf-output"
 
 // RUN: %clang -target x86_64-macosx -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-NO-ACTIONS < %t %s
@@ -41,7 +43,7 @@
 // RUN: %clang -target amdgcn-amd-amdhsa -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-OPTION < %t %s
 //
-// CHECK-OPTION: "-split-dwarf-file" "split-debug.dwo"
+// CHECK-OPTION: "-split-dwarf-file" "split-debug.dwo" "-split-dwarf-output" "split-debug.dwo"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ASM < %t %s
@@ -59,6 +61,7 @@
 // CHECK-GMLT-WITH-SPLIT: "-enable-split-dwarf"
 // CHECK-GMLT-WITH-SPLIT: 

[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-04-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D59673#1465975 , @aaronpuchert 
wrote:

> In D59673#1461983 , @dblaikie wrote:
>
> > Sure, I think the naming's a bit weird (but hard to come up with good names 
> > for any of this)
>
>
> Agreed, `-split-dwarf-output` is pretty clear, but `-split-dwarf-file` could 
> be both the actual filename or the attribute.
>
> There is `test/CodeGen/split-debug-filename.c` checking that we emit 
> `!DICompileUnit({{.*}}, splitDebugFilename: "foo.dwo"` into the IR under some 
> circumstances, but I'm not sure why. It seems to be ignored by `llc`.


For implicit modular debug info I think it probably isn't ignored. See 
DwarfDebug.cpp:~630.

> What's the intended use for this? Your commit message in rC301063 
>  suggests that this is needed for implicit 
> modules. How does this work? I'm asking of course because I'm not sure 
> whether we might need to emit both file names there.

So implicit modules can use a sort of pseudo-split DWARF. The .pcm (module 
file) itself is an object file in this mode - with the split DWARF and a 
section containing the AST bitcode. Then in the normal source files that use 
the .pcm, they get the usual non-split DWARF, plus skeleton CUs that reference 
the .pcm file (& contain some other attributes for regenerating it in case it's 
been cleaned up from the module cache). This is why the file name can be (& has 
to be) passed down through the IR - it /can/ be, because this compilation isn't 
choosing tnhe file name (so there's no issue with the .dwo file name changing 
between IR generation and object generation (as there is with LTO - where the 
compilation doesn't know the final object name, only the linker knows that)) 
and it /must/ be done this way due to multiple skeleton CUs if the main CU 
references multiple .pcm debug info.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59673/new/

https://reviews.llvm.org/D59673



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-04-14 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert planned changes to this revision.
aaronpuchert added a comment.

In D59673#1461983 , @dblaikie wrote:

> Sure, I think the naming's a bit weird (but hard to come up with good names 
> for any of this)


Agreed, `-split-dwarf-output` is pretty clear, but `-split-dwarf-file` could be 
both the actual filename or the attribute.

There is `test/CodeGen/split-debug-filename.c` checking that we emit 
`!DICompileUnit({{.*}}, splitDebugFilename: "foo.dwo"` into the IR under some 
circumstances, but I'm not sure why. It seems to be ignored by `llc`. What's 
the intended use for this? Your commit message in rC301063 
 suggests that this is needed for implicit 
modules. How does this work? I'm asking of course because I'm not sure whether 
we might need to emit both file names there.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59673/new/

https://reviews.llvm.org/D59673



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-04-10 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D59673#1460605 , @aaronpuchert 
wrote:

> Ok, here is an idea. We introduce `-split-dwarf-output` in Clang instead of 
> `-fsplit-dwarf-dwo-name-attr`. If given, it overrides the output file name 
> for the Split DWARF file, which we otherwise take from `-split-dwarf-file`. 
> The option is obviously incompatible with `-enable-split-dwarf=single`, so we 
> will disallow that. This should be backwards-compatible, and bring the 
> behavior of `llc` and `clang -cc1` closer together. What do you think?


Sure, I think the naming's a bit weird (but hard to come up with good names for 
any of this) - but consistency seems like a good first pass at least, given 
we're halfway there anyway.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59673/new/

https://reviews.llvm.org/D59673



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-04-09 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Ok, here is an idea. We introduce `-split-dwarf-output` in Clang instead of 
`-fsplit-dwarf-dwo-name-attr`. If given, it overrides the output file name for 
the Split DWARF file, which we otherwise take from `-split-dwarf-file`. The 
option is obviously incompatible with `-enable-split-dwarf=single`, so we will 
disallow that. This should be backwards-compatible, and bring the behavior of 
`llc` and `clang -cc1` closer together. What do you think?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59673/new/

https://reviews.llvm.org/D59673



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-04-07 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D59673#1452269 , @dblaikie wrote:

> Ah, fair. You could actually test the dwo_name is accurate in the .dwo file 
> (I added the dwo_name to the .dwo file so that multi-level dwp error messages 
> could be more informative)


Ok, I'll just check the dwo_name for both files then.

>>> (& I guess there's an LLVM patch to add the rest of this functionality?)
>> 
>> What do we have to do there? Should we add the option to `llc` as well?
> 
> Yep - pretty much anything in MCOptions should be surfaced through llc for 
> llvm-level testing.

I was about to add this when I discovered that there is such an option already. 
The command line `clang -cc1 -split-dwarf-file a -fsplit-dwarf-dwo-name-attr b` 
corresponds to `llc -split-dwarf-output a -split-dwarf-file b`. That seems a 
bit unfortunate, especially the different meanings of `-split-dwarf-file`. 
Should/can we strive to emulate the behavior of llc in Clang instead? That 
would perhaps require changes to the behavior of `-split-dwarf-file`. Here's 
how the options behave with llc:

| Option  | ∅| `-split-dwarf-file a`
|
| ∅   | No split | Split DI in same object, set 
`DW_AT_GNU_dwo_name = a`, no extra file |
| `-split-dwarf-output b` | No split | Split DI, set `DW_AT_GNU_dwo_name = a`, 
separate file `b`|
|

Currently, Clang's `-enable-split-dwarf[=split] -split-dwarf-file a` does the 
same as `-split-dwarf-output a -split-dwarf-file a` in llc, and 
`-enable-split-dwarf=single -split-dwarf-file a` does the same as 
`-split-dwarf-file a` in llc.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59673/new/

https://reviews.llvm.org/D59673



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-04-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D59673#143 , @aaronpuchert 
wrote:

> In D59673#1438716 , @dblaikie wrote:
>
> > Use llvm-dwarfdump rather than llvm-objdump to dump the contents of the 
> > debug_info section and test the dwo_name there (rather than dumping hex)
>
>
> I didn't know about llvm-dwarfdump, I wondered why llvm-objdump wouldn't 
> pretty-print the debug info as objdump does. That makes a lot of sense then.
>
> > probably the objdump part of the test isn't needed?
>
> Actually I only need to check that the DWO file is there (under the proper 
> file name). Any ideas?


Ah, fair. You could actually test the dwo_name is accurate in the .dwo file (I 
added the dwo_name to the .dwo file so that multi-level dwp error messages 
could be more informative)

>> (& I guess there's an LLVM patch to add the rest of this functionality?)
> 
> What do we have to do there? Should we add the option to `llc` as well?

Yep - pretty much anything in MCOptions should be surfaced through llc for 
llvm-level testing.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59673/new/

https://reviews.llvm.org/D59673



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-03-21 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert updated this revision to Diff 191813.
aaronpuchert added a comment.

Use llvm-dwarfdump to inspect debug info, remove unneeded flags.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59673/new/

https://reviews.llvm.org/D59673

Files:
  include/clang/Basic/CodeGenOptions.h
  include/clang/Driver/Options.td
  lib/CodeGen/BackendUtil.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/split-debug-dwo-name-attr.c


Index: test/CodeGen/split-debug-dwo-name-attr.c
===
--- /dev/null
+++ test/CodeGen/split-debug-dwo-name-attr.c
@@ -0,0 +1,8 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -debug-info-kind=limited 
-enable-split-dwarf -split-dwarf-file %t -fsplit-dwarf-dwo-name-attr=foo.dwo 
-emit-obj -o - %s | llvm-dwarfdump -debug-info - | FileCheck %s
+// RUN: llvm-objdump -section-headers %t | FileCheck --check-prefix=DWO %s
+
+int f() { return 0; }
+
+// CHECK: DW_AT_GNU_dwo_name ("foo.dwo")
+// DWO: .dwo
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -714,6 +714,8 @@
   Opts.WholeProgramVTables = Args.hasArg(OPT_fwhole_program_vtables);
   Opts.LTOVisibilityPublicStd = Args.hasArg(OPT_flto_visibility_public_std);
   Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
+  Opts.SplitDwarfDwoNameAttr =
+  Args.getLastArgValue(OPT_fsplit_dwarf_dwo_name_attr_EQ);
   Opts.SplitDwarfInlining = !Args.hasArg(OPT_fno_split_dwarf_inlining);
 
   if (Arg *A =
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -464,7 +464,9 @@
   Options.EmitAddrsig = CodeGenOpts.Addrsig;
 
   if (CodeGenOpts.getSplitDwarfMode() != CodeGenOptions::NoFission)
-Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
+Options.MCOptions.SplitDwarfFile = 
CodeGenOpts.SplitDwarfDwoNameAttr.empty()
+   ? CodeGenOpts.SplitDwarfFile
+   : CodeGenOpts.SplitDwarfDwoNameAttr;
   Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
   Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
   Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm;
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1849,6 +1849,8 @@
   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_dwo_name_attr_EQ: Joined<["-"], 
"fsplit-dwarf-dwo-name-attr=">, Group,
+  Flags<[CC1Option]>, HelpText<"Set the name for the split debug info file to 
be used in the object file">;
 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,
Index: include/clang/Basic/CodeGenOptions.h
===
--- include/clang/Basic/CodeGenOptions.h
+++ include/clang/Basic/CodeGenOptions.h
@@ -188,6 +188,10 @@
   /// in the backend for setting the name in the skeleton cu.
   std::string SplitDwarfFile;
 
+  /// Overrides \ref SplitDwarfFile as value of DW_AT_[GNU_]dwo_name to be used
+  /// in the skeleton CU, if not empty. Does not change the output file name.
+  std::string SplitDwarfDwoNameAttr;
+
   /// The name of the relocation model to use.
   llvm::Reloc::Model RelocationModel;
 


Index: test/CodeGen/split-debug-dwo-name-attr.c
===
--- /dev/null
+++ test/CodeGen/split-debug-dwo-name-attr.c
@@ -0,0 +1,8 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -debug-info-kind=limited -enable-split-dwarf -split-dwarf-file %t -fsplit-dwarf-dwo-name-attr=foo.dwo -emit-obj -o - %s | llvm-dwarfdump -debug-info - | FileCheck %s
+// RUN: llvm-objdump -section-headers %t | FileCheck --check-prefix=DWO %s
+
+int f() { return 0; }
+
+// CHECK: DW_AT_GNU_dwo_name ("foo.dwo")
+// DWO: .dwo
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -714,6 +714,8 @@
   Opts.WholeProgramVTables = Args.hasArg(OPT_fwhole_program_vtables);
   Opts.LTOVisibilityPublicStd = 

[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-03-21 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D59673#1438716 , @dblaikie wrote:

> Use llvm-dwarfdump rather than llvm-objdump to dump the contents of the 
> debug_info section and test the dwo_name there (rather than dumping hex)


I didn't know about llvm-dwarfdump, I wondered why llvm-objdump wouldn't 
pretty-print the debug info as objdump does. That makes a lot of sense then.

> probably the objdump part of the test isn't needed?

Actually I only need to check that the DWO file is there (under the proper file 
name). Any ideas?

> (& I guess there's an LLVM patch to add the rest of this functionality?)

What do we have to do there? Should we add the option to `llc` as well?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59673/new/

https://reviews.llvm.org/D59673



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-03-21 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Pleasue include mention of the bug (PR40276) in the commit message & clarify 
that while this is useful for some remote compilation models, it's not strictly 
necessary/the only way to do it (a remote compilation model that keeps relative 
paths and uses compilation-dir instead can work without this attribute)

Use llvm-dwarfdump rather than llvm-objdump to dump the contents of the 
debug_info section and test the dwo_name there (rather than dumping hex) & 
probably the objdump part of the test isn't needed? (& I guess there's an LLVM 
patch to add the rest of this functionality?)


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59673/new/

https://reviews.llvm.org/D59673



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-03-21 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert created this revision.
aaronpuchert added reviewers: dblaikie, echristo.
Herald added subscribers: cfe-commits, jdoerfert, aprantl.
Herald added a project: clang.

With Split DWARF the resulting object file (then called skeleton CU)
contains the file name of another ("DWO") file with the debug info.
This is a problem for remote compilation, as the file name written there
will be that of the compilation server, not of the client.

To reliably enable Split DWARF in the case of of remote compilation, we
need the ability to inject arbitrary file names into this field, which
is now provided by the option

  -fsplit-dwarf-dwo-name-attr=

For now we keep this as CC1 option, but the idea is to promote it
eventually, if it picks up.


Repository:
  rC Clang

https://reviews.llvm.org/D59673

Files:
  include/clang/Basic/CodeGenOptions.h
  include/clang/Driver/Options.td
  lib/CodeGen/BackendUtil.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/split-debug-dwo-name-attr.c


Index: test/CodeGen/split-debug-dwo-name-attr.c
===
--- /dev/null
+++ test/CodeGen/split-debug-dwo-name-attr.c
@@ -0,0 +1,8 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -debug-info-kind=limited 
-enable-split-dwarf -fdebug-compilation-dir /foo 
-fsplit-dwarf-dwo-name-attr=bar.dwo -split-dwarf-file %t -emit-obj -o - %s | 
llvm-objdump -s -section=.debug_str - | FileCheck %s
+// RUN: llvm-objdump -section-headers %t | FileCheck --check-prefix=DWO %s
+
+int f() { return 0; }
+
+// CHECK:  2f666f6f 00626172 2e64776f 00/foo.bar.dwo.
+// DWO: .dwo
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -714,6 +714,8 @@
   Opts.WholeProgramVTables = Args.hasArg(OPT_fwhole_program_vtables);
   Opts.LTOVisibilityPublicStd = Args.hasArg(OPT_flto_visibility_public_std);
   Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
+  Opts.SplitDwarfDwoNameAttr =
+  Args.getLastArgValue(OPT_fsplit_dwarf_dwo_name_attr_EQ);
   Opts.SplitDwarfInlining = !Args.hasArg(OPT_fno_split_dwarf_inlining);
 
   if (Arg *A =
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -464,7 +464,9 @@
   Options.EmitAddrsig = CodeGenOpts.Addrsig;
 
   if (CodeGenOpts.getSplitDwarfMode() != CodeGenOptions::NoFission)
-Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
+Options.MCOptions.SplitDwarfFile = 
CodeGenOpts.SplitDwarfDwoNameAttr.empty()
+   ? CodeGenOpts.SplitDwarfFile
+   : CodeGenOpts.SplitDwarfDwoNameAttr;
   Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
   Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
   Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm;
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1849,6 +1849,8 @@
   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_dwo_name_attr_EQ: Joined<["-"], 
"fsplit-dwarf-dwo-name-attr=">, Group,
+  Flags<[CC1Option]>, HelpText<"Set the name for the split debug info file to 
be used in the object file">;
 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,
Index: include/clang/Basic/CodeGenOptions.h
===
--- include/clang/Basic/CodeGenOptions.h
+++ include/clang/Basic/CodeGenOptions.h
@@ -188,6 +188,10 @@
   /// in the backend for setting the name in the skeleton cu.
   std::string SplitDwarfFile;
 
+  /// Overrides \ref SplitDwarfFile as value of DW_AT_[GNU_]dwo_name to be used
+  /// in the skeleton CU, if not empty. Does not change the output file name.
+  std::string SplitDwarfDwoNameAttr;
+
   /// The name of the relocation model to use.
   llvm::Reloc::Model RelocationModel;
 


Index: test/CodeGen/split-debug-dwo-name-attr.c
===
--- /dev/null
+++ test/CodeGen/split-debug-dwo-name-attr.c
@@ -0,0 +1,8 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -debug-info-kind=limited -enable-split-dwarf -fdebug-compilation-dir