Skip to content

Commit 49e46a5

Browse files
authored
[UBSan] [compiler-rt] add preservecc variants of handlers (#168643)
1 parent 3723a8b commit 49e46a5

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, const char *kind,
8989
}
9090
}
9191

92+
SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error_preserve,
93+
const char *kind, uintptr_t caller,
94+
const uintptr_t *address)
95+
[[clang::preserve_all]] {
96+
// Additional indirecton so the user can override this with their own
97+
// preserve_all function. This would allow, e.g., a function that reports the
98+
// first error only, so for all subsequent calls we can skip the register save
99+
// / restore.
100+
__ubsan_report_error(kind, caller, address);
101+
}
102+
92103
SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error_fatal, const char *kind,
93104
uintptr_t caller, const uintptr_t *address) {
94105
// Use another handlers, in case it's already overriden.
@@ -130,6 +141,10 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
130141
#define HANDLER_RECOVER(name, kind) \
131142
INTERFACE void __ubsan_handle_##name##_minimal() { \
132143
__ubsan_report_error(kind, GET_CALLER_PC(), nullptr); \
144+
} \
145+
INTERFACE void __ubsan_handle_##name##_minimal_preserve() \
146+
[[clang::preserve_all]] { \
147+
__ubsan_report_error_preserve(kind, GET_CALLER_PC(), nullptr); \
133148
}
134149

135150
#define HANDLER_NORECOVER(name, kind) \
@@ -146,6 +161,10 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
146161
#define HANDLER_RECOVER_PTR(name, kind) \
147162
INTERFACE void __ubsan_handle_##name##_minimal(const uintptr_t address) { \
148163
__ubsan_report_error(kind, GET_CALLER_PC(), &address); \
164+
} \
165+
INTERFACE void __ubsan_handle_##name##_minimal_preserve( \
166+
const uintptr_t address) [[clang::preserve_all]] { \
167+
__ubsan_report_error_preserve(kind, GET_CALLER_PC(), &address); \
149168
}
150169

151170
#define HANDLER_NORECOVER_PTR(name, kind) \

compiler-rt/test/ubsan_minimal/TestCases/test-darwin-interface.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// REQUIRES: x86_64-darwin
55

66
// RUN: nm -jgU `%clangxx_min_runtime -fsanitize-minimal-runtime -fsanitize=undefined %s -o %t '-###' 2>&1 | grep "libclang_rt.ubsan_minimal_osx_dynamic.dylib" | sed -e 's/.*"\(.*libclang_rt.ubsan_minimal_osx_dynamic.dylib\)".*/\1/'` | grep "^___ubsan_handle" \
7+
// RUN: | grep -vE "_minimal_preserve" \
78
// RUN: | sed 's/_minimal//g' \
89
// RUN: > %t.minimal.symlist
910
//

0 commit comments

Comments
 (0)