diff options
-rw-r--r-- | lib/Driver/Tools.cpp | 10 | ||||
-rw-r--r-- | test/Driver/asan-ld.c | 4 |
2 files changed, 10 insertions, 4 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 92f41063e2..d5f191cf8a 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1524,8 +1524,14 @@ static void addAsanRTLinux(const ToolChain &TC, const ArgList &Args, // 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)); + // strategy of inserting it at the front of the link command. It also + // needs to be forced to end up in the executable, so wrap it in + // whole-archive. + SmallVector<const char*, 3> PrefixArgs; + PrefixArgs.push_back("-whole-archive"); + PrefixArgs.push_back(Args.MakeArgString(LibAsan)); + PrefixArgs.push_back("-no-whole-archive"); + CmdArgs.insert(CmdArgs.begin(), PrefixArgs.begin(), PrefixArgs.end()); CmdArgs.push_back("-lpthread"); CmdArgs.push_back("-ldl"); CmdArgs.push_back("-export-dynamic"); diff --git a/test/Driver/asan-ld.c b/test/Driver/asan-ld.c index b90082a262..cf2b695aa0 100644 --- a/test/Driver/asan-ld.c +++ b/test/Driver/asan-ld.c @@ -19,7 +19,7 @@ // // CHECK-LINUX-CXX: "{{.*}}ld{{(.exe)?}}" // CHECK-LINUX-CXX-NOT: "-lc" -// CHECK-LINUX-CXX: libclang_rt.asan-i386.a" +// CHECK-LINUX-CXX: "-whole-archive" "{{.*}}libclang_rt.asan-i386.a" "-no-whole-archive" // CHECK-LINUX-CXX: "-lpthread" // CHECK-LINUX-CXX: "-ldl" // CHECK-LINUX-CXX: "-export-dynamic" @@ -32,7 +32,7 @@ // // CHECK-LINUX-CXX-STATIC: "{{.*}}ld{{(.exe)?}}" // CHECK-LINUX-CXX-STATIC-NOT: stdc++ -// CHECK-LINUX-CXX-STATIC: libclang_rt.asan-i386.a" +// CHECK-LINUX-CXX-STATIC: "-whole-archive" "{{.*}}libclang_rt.asan-i386.a" "-no-whole-archive" // CHECK-LINUX-CXX-STATIC: stdc++ // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ |