r208610 - [ASan] Split static ASan runtime in two parts: asan and asan_cxx.
Alexey Samsonov
samsonov at google.com
Mon May 12 11:39:51 PDT 2014
Author: samsonov
Date: Mon May 12 13:39:51 2014
New Revision: 208610
URL: http://llvm.org/viewvc/llvm-project?rev=208610&view=rev
Log:
[ASan] Split static ASan runtime in two parts: asan and asan_cxx.
asan_cxx containts replacements for new/delete operators, and should
only be linked in C++ mode. We plan to start building this part
with exception support to make new more standard-compliant.
See https://code.google.com/p/address-sanitizer/issues/detail?id=295
for more details.
Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/runtime/compiler-rt/Makefile
cfe/trunk/test/Driver/sanitizer-ld.c
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=208610&r1=208609&r2=208610&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Mon May 12 13:39:51 2014
@@ -1972,7 +1972,7 @@ static void addSanitizerRTLinkFlags(cons
/// 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 addAsanRT(const ToolChain &TC, const ArgList &Args,
- ArgStringList &CmdArgs, bool Shared) {
+ ArgStringList &CmdArgs, bool Shared, bool IsCXX) {
if (Shared) {
// Link dynamic runtime if necessary.
SmallString<128> LibSanitizer =
@@ -1985,10 +1985,15 @@ static void addAsanRT(const ToolChain &T
(TC.getTriple().getEnvironment() == llvm::Triple::Android))
return;
- const char *LibAsanStaticPart = Shared ? "asan-preinit" : "asan";
- addSanitizerRTLinkFlags(TC, Args, CmdArgs, LibAsanStaticPart,
- /*BeforeLibStdCXX*/ true, /*ExportSymbols*/ !Shared,
- /*LinkDeps*/ !Shared);
+ if (Shared) {
+ addSanitizerRTLinkFlags(TC, Args, CmdArgs, "asan-preinit",
+ /*BeforeLibStdCXX*/ true, /*ExportSymbols*/ false,
+ /*LinkDeps*/ false);
+ } else {
+ addSanitizerRTLinkFlags(TC, Args, CmdArgs, "asan", true);
+ if (IsCXX)
+ addSanitizerRTLinkFlags(TC, Args, CmdArgs, "asan_cxx", true);
+ }
}
/// If ThreadSanitizer is enabled, add appropriate linker flags (Linux).
@@ -2049,7 +2054,7 @@ static void addSanitizerRuntimes(const T
Sanitize.needsAsanRt() || Sanitize.needsTsanRt() ||
Sanitize.needsMsanRt() || Sanitize.needsLsanRt());
if (Sanitize.needsAsanRt())
- addAsanRT(TC, Args, CmdArgs, Sanitize.needsSharedAsanRt());
+ addAsanRT(TC, Args, CmdArgs, Sanitize.needsSharedAsanRt(), D.CCCIsCXX());
if (Sanitize.needsTsanRt())
addTsanRT(TC, Args, CmdArgs);
if (Sanitize.needsMsanRt())
Modified: cfe/trunk/runtime/compiler-rt/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/runtime/compiler-rt/Makefile?rev=208610&r1=208609&r2=208610&view=diff
==============================================================================
--- cfe/trunk/runtime/compiler-rt/Makefile (original)
+++ cfe/trunk/runtime/compiler-rt/Makefile Mon May 12 13:39:51 2014
@@ -126,8 +126,8 @@ TryCompile = \
# We try to build 32-bit runtimes both on 32-bit hosts and 64-bit hosts.
Runtime32BitConfigs = \
- full-i386.a profile-i386.a san-i386.a asan-i386.a ubsan-i386.a \
- ubsan_cxx-i386.a
+ full-i386.a profile-i386.a san-i386.a asan-i386.a asan_cxx-i386.a \
+ ubsan-i386.a ubsan_cxx-i386.a
# We currently only try to generate runtime libraries on x86.
ifeq ($(ARCH),x86)
@@ -137,8 +137,8 @@ endif
ifeq ($(ARCH),x86_64)
RuntimeLibrary.linux.Configs += \
full-x86_64.a profile-x86_64.a san-x86_64.a asan-x86_64.a \
- tsan-x86_64.a msan-x86_64.a ubsan-x86_64.a ubsan_cxx-x86_64.a \
- dfsan-x86_64.a lsan-x86_64.a
+ asan_cxx-x86_64.a tsan-x86_64.a msan-x86_64.a ubsan-x86_64.a \
+ ubsan_cxx-x86_64.a dfsan-x86_64.a lsan-x86_64.a
# We need to build 32-bit ASan/UBsan libraries on 64-bit platform, and add them
# to the list of runtime libraries to make
# "clang -fsanitize=(address|undefined) -m32" work.
Modified: cfe/trunk/test/Driver/sanitizer-ld.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=208610&r1=208609&r2=208610&view=diff
==============================================================================
--- cfe/trunk/test/Driver/sanitizer-ld.c (original)
+++ cfe/trunk/test/Driver/sanitizer-ld.c Mon May 12 13:39:51 2014
@@ -57,7 +57,9 @@
//
// CHECK-ASAN-FREEBSD: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
// CHECK-ASAN-FREEBSD-NOT: "-lc"
+// CHECK-ASAN-FREEBSD-NOT: libclang_rt.asan_cxx
// CHECK-ASAN-FREEBSD: freebsd{{/|\\+}}libclang_rt.asan-i386.a"
+// CHECK-ASAN-FREEBSD-NOT: libclang_rt.asan_cxx
// CHECK-ASAN-FREEBSD: "-lpthread"
// CHECK-ASAN-FREEBSD: "-lrt"
// CHECK-ASAN-FREEBSD: "-export-dynamic"
@@ -80,6 +82,7 @@
//
// CHECK-ASAN-LINUX-CXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
// CHECK-ASAN-LINUX-CXX-NOT: "-lc"
+// CHECK-ASAN-LINUX-CXX: "-whole-archive" "{{.*}}libclang_rt.asan_cxx-i386.a" "-no-whole-archive"
// CHECK-ASAN-LINUX-CXX: "-whole-archive" "{{.*}}libclang_rt.asan-i386.a" "-no-whole-archive"
// CHECK-ASAN-LINUX-CXX: "-lpthread"
// CHECK-ASAN-LINUX-CXX: "-lrt"
More information about the cfe-commits
mailing list