[PATCH] [CMake] Fix PR23539: Don't reference C++ ABI symbols prior to Mac OS 10.9.

Alexey Samsonov vonosmas at gmail.com
Mon Jun 22 17:10:52 PDT 2015


Hi thakis, hans,

This patch implements step 1 from
https://llvm.org/bugs/show_bug.cgi?id=23539#c10

I'd appreciate if you could test it on Mac OS and verify that parts of UBSan
runtime that reference C++ ABI symbols are properly excluded, and fix ASan/UBSan
builds.

http://reviews.llvm.org/D10621

Files:
  CMakeLists.txt
  lib/ubsan/CMakeLists.txt
  test/lit.common.cfg
  test/lit.common.configured.in
  test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp
  test/ubsan/TestCases/TypeCheck/vptr.cpp

Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -327,6 +327,15 @@
   endif()
 endif()
 
+if(APPLE AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9")
+  # Mac OS X prior to 10.9 had problems with exporting symbols from
+  # libc++/libc++abi.
+  set(SANITIZER_CAN_USE_CXXABI FALSE)
+else()
+  set(SANITIZER_CAN_USE_CXXABI TRUE)
+endif()
+pythonize_bool(SANITIZER_CAN_USE_CXXABI)
+
 add_subdirectory(include)
 
 set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx)
Index: lib/ubsan/CMakeLists.txt
===================================================================
--- lib/ubsan/CMakeLists.txt
+++ lib/ubsan/CMakeLists.txt
@@ -28,11 +28,16 @@
 add_custom_target(ubsan)
 
 if(APPLE)
+  set(UBSAN_COMMON_SOURCES ${UBSAN_SOURCES})
+  if(SANITIZER_CAN_USE_CXXABI)
+    list(APPEND UBSAN_COMMON_SOURCES ${UBSAN_CXX_SOURCES})
+  endif()
+
   # Common parts of UBSan runtime.
   add_compiler_rt_object_libraries(RTUbsan
     OS ${SANITIZER_COMMON_SUPPORTED_OS}
     ARCHS ${UBSAN_COMMON_SUPPORTED_ARCH}
-    SOURCES ${UBSAN_SOURCES} ${UBSAN_CXX_SOURCES}
+    SOURCES ${UBSAN_COMMON_SOURCES}
     CFLAGS ${UBSAN_CXXFLAGS})
 
   if(COMPILER_RT_HAS_UBSAN)
Index: test/lit.common.cfg
===================================================================
--- test/lit.common.cfg
+++ test/lit.common.cfg
@@ -90,6 +90,10 @@
 if not compiler_rt_debug:
   config.available_features.add('compiler-rt-optimized')
 
+sanitizer_can_use_cxxabi = getattr(config, 'sanitizer_can_use_cxxabi', True)
+if sanitizer_can_use_cxxabi:
+  config.available_features.add('cxxabi')
+
 lit.util.usePlatformSdkOnDarwin(config, lit_config)
 
 def is_darwin_lto_supported():
Index: test/lit.common.configured.in
===================================================================
--- test/lit.common.configured.in
+++ test/lit.common.configured.in
@@ -27,6 +27,7 @@
 set_default("compiler_rt_debug", @COMPILER_RT_DEBUG_PYBOOL@)
 set_default("compiler_rt_libdir", "@COMPILER_RT_LIBRARY_OUTPUT_DIR@")
 set_default("emulator", "@COMPILER_RT_EMULATOR@")
+set_default("sanitizer_can_use_cxxabi", @SANITIZER_CAN_USE_CXXABI_PYBOOL@)
 
 # LLVM tools dir can be passed in lit parameters, so try to
 # apply substitution.
Index: test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp
===================================================================
--- test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp
+++ test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp
@@ -1,6 +1,8 @@
 // RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr -g %s -O3 -o %t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
+// REQUIRES: cxxabi
+
 struct S { virtual int f() { return 0; } };
 struct T : virtual S {};
 
Index: test/ubsan/TestCases/TypeCheck/vptr.cpp
===================================================================
--- test/ubsan/TestCases/TypeCheck/vptr.cpp
+++ test/ubsan/TestCases/TypeCheck/vptr.cpp
@@ -24,7 +24,7 @@
 // RUN: echo "vptr_check:S" > %t.loc-supp
 // RUN: UBSAN_OPTIONS="suppressions='%t.loc-supp'" not %run %t x- 2>&1 | FileCheck %s --check-prefix=CHECK-LOC-SUPPRESS
 
-// REQUIRES: stable-runtime
+// REQUIRES: stable-runtime, cxxabi
 #include <new>
 #include <assert.h>
 #include <stdio.h>

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10621.28178.patch
Type: text/x-patch
Size: 3256 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150623/c4fc1f92/attachment.bin>


More information about the llvm-commits mailing list