[compiler-rt] a44477b - [CompilerRT] Remove ubsan static runtime on Apple
usama hameed via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 17 14:34:10 PST 2023
Author: usama hameed
Date: 2023-01-17T14:33:31-08:00
New Revision: a44477b1f4b5c462474c12144d5f914d04a674cb
URL: https://github.com/llvm/llvm-project/commit/a44477b1f4b5c462474c12144d5f914d04a674cb
DIFF: https://github.com/llvm/llvm-project/commit/a44477b1f4b5c462474c12144d5f914d04a674cb.diff
LOG: [CompilerRT] Remove ubsan static runtime on Apple
This patch removes the static ubsan runtime on Apple devices. The motivation
is to reduce the toolchain size.
rdar://102061519
Differential Revision: https://reviews.llvm.org/D141550
Added:
Modified:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/sanitizer-ld.c
compiler-rt/lib/ubsan/CMakeLists.txt
compiler-rt/test/ubsan/CMakeLists.txt
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 08be6966f686..6f046cdb7952 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -215,6 +215,8 @@ def err_drv_malformed_sanitizer_coverage_allowlist : Error<
"malformed sanitizer coverage allowlist: '%0'">;
def err_drv_malformed_sanitizer_coverage_ignorelist : Error<
"malformed sanitizer coverage ignorelist: '%0'">;
+def err_drv_unsupported_static_ubsan_darwin : Error<
+ "static UndefinedBehaviorSanitizer runtime is not supported on darwin">;
def err_drv_duplicate_config : Error<
"no more than one option '--config' is allowed">;
def err_drv_cannot_open_config_file : Error<
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index a161355ccbc4..9f95c962ee9a 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1425,15 +1425,22 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
}
const SanitizerArgs &Sanitize = getSanitizerArgs(Args);
+
+ if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
+ getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
+ return;
+ }
+
if (Sanitize.needsAsanRt())
AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
if (Sanitize.needsLsanRt())
AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
- if (Sanitize.needsUbsanRt())
+ if (Sanitize.needsUbsanRt()) {
+ assert(Sanitize.needsSharedRt() && "Static sanitizer runtimes not supported");
AddLinkSanitizerLibArgs(Args, CmdArgs,
Sanitize.requiresMinimalRuntime() ? "ubsan_minimal"
- : "ubsan",
- Sanitize.needsSharedRt());
+ : "ubsan");
+ }
if (Sanitize.needsTsanRt())
AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
index e58a6e51547f..6b85abfd81c5 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -423,8 +423,7 @@
// 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"
+// CHECK-UBSAN-STATIC-DARWIN: {{.*}}error: static UndefinedBehaviorSanitizer runtime is not supported on darwin
// RUN: %clang -fsanitize=address,undefined -### %s 2>&1 \
// RUN: --target=i386-unknown-linux -fuse-ld=ld \
diff --git a/compiler-rt/lib/ubsan/CMakeLists.txt b/compiler-rt/lib/ubsan/CMakeLists.txt
index 2c7e0f596ff5..520a024fbede 100644
--- a/compiler-rt/lib/ubsan/CMakeLists.txt
+++ b/compiler-rt/lib/ubsan/CMakeLists.txt
@@ -114,19 +114,21 @@ if(APPLE)
LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
PARENT_TARGET ubsan)
- add_compiler_rt_runtime(clang_rt.ubsan
- STATIC
- OS ${UBSAN_SUPPORTED_OS}
- ARCHS ${UBSAN_SUPPORTED_ARCH}
- OBJECT_LIBS RTUbsan
- RTUbsan_standalone
- RTSanitizerCommonNoHooks
- RTSanitizerCommonLibcNoHooks
- RTSanitizerCommonCoverage
- RTSanitizerCommonSymbolizerNoHooks
- RTInterception
- LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
- PARENT_TARGET ubsan)
+ if (NOT APPLE)
+ add_compiler_rt_runtime(clang_rt.ubsan
+ STATIC
+ OS ${UBSAN_SUPPORTED_OS}
+ ARCHS ${UBSAN_SUPPORTED_ARCH}
+ OBJECT_LIBS RTUbsan
+ RTUbsan_standalone
+ RTSanitizerCommonNoHooks
+ RTSanitizerCommonLibcNoHooks
+ RTSanitizerCommonCoverage
+ RTSanitizerCommonSymbolizerNoHooks
+ RTInterception
+ LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
+ PARENT_TARGET ubsan)
+ endif()
endif()
else()
diff --git a/compiler-rt/test/ubsan/CMakeLists.txt b/compiler-rt/test/ubsan/CMakeLists.txt
index 749446320ff3..d14aa149d978 100644
--- a/compiler-rt/test/ubsan/CMakeLists.txt
+++ b/compiler-rt/test/ubsan/CMakeLists.txt
@@ -101,7 +101,6 @@ if(APPLE)
set(UBSAN_TEST_TARGET_ARCH ${arch})
get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
set(UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS} -lc++abi")
- add_ubsan_testsuites("StandaloneStatic" ubsan ${arch})
endforeach()
# Device and simulator test suites.
More information about the llvm-commits
mailing list