Skip to content

Commit 3fa03e3

Browse files
committed
[CMake] Fix PR23539: Don't reference C++ ABI symbols prior to Mac OS 10.9.
Summary: 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. Test Plan: regression test suite Reviewers: thakis, hans Subscribers: llvm-commits, zaks.anna, kubabrecka Differential Revision: http://reviews.llvm.org/D10621 llvm-svn: 240617
1 parent f1eccbe commit 3fa03e3

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

compiler-rt/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,15 @@ if(APPLE)
327327
endif()
328328
endif()
329329

330+
if(APPLE AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9")
331+
# Mac OS X prior to 10.9 had problems with exporting symbols from
332+
# libc++/libc++abi.
333+
set(SANITIZER_CAN_USE_CXXABI FALSE)
334+
else()
335+
set(SANITIZER_CAN_USE_CXXABI TRUE)
336+
endif()
337+
pythonize_bool(SANITIZER_CAN_USE_CXXABI)
338+
330339
add_subdirectory(include)
331340

332341
set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx)

compiler-rt/lib/ubsan/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ set(UBSAN_CXXFLAGS ${SANITIZER_COMMON_CFLAGS})
2828
add_custom_target(ubsan)
2929

3030
if(APPLE)
31+
set(UBSAN_COMMON_SOURCES ${UBSAN_SOURCES})
32+
if(SANITIZER_CAN_USE_CXXABI)
33+
list(APPEND UBSAN_COMMON_SOURCES ${UBSAN_CXX_SOURCES})
34+
endif()
35+
3136
# Common parts of UBSan runtime.
3237
add_compiler_rt_object_libraries(RTUbsan
3338
OS ${SANITIZER_COMMON_SUPPORTED_OS}
3439
ARCHS ${UBSAN_COMMON_SUPPORTED_ARCH}
35-
SOURCES ${UBSAN_SOURCES} ${UBSAN_CXX_SOURCES}
40+
SOURCES ${UBSAN_COMMON_SOURCES}
3641
CFLAGS ${UBSAN_CXXFLAGS})
3742

3843
if(COMPILER_RT_HAS_UBSAN)

compiler-rt/test/lit.common.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ compiler_rt_debug = getattr(config, 'compiler_rt_debug', False)
9090
if not compiler_rt_debug:
9191
config.available_features.add('compiler-rt-optimized')
9292

93+
sanitizer_can_use_cxxabi = getattr(config, 'sanitizer_can_use_cxxabi', True)
94+
if sanitizer_can_use_cxxabi:
95+
config.available_features.add('cxxabi')
96+
9397
lit.util.usePlatformSdkOnDarwin(config, lit_config)
9498

9599
def is_darwin_lto_supported():

compiler-rt/test/lit.common.configured.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ set_default("python_executable", "@PYTHON_EXECUTABLE@")
2727
set_default("compiler_rt_debug", @COMPILER_RT_DEBUG_PYBOOL@)
2828
set_default("compiler_rt_libdir", "@COMPILER_RT_LIBRARY_OUTPUT_DIR@")
2929
set_default("emulator", "@COMPILER_RT_EMULATOR@")
30+
set_default("sanitizer_can_use_cxxabi", @SANITIZER_CAN_USE_CXXABI_PYBOOL@)
3031

3132
# LLVM tools dir can be passed in lit parameters, so try to
3233
# apply substitution.

compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr -g %s -O3 -o %t
22
// RUN: not %run %t 2>&1 | FileCheck %s
33

4+
// REQUIRES: cxxabi
5+
46
struct S { virtual int f() { return 0; } };
57
struct T : virtual S {};
68

compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// RUN: echo "vptr_check:S" > %t.loc-supp
2525
// RUN: UBSAN_OPTIONS="suppressions='%t.loc-supp'" not %run %t x- 2>&1 | FileCheck %s --check-prefix=CHECK-LOC-SUPPRESS
2626

27-
// REQUIRES: stable-runtime
27+
// REQUIRES: stable-runtime, cxxabi
2828
#include <new>
2929
#include <assert.h>
3030
#include <stdio.h>

0 commit comments

Comments
 (0)