Add -dwarf-debug-flags, which provides a way to embed the cc1 level options used
to compile a translation unit into the debug info for that file.
- Used by parts of Darwin build process to check compiler flags, etc.
- <rdar://problem/7256886> clang does not emit AT_APPLE_flags
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91661 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 420573d..0c2db8a 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -526,6 +526,12 @@
return getArchName() == "x86_64";
}
+bool Darwin::UseDwarfDebugFlags() const {
+ if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
+ return S[0] != '\0';
+ return false;
+}
+
const char *Darwin::GetDefaultRelocationModel() const {
return "pic";
}
diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
index fcd96f1..be36344 100644
--- a/lib/Driver/ToolChains.h
+++ b/lib/Driver/ToolChains.h
@@ -154,6 +154,8 @@
virtual const char *GetDefaultRelocationModel() const;
virtual const char *GetForcedPicModel() const;
+ virtual bool UseDwarfDebugFlags() const;
+
/// }
};
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 55008e3..d3c1b31 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1109,6 +1109,20 @@
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath(C, "clang"));
+
+ // Optionally embed the -cc1 level arguments into the debug info, for build
+ // analysis.
+ if (getToolChain().UseDwarfDebugFlags()) {
+ llvm::SmallString<256> Flags;
+ Flags += Exec;
+ for (unsigned i = 0, e = CmdArgs.size(); i != e; ++i) {
+ Flags += " ";
+ Flags += CmdArgs[i];
+ }
+ CmdArgs.push_back("-dwarf-debug-flags");
+ CmdArgs.push_back(Args.MakeArgString(Flags.str()));
+ }
+
Dest.addCommand(new Command(JA, *this, Exec, CmdArgs));
// Explicitly warn that these options are unsupported, even though