]> granicus.if.org Git - clang/commitdiff
[UBSan] Embed UBSan into ASan runtime (Clang part).
authorAlexey Samsonov <vonosmas@gmail.com>
Wed, 1 Apr 2015 22:42:25 +0000 (22:42 +0000)
committerAlexey Samsonov <vonosmas@gmail.com>
Wed, 1 Apr 2015 22:42:25 +0000 (22:42 +0000)
Summary:
Change the way we use ASan and UBSan together. Instead of keeping two
separate runtimes (libclang_rt.asan and libclang_rt.ubsan), embed UBSan
into ASan and get rid of libclang_rt.ubsan. If UBSan is not supported on
a platform, all UBSan sources are just compiled into dummy empty object
files. UBSan initialization code (e.g. flag parsing) is directly called
from ASan initialization, so we are able to enforce correct
initialization order.

This mirrors the approach we already use for ASan+LSan. This change doesn't
modify the way we use standalone UBSan.

Test Plan: regression test suite

Reviewers: kubabrecka, zaks.anna, kcc, rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D8645

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233860 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/SanitizerArgs.cpp
lib/Driver/ToolChains.cpp
lib/Driver/Tools.cpp
test/Driver/sanitizer-ld.c

index fb907a7eea3da50d0402e4f69535917a27ea0630..88725cdedd260de9b925d57063f53d6ed687b95a 100644 (file)
@@ -159,7 +159,8 @@ static bool getDefaultBlacklist(const Driver &D, uint64_t Kinds,
 }
 
 bool SanitizerArgs::needsUbsanRt() const {
-  return !UbsanTrapOnError && hasOneOf(Sanitizers, NeedsUbsanRt);
+  return !UbsanTrapOnError && hasOneOf(Sanitizers, NeedsUbsanRt) &&
+         !Sanitizers.has(SanitizerKind::Address);
 }
 
 bool SanitizerArgs::requiresPIE() const {
index 61a2ac6934b9d3dfaf2df690d9be9be5d12d6646..658ffb6d324cd1a816852fb64fff3a61bf3cb21e 100644 (file)
@@ -338,6 +338,9 @@ void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args,
                                     OS + "_dynamic.dylib").str(),
                     /*AlwaysLink*/ true, /*IsEmbedded*/ false,
                     /*AddRPath*/ true);
+  // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export
+  // all RTTI-related symbols that UBSan uses.
+  CmdArgs.push_back("-lc++abi");
 }
 
 void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
@@ -401,9 +404,6 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
           << "-fsanitize=undefined";
     } else {
       AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan");
-      // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export
-      // all RTTI-related symbols that UBSan uses.
-      CmdArgs.push_back("-lc++abi");
     }
   }
 
index 3a57129d63ee07d36240d218afb7c71f0c822058..d96c294581c98444de46e7588d1905507a562ea2 100644 (file)
@@ -2307,18 +2307,10 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
     StaticRuntimes.push_back("msan");
   if (SanArgs.needsTsanRt())
     StaticRuntimes.push_back("tsan");
-  // WARNING: UBSan should always go last.
   if (SanArgs.needsUbsanRt()) {
-    // Check if UBSan is combined with another sanitizers.
-    if (StaticRuntimes.empty()) {
-      StaticRuntimes.push_back("ubsan_standalone");
-      if (SanArgs.linkCXXRuntimes())
-        StaticRuntimes.push_back("ubsan_standalone_cxx");
-    } else {
-      StaticRuntimes.push_back("ubsan");
-      if (SanArgs.linkCXXRuntimes())
-        StaticRuntimes.push_back("ubsan_cxx");
-    }
+    StaticRuntimes.push_back("ubsan_standalone");
+    if (SanArgs.linkCXXRuntimes())
+      StaticRuntimes.push_back("ubsan_standalone_cxx");
   }
 }
 
index 97205f4ba9cc00ca759ce73c73a90ff4318e04a6..586d0c729caebc72a82d2a0edaf5d15c9b4f6ea7 100644 (file)
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-UBSAN-LINUX %s
 // CHECK-ASAN-UBSAN-LINUX: "{{.*}}ld{{(.exe)?}}"
 // CHECK-ASAN-UBSAN-LINUX: "-whole-archive" "{{.*}}libclang_rt.asan-i386.a" "-no-whole-archive"
-// CHECK-ASAN-UBSAN-LINUX: "-whole-archive" "{{.*}}libclang_rt.ubsan-i386.a" "-no-whole-archive"
-// CHECK-ASAN-UBSAN-LINUX-NOT: libclang_rt.ubsan_cxx
+// CHECK-ASAN-UBSAN-LINUX-NOT: libclang_rt.ubsan
 // CHECK-ASAN-UBSAN-LINUX-NOT: "-lstdc++"
 // CHECK-ASAN-UBSAN-LINUX: "-lpthread"
 
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-UBSAN-LINUX-CXX %s
 // CHECK-ASAN-UBSAN-LINUX-CXX: "{{.*}}ld{{(.exe)?}}"
 // CHECK-ASAN-UBSAN-LINUX-CXX: "-whole-archive" "{{.*}}libclang_rt.asan-i386.a" "-no-whole-archive"
-// CHECK-ASAN-UBSAN-LINUX-CXX: "-whole-archive" "{{.*}}libclang_rt.ubsan-i386.a" "-no-whole-archive"
-// CHECK-ASAN-UBSAN-LINUX-CXX: "-whole-archive" "{{.*}}libclang_rt.ubsan_cxx-i386.a" "-no-whole-archive"
+// CHECK-ASAN-UBSAN-LINUX-CXX: "-whole-archive" "{{.*}}libclang_rt.asan_cxx-i386.a" "-no-whole-archive"
+// CHECK-ASAN-UBSAN-LINUX-CXX-NOT: libclang_rt.ubsan
 // CHECK-ASAN-UBSAN-LINUX-CXX: "-lstdc++"
 // CHECK-ASAN-UBSAN-LINUX-CXX: "-lpthread"