[compiler-rt] r315143 - [ubsan] Add a static runtime on Darwin

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 6 18:46:36 PDT 2017


Author: vedantk
Date: Fri Oct  6 18:46:36 2017
New Revision: 315143

URL: http://llvm.org/viewvc/llvm-project?rev=315143&view=rev
Log:
[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.

Modified:
    compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
    compiler-rt/trunk/lib/ubsan/CMakeLists.txt
    compiler-rt/trunk/test/ubsan/CMakeLists.txt
    compiler-rt/trunk/test/ubsan/TestCases/Misc/coverage-levels.cc
    compiler-rt/trunk/test/ubsan/lit.common.cfg

Modified: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=315143&r1=315142&r2=315143&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Fri Oct  6 18:46:36 2017
@@ -199,6 +199,21 @@ add_compiler_rt_object_libraries(RTSanit
   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}

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=315143&r1=315142&r2=315143&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h Fri Oct  6 18:46:36 2017
@@ -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

Modified: compiler-rt/trunk/lib/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/CMakeLists.txt?rev=315143&r1=315142&r2=315143&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/ubsan/CMakeLists.txt Fri Oct  6 18:46:36 2017
@@ -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()

Modified: compiler-rt/trunk/test/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/CMakeLists.txt?rev=315143&r1=315142&r2=315143&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/ubsan/CMakeLists.txt Fri Oct  6 18:46:36 2017
@@ -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})

Modified: compiler-rt/trunk/test/ubsan/TestCases/Misc/coverage-levels.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/Misc/coverage-levels.cc?rev=315143&r1=315142&r2=315143&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/Misc/coverage-levels.cc (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/Misc/coverage-levels.cc Fri Oct  6 18:46:36 2017
@@ -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) {

Modified: compiler-rt/trunk/test/ubsan/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/lit.common.cfg?rev=315143&r1=315142&r2=315143&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/lit.common.cfg (original)
+++ compiler-rt/trunk/test/ubsan/lit.common.cfg Fri Oct  6 18:46:36 2017
@@ -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")




More information about the llvm-commits mailing list