aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Driver/CC1AsOptions.td3
-rw-r--r--lib/Driver/Tools.cpp31
-rw-r--r--test/Driver/debug-comp-dir.S11
-rw-r--r--tools/driver/cc1as_main.cpp4
4 files changed, 39 insertions, 10 deletions
diff --git a/include/clang/Driver/CC1AsOptions.td b/include/clang/Driver/CC1AsOptions.td
index 9fd855a9ce..620d721506 100644
--- a/include/clang/Driver/CC1AsOptions.td
+++ b/include/clang/Driver/CC1AsOptions.td
@@ -86,5 +86,8 @@ def fatal_warnings : Flag<["--"], "fatal-warnings">,
def g : Flag<["-"], "g">, HelpText<"Generate source level debug information">;
+def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">,
+ HelpText<"The compilation directory to embed in the debug info.">;
+
def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
HelpText<"The string to embed in the Dwarf debug flags record.">;
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 2737c1a88a..bbc3cccef3 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1611,6 +1611,20 @@ static bool shouldUseFramePointer(const ArgList &Args,
return true;
}
+/// If the PWD environment variable is set, add a CC1 option to specify the
+/// debug compilation directory.
+static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs) {
+ if (const char *pwd = ::getenv("PWD")) {
+ // GCC also verifies that stat(pwd) and stat(".") have the same inode
+ // number. Not doing those because stats are slow, but we could.
+ if (llvm::sys::path::is_absolute(pwd)) {
+ std::string CompDir = pwd;
+ CmdArgs.push_back("-fdebug-compilation-dir");
+ CmdArgs.push_back(Args.MakeArgString(CompDir));
+ }
+ }
+}
+
void Clang::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
@@ -2362,15 +2376,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (ShouldDisableDwarfDirectory(Args, getToolChain()))
CmdArgs.push_back("-fno-dwarf-directory-asm");
- if (const char *pwd = ::getenv("PWD")) {
- // GCC also verifies that stat(pwd) and stat(".") have the same inode
- // number. Not doing those because stats are slow, but we could.
- if (llvm::sys::path::is_absolute(pwd)) {
- std::string CompDir = pwd;
- CmdArgs.push_back("-fdebug-compilation-dir");
- CmdArgs.push_back(Args.MakeArgString(CompDir));
- }
- }
+ // Add in -fdebug-compilation-dir if necessary.
+ addDebugCompDirArg(Args, CmdArgs);
if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_,
options::OPT_ftemplate_depth_EQ)) {
@@ -3295,13 +3302,17 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
SourceAction = SourceAction->getInputs()[0];
}
- // Forward -g, assuming we are dealing with an actual assembly file.
+ // Forward -g and handle debug info related flags, assuming we are dealing
+ // with an actual assembly file.
if (SourceAction->getType() == types::TY_Asm ||
SourceAction->getType() == types::TY_PP_Asm) {
Args.ClaimAllArgs(options::OPT_g_Group);
if (Arg *A = Args.getLastArg(options::OPT_g_Group))
if (!A->getOption().matches(options::OPT_g0))
CmdArgs.push_back("-g");
+
+ // Add the -fdebug-compilation-dir flag if needed.
+ addDebugCompDirArg(Args, CmdArgs);
}
// Optionally embed the -cc1as level arguments into the debug info, for build
diff --git a/test/Driver/debug-comp-dir.S b/test/Driver/debug-comp-dir.S
new file mode 100644
index 0000000000..ca1ca30ae6
--- /dev/null
+++ b/test/Driver/debug-comp-dir.S
@@ -0,0 +1,11 @@
+// RUN: cd %S && %clang -### -g %s -c 2>&1 | FileCheck -check-prefix=CHECK-PWD %s
+// CHECK-PWD: {{"-fdebug-compilation-dir" ".*Driver.*"}}
+
+// RUN: env PWD=/foo %clang -### -g %s -c 2>&1 | FileCheck -check-prefix=CHECK-FOO %s
+// CHECK-FOO: {{"-fdebug-compilation-dir" ".*foo"}}
+
+// "PWD=/foo gcc" wouldn't necessarily work. You would need to pick a different
+// path to the same directory (try a symlink).
+
+// This depends on host's behavior how $PWD would be set.
+// REQUIRES: shell
diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp
index 87e3bfba84..73be56c2b4 100644
--- a/tools/driver/cc1as_main.cpp
+++ b/tools/driver/cc1as_main.cpp
@@ -83,6 +83,7 @@ struct AssemblerInvocation {
unsigned SaveTemporaryLabels : 1;
unsigned GenDwarfForAssembly : 1;
std::string DwarfDebugFlags;
+ std::string DebugCompilationDir;
/// @}
/// @name Frontend Options
@@ -181,6 +182,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
Opts.SaveTemporaryLabels = Args->hasArg(OPT_L);
Opts.GenDwarfForAssembly = Args->hasArg(OPT_g);
Opts.DwarfDebugFlags = Args->getLastArgValue(OPT_dwarf_debug_flags);
+ Opts.DebugCompilationDir = Args->getLastArgValue(OPT_fdebug_compilation_dir);
// Frontend Options
if (Args->hasArg(OPT_INPUT)) {
@@ -305,6 +307,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
Ctx.setGenDwarfForAssembly(true);
if (!Opts.DwarfDebugFlags.empty())
Ctx.setDwarfDebugFlags(StringRef(Opts.DwarfDebugFlags));
+ if (!Opts.DebugCompilationDir.empty())
+ Ctx.setCompilationDir(Opts.DebugCompilationDir);
// Build up the feature string from the target feature list.
std::string FS;