Skip to content

Commit 71d2fa7

Browse files
authored
[ubsan-minimal] Switch to weak symbols for callbacks to allow overriding in client code (#119242)
1 parent 1345ee4 commit 71d2fa7

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ static void format_msg(const char *kind, uintptr_t caller, char *buf,
4848
*buf = '\0';
4949
}
5050

51-
static void report_error(const char *kind, uintptr_t caller) {
51+
SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, const char *kind,
52+
uintptr_t caller) {
5253
if (caller == 0)
5354
return;
5455
while (true) {
@@ -114,13 +115,13 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
114115

115116
#define HANDLER_RECOVER(name, kind) \
116117
INTERFACE void __ubsan_handle_##name##_minimal() { \
117-
report_error(kind, GET_CALLER_PC()); \
118+
__ubsan_report_error(kind, GET_CALLER_PC()); \
118119
}
119120

120121
#define HANDLER_NORECOVER(name, kind) \
121122
INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
122123
uintptr_t caller = GET_CALLER_PC(); \
123-
report_error(kind, caller); \
124+
__ubsan_report_error(kind, caller); \
124125
abort_with_message(kind, caller); \
125126
}
126127

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang -fsanitize=implicit-integer-sign-change %s -o %t && %run %t 0 2>&1 | FileCheck %s
2+
#include <stdint.h>
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
6+
static int Result;
7+
8+
void __ubsan_report_error(const char *kind, uintptr_t caller) {
9+
fprintf(stderr, "CUSTOM_CALLBACK: %s\n", kind);
10+
}
11+
12+
int main(int argc, const char **argv) {
13+
int32_t t0 = (~((uint32_t)0));
14+
// CHECK: CUSTOM_CALLBACK: implicit-conversion
15+
}

0 commit comments

Comments
 (0)