summaryrefslogtreecommitdiffstats
path: root/clang/lib/Driver/Tools.cpp
diff options
context:
space:
mode:
authorMatt Beaumont-Gay <matthewbg@google.com>2012-12-04 21:18:26 +0000
committerMatt Beaumont-Gay <matthewbg@google.com>2012-12-04 21:18:26 +0000
commit35439dff76c4c6ccbed39182ba818ecbca179dac (patch)
treed40e3f1a40007b499a390e1f141e3683154f8841 /clang/lib/Driver/Tools.cpp
parentf75e74f67eef1f2effccb5e6668b640437c7eb61 (diff)
downloadbcm5719-llvm-35439dff76c4c6ccbed39182ba818ecbca179dac.tar.gz
bcm5719-llvm-35439dff76c4c6ccbed39182ba818ecbca179dac.zip
Currently, with -fsanitize=address, the driver appends libclang_rt.asan.a to
the link command. This all works fine when the driver is also responsible for adding -lstdc++ to the link command. But, if -lstdc++ (or libstdc++.a, etc) is passed explicitly to the driver, the ASan runtime will appear in the link command after the standard library, leading to multiple-definition errors for the global 'operator new' and 'operator delete'. Fix this in a painfully simple way, by inserting libclang_rt.asan.a at the start of the link command instead of the end. If we need to do something more clever, we can walk the link command looking for something that resembles libstdc++ and insert libclang_rt.asan.a as late as possible, but the simple solution works for now. llvm-svn: 169310
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
-rw-r--r--clang/lib/Driver/Tools.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index ab001182440..92f41063e2d 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -1512,7 +1512,7 @@ static void addAsanRTLinux(const ToolChain &TC, const ArgList &Args,
llvm::sys::path::append(LibAsan, "lib", "linux",
(Twine("libclang_rt.asan-") +
TC.getArchName() + "-android.so"));
- CmdArgs.push_back(Args.MakeArgString(LibAsan));
+ CmdArgs.insert(CmdArgs.begin(), Args.MakeArgString(LibAsan));
} else {
if (!Args.hasArg(options::OPT_shared)) {
// LibAsan is "libclang_rt.asan-<ArchName>.a" in the Linux library
@@ -1521,7 +1521,11 @@ static void addAsanRTLinux(const ToolChain &TC, const ArgList &Args,
llvm::sys::path::append(LibAsan, "lib", "linux",
(Twine("libclang_rt.asan-") +
TC.getArchName() + ".a"));
- CmdArgs.push_back(Args.MakeArgString(LibAsan));
+ // The ASan runtime needs to come before -lstdc++ (or -lc++, libstdc++.a,
+ // etc.) so that the linker picks ASan's versions of the global 'operator
+ // new' and 'operator delete' symbols. We take the extreme (but simple)
+ // strategy of inserting it at the front of the link command.
+ CmdArgs.insert(CmdArgs.begin(), Args.MakeArgString(LibAsan));
CmdArgs.push_back("-lpthread");
CmdArgs.push_back("-ldl");
CmdArgs.push_back("-export-dynamic");
OpenPOWER on IntegriCloud