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

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 11:56:19 PST 2024


================
@@ -44,35 +74,24 @@ __attribute__((noinline)) static bool report_this_error(uintptr_t caller) {
 
     if (sz == kMaxCallerPcs) {
       message("ubsan: too many errors\n");
-      return false;
+      return;
     }
     __sanitizer::atomic_store_relaxed(&caller_pcs[sz], caller);
-    return true;
-  }
-}
 
-__attribute__((noinline)) static void decorate_msg(char *buf,
-                                                   uintptr_t caller) {
-  // print the address by nibbles
-  for (unsigned shift = sizeof(uintptr_t) * 8; shift;) {
-    shift -= 4;
-    unsigned nibble = (caller >> shift) & 0xf;
-    *(buf++) = nibble < 10 ? nibble + '0' : nibble - 10 + 'a';
-  }
-  // finish the message
-  buf[0] = '\n';
-  buf[1] = '\0';
-}
+    char msg_buf[128] = MSG_PREFIX;
+    const char *end = msg_buf + sizeof(msg_buf);
+    char *p = append_str(msg, msg_buf + sizeof(MSG_PREFIX) - 1, end);
----------------
vitalybuka wrote:

insted of sizeof(MSG_PREFIX) - 1, making 
```
char msg_buf[128];
p = append_str(PREFIX, p, end);
p = append_str(msg, p, end);
```

https://github.com/llvm/llvm-project/pull/119242


More information about the llvm-commits mailing list