Skip to content

Commit 2f856a3

Browse files
committed
[msan] Blacklist __gxx_personality_v0.
Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=31877. Fixes google/sanitizers#1155. Enables exceptions in msan/tsan buid of libcxx, and in msan tests. -fdepfile-entry stuff is a workaround for https://reviews.llvm.org/D69290 (default blacklist missing from -MMD output). Reviewers: pcc, dvyukov Subscribers: mgorny, christof, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D69587
1 parent cb19ea4 commit 2f856a3

File tree

6 files changed

+41
-5
lines changed

6 files changed

+41
-5
lines changed

compiler-rt/cmake/Modules/AddCompilerRT.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ macro(add_custom_libcxx name prefix)
623623
USES_TERMINAL_BUILD 1
624624
USES_TERMINAL_INSTALL 1
625625
EXCLUDE_FROM_ALL TRUE
626+
BUILD_BYPRODUCTS "${prefix}/lib/libc++.a" "${prefix}/lib/libc++abi.a"
626627
)
627628

628629
if (CMAKE_GENERATOR MATCHES "Make")

compiler-rt/cmake/Modules/CustomLibcxx/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project(custom-libcxx C CXX)
44
# Build static libcxxabi.
55
set(LIBCXXABI_STANDALONE_BUILD 1)
66
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
7-
set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
7+
set(LIBCXXABI_ENABLE_EXCEPTIONS ON CACHE BOOL "")
88
set(LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE STRING "")
99
set(LIBCXXABI_LIBCXX_PATH ${COMPILER_RT_LIBCXX_PATH} CACHE PATH "")
1010
set(LIBCXXABI_INCLUDE_TESTS OFF CACHE BOOL "")

compiler-rt/lib/msan/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ foreach(arch ${MSAN_SUPPORTED_ARCH})
8181
endforeach()
8282

8383
add_compiler_rt_resource_file(msan_blacklist msan_blacklist.txt msan)
84+
list(APPEND MSAN_RUNTIME_LIBRARIES msan_blacklist)
8485

8586
if(COMPILER_RT_INCLUDE_TESTS)
8687
add_subdirectory(tests)

compiler-rt/lib/msan/msan_blacklist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
# Example usage:
66
# fun:*bad_function_name*
77
# src:file_with_tricky_code.cc
8+
9+
# https://bugs.llvm.org/show_bug.cgi?id=31877
10+
fun:__gxx_personality_*

compiler-rt/lib/msan/tests/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ include_directories(../..)
88
set(MSAN_LIBCXX_CFLAGS
99
-fsanitize=memory
1010
-fsanitize-memory-track-origins
11-
-Wno-pedantic)
11+
-Wno-pedantic
12+
-Xclang -fdepfile-entry=${COMPILER_RT_OUTPUT_DIR}/share/msan_blacklist.txt
13+
)
1214

1315
# Unittest sources and build flags.
1416
set(MSAN_UNITTEST_SOURCES
@@ -32,7 +34,6 @@ set(MSAN_UNITTEST_COMMON_CFLAGS
3234
-I${COMPILER_RT_SOURCE_DIR}/lib/msan
3335
-g
3436
-O2
35-
-fno-exceptions
3637
-fno-omit-frame-pointer
3738
-mno-omit-leaf-frame-pointer
3839
-Wno-deprecated-declarations
@@ -114,13 +115,14 @@ macro(add_msan_tests_for_arch arch kind cflags)
114115

115116
set(MSAN_TEST_OBJECTS ${MSAN_INST_TEST_OBJECTS} ${MSAN_INST_GTEST})
116117
set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan_${arch}-build
117-
${MSAN_LOADABLE_SO})
118+
${MSAN_LOADABLE_SO}
119+
"${MSAN_LIBCXX_DIR}/libc++.a" "${MSAN_LIBCXX_DIR}/libc++abi.a")
118120
if(NOT COMPILER_RT_STANDALONE_BUILD)
119121
list(APPEND MSAN_TEST_DEPS msan)
120122
endif()
121123
get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
122124
add_compiler_rt_test(MsanUnitTests "Msan-${arch}${kind}-Test" ${arch}
123-
OBJECTS ${MSAN_TEST_OBJECTS} "${MSAN_LIBCXX_DIR}/libc++.a"
125+
OBJECTS ${MSAN_TEST_OBJECTS} "${MSAN_LIBCXX_DIR}/libc++.a" "${MSAN_LIBCXX_DIR}/libc++abi.a"
124126
DEPS ${MSAN_TEST_DEPS}
125127
LINK_FLAGS ${MSAN_UNITTEST_LINK_FLAGS}
126128
${TARGET_LINK_FLAGS})

compiler-rt/lib/msan/tests/msan_test.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4798,3 +4798,32 @@ TEST(MemorySanitizer, Bmi) {
47984798
}
47994799
}
48004800
#endif // defined(__x86_64__)
4801+
4802+
namespace {
4803+
volatile long z;
4804+
4805+
__attribute__((noinline,optnone)) void f(long a, long b, long c, long d, long e, long f) {
4806+
z = a + b + c + d + e + f;
4807+
}
4808+
4809+
__attribute__((noinline,optnone)) void throw_stuff() {
4810+
throw 5;
4811+
}
4812+
4813+
TEST(MemorySanitizer, throw_catch) {
4814+
long x;
4815+
// Poison __msan_param_tls.
4816+
__msan_poison(&x, sizeof(x));
4817+
f(x, x, x, x, x, x);
4818+
try {
4819+
// This calls __gxx_personality_v0 through some libgcc_s function.
4820+
// __gxx_personality_v0 is instrumented, libgcc_s is not; as a result,
4821+
// __msan_param_tls is not updated and __gxx_personality_v0 can find
4822+
// leftover poison from the previous call.
4823+
// A suppression in msan_blacklist.txt makes it work.
4824+
throw_stuff();
4825+
} catch (const int &e) {
4826+
// pass
4827+
}
4828+
}
4829+
} // namespace

0 commit comments

Comments
 (0)