[ubsan] Add a static runtime on Darwin

As a follow-up to r315142, this makes it possible to use ubsan with a
static runtime on Darwin. I've also added a new StandaloneStatic testing
configuration so the new setup can be tested.

llvm-svn: 315143
This commit is contained in:
Vedant Kumar 2017-10-07 01:46:36 +00:00
parent 358d642f65
commit 074a997b13
6 changed files with 43 additions and 0 deletions

View File

@ -199,6 +199,21 @@ add_compiler_rt_object_libraries(RTSanitizerCommonLibc
CFLAGS ${SANITIZER_CFLAGS}
DEFS ${SANITIZER_COMMON_DEFINITIONS})
set(SANITIZER_NO_WEAK_HOOKS_CFLAGS ${SANITIZER_CFLAGS})
append("-DSANITIZER_SUPPORTS_WEAK_HOOKS=0" SANITIZER_NO_WEAK_HOOKS_CFLAGS)
add_compiler_rt_object_libraries(RTSanitizerCommonNoHooks
${OS_OPTION}
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
SOURCES ${SANITIZER_SOURCES}
CFLAGS ${SANITIZER_NO_WEAK_HOOKS_CFLAGS}
DEFS ${SANITIZER_COMMON_DEFINITIONS})
add_compiler_rt_object_libraries(RTSanitizerCommonLibcNoHooks
${OS_OPTION}
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
SOURCES ${SANITIZER_LIBCDEP_SOURCES}
CFLAGS ${SANITIZER_NO_WEAK_HOOKS_CFLAGS}
DEFS ${SANITIZER_COMMON_DEFINITIONS})
if(WIN32)
add_compiler_rt_object_libraries(SanitizerCommonWeakInterception
${SANITIZER_COMMON_SUPPORTED_OS}

View File

@ -64,11 +64,13 @@
// SANITIZER_SUPPORTS_WEAK_HOOKS means that we support real weak functions that
// will evaluate to a null pointer when not defined.
#ifndef SANITIZER_SUPPORTS_WEAK_HOOKS
#if (SANITIZER_LINUX || SANITIZER_MAC) && !SANITIZER_GO
# define SANITIZER_SUPPORTS_WEAK_HOOKS 1
#else
# define SANITIZER_SUPPORTS_WEAK_HOOKS 0
#endif
#endif // SANITIZER_SUPPORTS_WEAK_HOOKS
// For some weak hooks that will be called very often and we want to avoid the
// overhead of executing the default implementation when it is not necessary,
// we can use the flag SANITIZER_SUPPORTS_WEAK_HOOKS to only define the default

View File

@ -79,6 +79,18 @@ if(APPLE)
RTInterception
LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
PARENT_TARGET ubsan)
add_compiler_rt_runtime(clang_rt.ubsan
STATIC
OS ${SANITIZER_COMMON_SUPPORTED_OS}
ARCHS ${UBSAN_SUPPORTED_ARCH}
OBJECT_LIBS RTUbsan
RTUbsan_standalone
RTSanitizerCommonNoHooks
RTSanitizerCommonLibcNoHooks
RTInterception
LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
PARENT_TARGET ubsan)
endif()
else()

View File

@ -40,6 +40,15 @@ foreach(arch ${UBSAN_TEST_ARCH})
endif()
endforeach()
if(APPLE)
foreach(arch ${UBSAN_TEST_ARCH})
set(UBSAN_TEST_TARGET_ARCH ${arch})
get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
append("-lc++abi" UBSAN_TEST_TARGET_CFLAGS)
add_ubsan_testsuite("StandaloneStatic" ubsan ${arch})
endforeach()
endif()
add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests"
${UBSAN_TESTSUITES}
DEPENDS ${UBSAN_TEST_DEPS})

View File

@ -22,6 +22,7 @@
// Coverage is not yet implemented in TSan.
// XFAIL: ubsan-tsan
// UNSUPPORTED: ubsan-standalone-static
volatile int sink;
int main(int argc, char **argv) {

View File

@ -21,6 +21,10 @@ if ubsan_lit_test_mode == "Standalone":
config.name = 'UBSan-Standalone-' + config.target_arch
config.available_features.add("ubsan-standalone")
clang_ubsan_cflags = []
elif ubsan_lit_test_mode == "StandaloneStatic":
config.name = 'UBSan-StandaloneStatic-' + config.target_arch
config.available_features.add("ubsan-standalone-static")
clang_ubsan_cflags = ['-static-libsan']
elif ubsan_lit_test_mode == "AddressSanitizer":
config.name = 'UBSan-ASan-' + config.target_arch
config.available_features.add("ubsan-asan")