From 613051701aab62f2b9062b8c2f3792d0cd6ee461 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Sat, 7 Oct 2017 01:42:09 +0000 Subject: [PATCH] [Driver] Fix -static-libsan / -shared-libsan on Darwin Don't ignore these flags on Darwin. The old behavior of using the dynamic runtime when neither flag is passed is preserved. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315142 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/SanitizerArgs.cpp | 3 ++- lib/Driver/ToolChains/Darwin.cpp | 3 ++- test/Driver/sanitizer-ld.c | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Driver/SanitizerArgs.cpp b/lib/Driver/SanitizerArgs.cpp index ceb5bbad7e..7e9ee02309 100644 --- a/lib/Driver/SanitizerArgs.cpp +++ b/lib/Driver/SanitizerArgs.cpp @@ -612,7 +612,8 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, SharedRuntime = Args.hasFlag(options::OPT_shared_libsan, options::OPT_static_libsan, - TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia()); + TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia() || + TC.getTriple().isOSDarwin()); if (AllAddedKinds & Address) { NeedPIE |= TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia(); diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index 29fae0019a..78d7bf4b3d 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -1049,7 +1049,8 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, if (Sanitize.needsUbsanRt()) AddLinkSanitizerLibArgs(Args, CmdArgs, Sanitize.requiresMinimalRuntime() ? "ubsan_minimal" - : "ubsan"); + : "ubsan", + Sanitize.needsSharedRt()); if (Sanitize.needsTsanRt()) AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan"); if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) { diff --git a/test/Driver/sanitizer-ld.c b/test/Driver/sanitizer-ld.c index 52e7bdeadb..6f9ee052c3 100644 --- a/test/Driver/sanitizer-ld.c +++ b/test/Driver/sanitizer-ld.c @@ -335,6 +335,13 @@ // CHECK-UBSAN-MINIMAL-DARWIN: "{{.*}}ld{{(.exe)?}}" // CHECK-UBSAN-MINIMAL-DARWIN: "{{.*}}libclang_rt.ubsan_minimal_osx_dynamic.dylib" +// RUN: %clang -fsanitize=undefined %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-apple-darwin -fuse-ld=ld -static-libsan \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-UBSAN-STATIC-DARWIN %s +// CHECK-UBSAN-STATIC-DARWIN: "{{.*}}ld{{(.exe)?}}" +// CHECK-UBSAN-STATIC-DARWIN: "{{.*}}libclang_rt.ubsan_osx.a" + // RUN: %clang -fsanitize=address,undefined %s -### -o %t.o 2>&1 \ // RUN: -target i386-unknown-linux -fuse-ld=ld \ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ -- 2.40.0