Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit d1997bf

Browse files
committed
[sanitizer] Support libc++abi in addition to libstdc++
This change adds sanitizer support for LLVM's libunwind and libc++abi as an alternative to libstdc++. This allows using the in tree version of libunwind and libc++abi which is useful when building a toolchain for different target. Differential Revision: https://reviews.llvm.org/D34501 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@309074 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent fd63314 commit d1997bf

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,40 @@ endif()
9494
option(SANITIZER_CAN_USE_CXXABI "Sanitizers can use cxxabi" ${use_cxxabi_default})
9595
pythonize_bool(SANITIZER_CAN_USE_CXXABI)
9696

97+
set(SANITIZER_CXX_ABI "default" CACHE STRING
98+
"Specify C++ ABI library to use.")
99+
set(CXXABIS none default libcxxabi libstdc++)
100+
set_property(CACHE SANITIZER_CXX_ABI PROPERTY STRINGS ;${CXXABIS})
101+
102+
if (SANITIZER_CXX_ABI STREQUAL "default")
103+
if (HAVE_LIBCXXABI AND COMPILER_RT_DEFAULT_TARGET_ONLY)
104+
set(SANITIZER_CXX_ABI_LIBNAME "libcxxabi")
105+
set(SANITIZER_CXX_ABI_INTREE 1)
106+
elseif (APPLE)
107+
set(SANITIZER_CXX_ABI_LIBNAME "libcxxabi")
108+
set(SANITIZER_CXX_ABI_SYSTEM 1)
109+
else()
110+
set(SANITIZER_CXX_ABI_LIBNAME "libstdc++")
111+
endif()
112+
elseif()
113+
set(SANITIZER_CXX_ABI_LIBNAME "${SANITIZER_CXX_ABI}")
114+
endif()
115+
116+
if (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libcxxabi")
117+
if (SANITIZER_CXX_ABI_INTREE)
118+
if (TARGET unwind_shared OR HAVE_LIBUNWIND)
119+
list(APPEND SANITIZER_CXX_ABI_LIBRARY unwind_shared)
120+
endif()
121+
if (TARGET cxxabi_shared OR HAVE_LIBCXXABI)
122+
list(APPEND SANITIZER_CXX_ABI_LIBRARY cxxabi_shared)
123+
endif()
124+
else()
125+
list(APPEND SANITIZER_CXX_ABI_LIBRARY "c++abi")
126+
endif()
127+
elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libstdc++")
128+
append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_CXX_ABI_LIBRARY)
129+
endif()
130+
97131
option(SANITIZER_USE_COMPILER_RT "Use compiler-rt builtins instead of libgcc" OFF)
98132

99133
#================================

lib/asan/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ append_list_if(COMPILER_RT_HAS_LIBDL dl ASAN_DYNAMIC_LIBS)
7171
append_list_if(COMPILER_RT_HAS_LIBRT rt ASAN_DYNAMIC_LIBS)
7272
append_list_if(COMPILER_RT_HAS_LIBM m ASAN_DYNAMIC_LIBS)
7373
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread ASAN_DYNAMIC_LIBS)
74-
append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ ASAN_DYNAMIC_LIBS)
7574
append_list_if(COMPILER_RT_HAS_LIBLOG log ASAN_DYNAMIC_LIBS)
7675

76+
list(APPEND ASAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARY})
77+
7778
# Compile ASan sources into an object library.
7879

7980
add_compiler_rt_object_libraries(RTAsan_dynamic

lib/tsan/dd/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ set(DD_LINKLIBS ${SANITIZER_COMMON_LINK_LIBS})
1515
append_list_if(COMPILER_RT_HAS_LIBDL dl DD_LINKLIBS)
1616
append_list_if(COMPILER_RT_HAS_LIBRT rt DD_LINKLIBS)
1717
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread DD_LINKLIBS)
18-
append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ DD_LINKLIBS)
18+
19+
list(APPEND DD_LINKLIBS ${SANITIZER_CXX_ABI_LIBRARY})
1920

2021
add_custom_target(dd)
2122
# Deadlock detector is currently supported on 64-bit Linux only.

lib/ubsan/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ set(UBSAN_DYNAMIC_LIBS ${SANITIZER_COMMON_LINK_LIBS})
3939
append_list_if(COMPILER_RT_HAS_LIBDL dl UBSAN_DYNAMIC_LIBS)
4040
append_list_if(COMPILER_RT_HAS_LIBRT rt UBSAN_DYNAMIC_LIBS)
4141
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread UBSAN_DYNAMIC_LIBS)
42-
append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ UBSAN_DYNAMIC_LIBS)
42+
43+
list(APPEND UBSAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARY})
4344

4445
add_compiler_rt_component(ubsan)
4546

0 commit comments

Comments
 (0)