[cfe-commits] r168428 - in /cfe/trunk: lib/Driver/ToolChains.cpp lib/Driver/ToolChains.h test/Driver/darwin-sanitizer-ld.c
Alexey Samsonov
samsonov at google.com
Wed Nov 21 06:17:43 PST 2012
Author: samsonov
Date: Wed Nov 21 08:17:42 2012
New Revision: 168428
URL: http://llvm.org/viewvc/llvm-project?rev=168428&view=rev
Log:
[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.
Added:
cfe/trunk/test/Driver/darwin-sanitizer-ld.c
Modified:
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/ToolChains.h
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=168428&r1=168427&r2=168428&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Wed Nov 21 08:17:42 2012
@@ -261,16 +261,18 @@
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 @@
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 @@
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);
Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=168428&r1=168427&r2=168428&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Wed Nov 21 08:17:42 2012
@@ -370,9 +370,10 @@
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;
Added: cfe/trunk/test/Driver/darwin-sanitizer-ld.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-sanitizer-ld.c?rev=168428&view=auto
==============================================================================
--- cfe/trunk/test/Driver/darwin-sanitizer-ld.c (added)
+++ cfe/trunk/test/Driver/darwin-sanitizer-ld.c Wed Nov 21 08:17:42 2012
@@ -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
More information about the cfe-commits
mailing list