[Sanitizer] force linking with static sanitizer runtimes on Darwin even if they are not found in resource directory. Add test checking sanitizer linker flags on Darwin.

llvm-svn: 168428
This commit is contained in:
Alexey Samsonov 2012-11-21 14:17:42 +00:00
parent ff571cce2f
commit 8368b376ad
3 changed files with 51 additions and 8 deletions

View File

@ -261,16 +261,18 @@ void DarwinClang::AddLinkARCArgs(const ArgList &Args,
void DarwinClang::AddLinkRuntimeLib(const ArgList &Args,
ArgStringList &CmdArgs,
const char *DarwinStaticLib) const {
const char *DarwinStaticLib,
bool AlwaysLink) const {
llvm::sys::Path P(getDriver().ResourceDir);
P.appendComponent("lib");
P.appendComponent("darwin");
P.appendComponent(DarwinStaticLib);
// For now, allow missing resource libraries to support developers who may
// not have compiler-rt checked out or integrated into their build.
// not have compiler-rt checked out or integrated into their build (unless
// we explicitly force linking with this library).
bool Exists;
if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
if (AlwaysLink || (!llvm::sys::fs::exists(P.str(), Exists) && Exists))
CmdArgs.push_back(Args.MakeArgString(P.str()));
}
@ -326,7 +328,7 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
getDriver().Diag(diag::err_drv_clang_unsupported_per_platform)
<< "-fsanitize=undefined";
} else {
AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ubsan_osx.a");
AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ubsan_osx.a", true);
// The Ubsan runtime library requires C++.
AddCXXStdlibLibArgs(Args, CmdArgs);
@ -343,7 +345,7 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
getDriver().Diag(diag::err_drv_clang_unsupported_per_platform)
<< "-fsanitize=address";
} else {
AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.asan_osx.a");
AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.asan_osx.a", true);
// The ASAN runtime library requires C++ and CoreFoundation.
AddCXXStdlibLibArgs(Args, CmdArgs);

View File

@ -370,9 +370,10 @@ public:
virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const;
void AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
const char *DarwinStaticLib) const;
void AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
const char *DarwinStaticLib,
bool AlwaysLink = false) const;
virtual void AddCXXStdlibLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const;

View File

@ -0,0 +1,40 @@
// Test sanitizer link flags on Darwin.
// RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
// RUN: -fsanitize=address %s -o %t.o 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-ASAN %s
// CHECK-ASAN: "{{.*}}ld"
// CHECK-ASAN: libclang_rt.asan_osx.a"
// CHECK-ASAN: "-lstdc++"
// CHECK-ASAN: "-framework" "CoreFoundation"
// RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
// RUN: -fPIC -shared -fsanitize=address %s -o %t.so 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-DYN-ASAN %s
// CHECK-DYN-ASAN: "{{.*}}ld"
// CHECK-DYN-ASAN: "-dylib"
// CHECK-DYN-ASAN-NOT: libclang_rt.asan_osx.a
// CHECK-DYN-ASAN: "-undefined"
// CHECK-DYN-ASAN: "dynamic_lookup"
// CHECK-DYN-ASAN-NOT: libclang_rt.asan_osx.a
// RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
// RUN: -fsanitize=undefined %s -o %t.o 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-UBSAN %s
// CHECK-UBSAN: "{{.*}}ld"
// CHECK-UBSAN: libclang_rt.ubsan_osx.a"
// CHECK-UBSAN: "-lstdc++"
// RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
// RUN: -fPIC -shared -fsanitize=undefined %s -o %t.so 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-DYN-UBSAN %s
// CHECK-DYN-UBSAN: "{{.*}}ld"
// CHECK-DYN-UBSAN: "-dylib"
// CHECK-DYN-UBSAN-NOT: libclang_rt.ubsan_osx.a
// CHECK-DYN-UBSAN: "-undefined"
// CHECK-DYN-UBSAN: "dynamic_lookup"
// CHECK-DYN-UBSAN-NOT: libclang_rt.ubsan_osx.a