r233035 - [UBSan] Use shared library for UBSan on OS X (Clang part).
Alexey Samsonov
vonosmas at gmail.com
Mon Mar 23 16:14:05 PDT 2015
Author: samsonov
Date: Mon Mar 23 18:14:05 2015
New Revision: 233035
URL: http://llvm.org/viewvc/llvm-project?rev=233035&view=rev
Log:
[UBSan] Use shared library for UBSan on OS X (Clang part).
Summary:
UBSan is now used in the same way as ASan, and is supported on
OSX and on iOS simulator. At the moment ASan and UBSan can't be used
together due to PR21112, but I hope to resolve it soon by
embedding UBSan into ASan.
Test Plan: regression test suite.
Reviewers: zaks.anna, kubabrecka
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D8471
Modified:
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/runtime/compiler-rt/Makefile
cfe/trunk/test/Driver/darwin-sanitizer-ld.c
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=233035&r1=233034&r2=233035&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Mon Mar 23 18:14:05 2015
@@ -324,6 +324,22 @@ void MachO::AddLinkRuntimeLib(const ArgL
}
}
+void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args,
+ ArgStringList &CmdArgs,
+ StringRef Sanitizer) const {
+ if (!Args.hasArg(options::OPT_dynamiclib) &&
+ !Args.hasArg(options::OPT_bundle)) {
+ // Sanitizer runtime libraries requires C++.
+ AddCXXStdlibLibArgs(Args, CmdArgs);
+ }
+ assert(isTargetMacOS() || isTargetIOSSimulator());
+ StringRef OS = isTargetMacOS() ? "osx" : "iossim";
+ AddLinkRuntimeLib(Args, CmdArgs, (Twine("libclang_rt.") + Sanitizer + "_" +
+ OS + "_dynamic.dylib").str(),
+ /*AlwaysLink*/ true, /*IsEmbedded*/ false,
+ /*AddRPath*/ true);
+}
+
void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
// Darwin only supports the compiler-rt based runtime libraries.
@@ -368,47 +384,26 @@ void DarwinClang::AddLinkRuntimeLibArgs(
const SanitizerArgs &Sanitize = getSanitizerArgs();
- // Add Ubsan runtime library, if required.
- if (Sanitize.needsUbsanRt()) {
- // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds.
- if (isTargetIOSBased()) {
+ if (Sanitize.needsAsanRt()) {
+ if (!isTargetMacOS() && !isTargetIOSSimulator()) {
+ // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds.
getDriver().Diag(diag::err_drv_clang_unsupported_per_platform)
- << "-fsanitize=undefined";
+ << "-fsanitize=address";
} else {
- assert(isTargetMacOS() && "unexpected non OS X target");
- AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ubsan_osx.a", true);
-
- // The Ubsan runtime library requires C++.
- AddCXXStdlibLibArgs(Args, CmdArgs);
+ AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
}
}
- // Add ASAN runtime library, if required. Dynamic libraries and bundles
- // should not be linked with the runtime library.
- if (Sanitize.needsAsanRt()) {
- // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds.
- if (isTargetIPhoneOS()) {
+ if (Sanitize.needsUbsanRt()) {
+ if (!isTargetMacOS() && !isTargetIOSSimulator()) {
+ // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds.
getDriver().Diag(diag::err_drv_clang_unsupported_per_platform)
- << "-fsanitize=address";
+ << "-fsanitize=undefined";
} else {
- if (!Args.hasArg(options::OPT_dynamiclib) &&
- !Args.hasArg(options::OPT_bundle)) {
- // The ASAN runtime library requires C++.
- AddCXXStdlibLibArgs(Args, CmdArgs);
- }
- if (isTargetMacOS()) {
- AddLinkRuntimeLib(Args, CmdArgs,
- "libclang_rt.asan_osx_dynamic.dylib",
- /*AlwaysLink*/ true, /*IsEmbedded*/ false,
- /*AddRPath*/ true);
- } else {
- if (isTargetIOSSimulator()) {
- AddLinkRuntimeLib(Args, CmdArgs,
- "libclang_rt.asan_iossim_dynamic.dylib",
- /*AlwaysLink*/ true, /*IsEmbedded*/ false,
- /*AddRPath*/ true);
- }
- }
+ 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");
}
}
Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=233035&r1=233034&r2=233035&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Mon Mar 23 18:14:05 2015
@@ -494,6 +494,11 @@ public:
AddLinkARCArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;
/// }
+
+private:
+ void AddLinkSanitizerLibArgs(const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs,
+ StringRef Sanitizer) const;
};
class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
Modified: cfe/trunk/runtime/compiler-rt/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/runtime/compiler-rt/Makefile?rev=233035&r1=233034&r2=233035&view=diff
==============================================================================
--- cfe/trunk/runtime/compiler-rt/Makefile (original)
+++ cfe/trunk/runtime/compiler-rt/Makefile Mon Mar 23 18:14:05 2015
@@ -79,7 +79,7 @@ RuntimeLibrary.darwin.Configs := \
eprintf.a 10.4.a osx.a cc_kext.a \
asan_osx_dynamic.dylib \
profile_osx.a \
- ubsan_osx.a
+ ubsan_osx_dynamic.dylib
IOS_SDK := $(shell xcrun --show-sdk-path -sdk iphoneos 2> /dev/null)
IOSSIM_SDK := $(shell xcrun --show-sdk-path -sdk iphonesimulator 2> /dev/null)
@@ -93,7 +93,8 @@ RuntimeLibrary.darwin.Configs += cc_kext
endif
ifneq ($(IOSSIM_SDK),)
-RuntimeLibrary.darwin.Configs += asan_iossim_dynamic.dylib
+RuntimeLibrary.darwin.Configs += asan_iossim_dynamic.dylib \
+ ubsan_iossim_dynamic.dylib
endif
RuntimeLibrary.macho_embedded.Configs := \
Modified: cfe/trunk/test/Driver/darwin-sanitizer-ld.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-sanitizer-ld.c?rev=233035&r1=233034&r2=233035&view=diff
==============================================================================
--- cfe/trunk/test/Driver/darwin-sanitizer-ld.c (original)
+++ cfe/trunk/test/Driver/darwin-sanitizer-ld.c Mon Mar 23 18:14:05 2015
@@ -35,8 +35,10 @@
// RUN: | FileCheck --check-prefix=CHECK-UBSAN %s
// CHECK-UBSAN: "{{.*}}ld{{(.exe)?}}"
-// CHECK-UBSAN: libclang_rt.ubsan_osx.a"
// CHECK-UBSAN: stdc++
+// CHECK-UBSAN: libclang_rt.ubsan_osx_dynamic.dylib"
+// CHECK-UBSAN: "-rpath" "@executable_path"
+// CHECK-UBSAN: "-rpath" "{{.*}}lib{{.*}}darwin"
// RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
// RUN: -fsanitize=bounds -fsanitize-undefined-trap-on-error \
@@ -52,7 +54,9 @@
// CHECK-DYN-UBSAN: "{{.*}}ld{{(.exe)?}}"
// CHECK-DYN-UBSAN: "-dylib"
-// CHECK-DYN-UBSAN: libclang_rt.ubsan_osx.a
+// CHECK-DYN-UBSAN: libclang_rt.ubsan_osx_dynamic.dylib"
+// CHECK-DYN-UBSAN: "-rpath" "@executable_path"
+// CHECK-DYN-UBSAN: "-rpath" "{{.*}}lib{{.*}}darwin"
// RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
// RUN: -fsanitize=bounds -fsanitize-undefined-trap-on-error \
@@ -60,4 +64,4 @@
// RUN: | FileCheck --check-prefix=CHECK-DYN-BOUNDS %s
// CHECK-DYN-BOUNDS: "{{.*}}ld{{(.exe)?}}"
-// CHECK-DYN-BOUNDS-NOT: libclang_rt.ubsan_osx.a
+// CHECK-DYN-BOUNDS-NOT: ubsan_osx
More information about the cfe-commits
mailing list