[ubsan-minimal] Switch to weak symbols for callbacks to allow overriding in client code (#119242)

This commit is contained in:
Kirill Stoimenov 2024-12-13 15:10:40 -08:00 committed by GitHub
parent 1345ee4232
commit 71d2fa7988
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -48,7 +48,8 @@ static void format_msg(const char *kind, uintptr_t caller, char *buf,
*buf = '\0'; *buf = '\0';
} }
static void report_error(const char *kind, uintptr_t caller) { SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, const char *kind,
uintptr_t caller) {
if (caller == 0) if (caller == 0)
return; return;
while (true) { while (true) {
@ -114,13 +115,13 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
#define HANDLER_RECOVER(name, kind) \ #define HANDLER_RECOVER(name, kind) \
INTERFACE void __ubsan_handle_##name##_minimal() { \ INTERFACE void __ubsan_handle_##name##_minimal() { \
report_error(kind, GET_CALLER_PC()); \ __ubsan_report_error(kind, GET_CALLER_PC()); \
} }
#define HANDLER_NORECOVER(name, kind) \ #define HANDLER_NORECOVER(name, kind) \
INTERFACE void __ubsan_handle_##name##_minimal_abort() { \ INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
uintptr_t caller = GET_CALLER_PC(); \ uintptr_t caller = GET_CALLER_PC(); \
report_error(kind, caller); \ __ubsan_report_error(kind, caller); \
abort_with_message(kind, caller); \ abort_with_message(kind, caller); \
} }

View File

@ -0,0 +1,15 @@
// RUN: %clang -fsanitize=implicit-integer-sign-change %s -o %t && %run %t 0 2>&1 | FileCheck %s
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
static int Result;
void __ubsan_report_error(const char *kind, uintptr_t caller) {
fprintf(stderr, "CUSTOM_CALLBACK: %s\n", kind);
}
int main(int argc, const char **argv) {
int32_t t0 = (~((uint32_t)0));
// CHECK: CUSTOM_CALLBACK: implicit-conversion
}