[cfe-commits] r145467 - /cfe/trunk/lib/Driver/Tools.cpp
Kostya Serebryany
kcc at google.com
Tue Nov 29 17:39:16 PST 2011
Author: kcc
Date: Tue Nov 29 19:39:16 2011
New Revision: 145467
URL: http://llvm.org/viewvc/llvm-project?rev=145467&view=rev
Log:
when -faddress-sanitizer is present, add required flags to the linker command (linux-only)
Modified:
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=145467&r1=145466&r2=145467&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Nov 29 19:39:16 2011
@@ -1090,6 +1090,27 @@
RelaxDefault);
}
+/// If AddressSanitizer is enabled, add appropriate linker flags (Linux).
+/// This needs to be called before we add the C run-time (malloc, etc).
+static void addAsanRTLinux(const ToolChain &TC, const ArgList &Args,
+ ArgStringList &CmdArgs) {
+ // Add asan linker flags when linking an executable, but not a shared object.
+ if (Args.hasArg(options::OPT_shared) ||
+ !Args.hasFlag(options::OPT_faddress_sanitizer,
+ options::OPT_fno_address_sanitizer, false))
+ return;
+ // LibAsan is "../lib/clang/linux/ArchName/libclang_rt.asan.a
+ llvm::SmallString<128> LibAsan =
+ llvm::sys::path::parent_path(StringRef(TC.getDriver().Dir));
+ llvm::sys::path::append(LibAsan, "lib", "clang", "linux", TC.getArchName());
+ llvm::sys::path::append(LibAsan, "libclang_rt.asan.a");
+ CmdArgs.push_back(Args.MakeArgString(LibAsan));
+ CmdArgs.push_back("-lpthread");
+ CmdArgs.push_back("-ldl");
+ CmdArgs.push_back("-export-dynamic");
+ TC.AddCXXStdlibLibArgs(Args, CmdArgs);
+}
+
void Clang::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
@@ -4443,6 +4464,9 @@
CmdArgs.push_back("-lm");
}
+ // Call this before we add the C run-time.
+ addAsanRTLinux(getToolChain(), Args, CmdArgs);
+
if (!Args.hasArg(options::OPT_nostdlib)) {
if (Args.hasArg(options::OPT_static))
CmdArgs.push_back("--start-group");
More information about the cfe-commits
mailing list