[compiler-rt] 71d2fa7 - [ubsan-minimal] Switch to weak symbols for callbacks to allow overriding in client code (#119242)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 13 15:10:44 PST 2024
Author: Kirill Stoimenov
Date: 2024-12-13T15:10:40-08:00
New Revision: 71d2fa7988f4ce4647b6ed387cf5b51dafa11e4c
URL: https://github.com/llvm/llvm-project/commit/71d2fa7988f4ce4647b6ed387cf5b51dafa11e4c
DIFF: https://github.com/llvm/llvm-project/commit/71d2fa7988f4ce4647b6ed387cf5b51dafa11e4c.diff
LOG: [ubsan-minimal] Switch to weak symbols for callbacks to allow overriding in client code (#119242)
Added:
compiler-rt/test/ubsan_minimal/TestCases/override-callback.c
Modified:
compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp b/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
index cd0b38618c5cb2..98662c5881c9f9 100644
--- a/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
+++ b/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
@@ -48,7 +48,8 @@ static void format_msg(const char *kind, uintptr_t caller, char *buf,
*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)
return;
while (true) {
@@ -114,13 +115,13 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
#define HANDLER_RECOVER(name, kind) \
INTERFACE void __ubsan_handle_##name##_minimal() { \
- report_error(kind, GET_CALLER_PC()); \
+ __ubsan_report_error(kind, GET_CALLER_PC()); \
}
#define HANDLER_NORECOVER(name, kind) \
INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
uintptr_t caller = GET_CALLER_PC(); \
- report_error(kind, caller); \
+ __ubsan_report_error(kind, caller); \
abort_with_message(kind, caller); \
}
diff --git a/compiler-rt/test/ubsan_minimal/TestCases/override-callback.c b/compiler-rt/test/ubsan_minimal/TestCases/override-callback.c
new file mode 100644
index 00000000000000..e11a3712f1be3b
--- /dev/null
+++ b/compiler-rt/test/ubsan_minimal/TestCases/override-callback.c
@@ -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
+}
More information about the llvm-commits
mailing list