diff options
author | Alexey Samsonov <samsonov@google.com> | 2014-05-12 18:39:51 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2014-05-12 18:39:51 +0000 |
commit | 161a85d8786d2394a6a7cd84385f5a40043d26eb (patch) | |
tree | 1ead6ef101994952e0bf6b2f42e716bae644de7e | |
parent | 2b84dd3d77a6f9ac9cc06bf9685ac8ebcf4ecfe6 (diff) | |
download | clang-161a85d8786d2394a6a7cd84385f5a40043d26eb.tar.gz clang-161a85d8786d2394a6a7cd84385f5a40043d26eb.tar.bz2 clang-161a85d8786d2394a6a7cd84385f5a40043d26eb.tar.xz |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208610 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Driver/Tools.cpp | 17 | ||||
-rw-r--r-- | runtime/compiler-rt/Makefile | 8 | ||||
-rw-r--r-- | test/Driver/sanitizer-ld.c | 3 |
3 files changed, 18 insertions, 10 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index ec870aff15..e2bb0b12cd 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1972,7 +1972,7 @@ static void addSanitizerRTLinkFlags(const ToolChain &TC, const ArgList &Args, /// 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 &TC, const ArgList &Args, (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 ToolChain &TC, const ArgList &Args, 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()) diff --git a/runtime/compiler-rt/Makefile b/runtime/compiler-rt/Makefile index b683fcdc8b..24efdf45b5 100644 --- a/runtime/compiler-rt/Makefile +++ b/runtime/compiler-rt/Makefile @@ -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. diff --git a/test/Driver/sanitizer-ld.c b/test/Driver/sanitizer-ld.c index 603e5104cc..405e3a6166 100644 --- a/test/Driver/sanitizer-ld.c +++ b/test/Driver/sanitizer-ld.c @@ -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" |