[+cfe-commits now that this has a patch.]

On 20 October 2011 14:59, Nick Lewycky <[email protected]> wrote:

> On 20 October 2011 14:55, Chandler Carruth <[email protected]> wrote:
>
>> On Thu, Oct 20, 2011 at 2:03 PM, Nick Lewycky <[email protected]>wrote:
>>
>>> To understand why, you first need to know that we run builds on hermetic
>>> build machines.
>>
>>
>> I'm not really sure why our build system is relevant here.
>>
>
>  Only because there are ways to fix that problem which would still break
> caching in our build system. I wanted to steer us away from that.
>
>
>>  This has been a problem for me many times using very mundane and ordinary
>> build systems. If I build on machine X and then copy the binary to machine
>> Y, it can't find the source code if it is stored in a different directory,
>> even if the directory structure is entirely compatible.
>>
>> Why can't we follow GCC's lead here, and use PWD (when on a system with
>> such a concept) as the basis for DW_AT_comp_dir? I think what I'm missing is
>> why doing that causes problems...
>>
>
> Works for me. I just want agreement for what to do (flag, using PWD,
> whatever). I honestly don't care how it works as long as it works. I can
> propose a patch using PWD if you want, the plumbing through -cc1 will be the
> same either way.
>

Ok, here's a patch that passes PWD through from the driver into the .bc, and
it comes out in the .o files. Yay!

Please review!

Nick

Nick
>
> Chris's objections (which seem reasonable) are to *always* using PWD. To be
>> clear, I'm not suggesting that. I'm suggesting that the Clang driver, which
>> is already quite aware of the user's shell, can inspect PWD and getcwd and
>> consult any other oracle needed to determine a valid working directory, and
>> then pass it via an internal-only flag to the CC1 layer IFF it differs from
>> getcwd.
>>
>
>
Index: include/clang/Frontend/CodeGenOptions.h
===================================================================
--- include/clang/Frontend/CodeGenOptions.h	(revision 142623)
+++ include/clang/Frontend/CodeGenOptions.h	(working copy)
@@ -115,6 +115,9 @@
   /// Enable additional debugging information.
   std::string DebugPass;
 
+  /// The string to embed in debug information as the current working directory.
+  std::string DwarfCompilationDir;
+
   /// The string to embed in the debug information for the compile unit, if
   /// non-empty.
   std::string DwarfDebugFlags;
Index: include/clang/Driver/CC1Options.td
===================================================================
--- include/clang/Driver/CC1Options.td	(revision 142623)
+++ include/clang/Driver/CC1Options.td	(working copy)
@@ -110,6 +110,8 @@
   HelpText<"Don't run the LLVM IR verifier pass">;
 def disable_red_zone : Flag<"-disable-red-zone">,
   HelpText<"Do not emit code that uses the red zone.">;
+def fdwarf_compilation_dir : Separate<"-fdwarf-compilation-dir">,
+  HelpText<"The string to embed in the Dwarf compilation directory record.">;
 def dwarf_debug_flags : Separate<"-dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">;
 def fforbid_guard_variables : Flag<"-fforbid-guard-variables">,
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp	(revision 142623)
+++ lib/Frontend/CompilerInvocation.cpp	(working copy)
@@ -131,6 +131,10 @@
     Res.push_back("-disable-llvm-optzns");
   if (Opts.DisableRedZone)
     Res.push_back("-disable-red-zone");
+  if (!Opts.DwarfCompilationDir.empty()) {
+    Res.push_back("-fdwarf-compilation-dir");
+    Res.push_back(Opts.DwarfCompilationDir);
+  }
   if (!Opts.DwarfDebugFlags.empty()) {
     Res.push_back("-dwarf-debug-flags");
     Res.push_back(Opts.DwarfDebugFlags);
@@ -1071,6 +1075,7 @@
   Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data);
   Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes);
   Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file);
+  Opts.DwarfCompilationDir = Args.getLastArgValue(OPT_fdwarf_compilation_dir);
 
   if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) {
     StringRef Name = A->getValue(Args);
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 142623)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -1625,6 +1625,12 @@
   if (ShouldDisableDwarfDirectory(Args, getToolChain()))
     CmdArgs.push_back("-fno-dwarf-directory-asm");
 
+  if (const char *pwd = getenv("PWD")) {
+    std::string CompDir = pwd;
+    CmdArgs.push_back("-fdwarf-compilation-dir");
+    CmdArgs.push_back(Args.MakeArgString(CompDir));
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) {
     CmdArgs.push_back("-ftemplate-depth");
     CmdArgs.push_back(A->getValue(Args));
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp	(revision 142623)
+++ lib/CodeGen/CGDebugInfo.cpp	(working copy)
@@ -250,6 +250,8 @@
 }
 
 StringRef CGDebugInfo::getCurrentDirname() {
+  if (!CGM.getCodeGenOpts().DwarfCompilationDir.empty())
+    return CGM.getCodeGenOpts().DwarfCompilationDir;
   if (!CWDName.empty())
     return CWDName;
   llvm::SmallString<256> CWD;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to