Index: lib/Driver/SanitizerArgs.cpp =================================================================== --- lib/Driver/SanitizerArgs.cpp +++ lib/Driver/SanitizerArgs.cpp @@ -159,7 +159,8 @@ } bool SanitizerArgs::needsUbsanRt() const { - return !UbsanTrapOnError && hasOneOf(Sanitizers, NeedsUbsanRt); + return !UbsanTrapOnError && hasOneOf(Sanitizers, NeedsUbsanRt) && + !Sanitizers.has(SanitizerKind::Address); } bool SanitizerArgs::requiresPIE() const { Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -338,6 +338,9 @@ 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 @@ << "-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: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2281,18 +2281,10 @@ 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: test/Driver/sanitizer-ld.c =================================================================== --- test/Driver/sanitizer-ld.c +++ test/Driver/sanitizer-ld.c @@ -227,8 +227,7 @@ // 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" @@ -238,8 +237,8 @@ // 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"