[compiler-rt] [llvm] [compiler-rt][UBSan] Add __ubsan_default_suppressions() hook (PR #194862)

Kleis Auke Wolthuizen via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 29 07:00:00 PDT 2026


https://github.com/kleisauke updated https://github.com/llvm/llvm-project/pull/194862

>From a95016a7c06b903c9c7393a721cd2c6e40b0d89f Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <github at kleisauke.nl>
Date: Wed, 29 Apr 2026 15:32:49 +0200
Subject: [PATCH 1/2] [compiler-rt][UBSan] Add __ubsan_default_suppressions()
 hook

In line with commit 5c62af5 and 83566da.
---
 compiler-rt/lib/ubsan/ubsan_diag.cpp                       | 7 +++++++
 compiler-rt/lib/ubsan/ubsan_interface.inc                  | 1 +
 compiler-rt/lib/ubsan/weak_symbols.txt                     | 1 +
 .../test/ubsan/TestCases/Misc/Posix/ubsan_suppressions.cpp | 7 +++++++
 llvm/utils/gn/secondary/compiler-rt/lib/asan/BUILD.gn      | 1 +
 llvm/utils/gn/secondary/compiler-rt/lib/ubsan/BUILD.gn     | 1 +
 6 files changed, 18 insertions(+)
 create mode 100644 compiler-rt/test/ubsan/TestCases/Misc/Posix/ubsan_suppressions.cpp

diff --git a/compiler-rt/lib/ubsan/ubsan_diag.cpp b/compiler-rt/lib/ubsan/ubsan_diag.cpp
index 2146ed3c27287..6ec81736d4502 100644
--- a/compiler-rt/lib/ubsan/ubsan_diag.cpp
+++ b/compiler-rt/lib/ubsan/ubsan_diag.cpp
@@ -16,6 +16,7 @@
 #include "ubsan_init.h"
 #include "ubsan_flags.h"
 #include "ubsan_monitor.h"
+#include "sanitizer_common/sanitizer_internal_defs.h"
 #include "sanitizer_common/sanitizer_placement_new.h"
 #include "sanitizer_common/sanitizer_report_decorator.h"
 #include "sanitizer_common/sanitizer_stacktrace.h"
@@ -26,6 +27,11 @@
 
 using namespace __ubsan;
 
+// Can be overriden in frontend.
+SANITIZER_INTERFACE_WEAK_DEF(const char *, __ubsan_default_suppressions, void) {
+  return "";
+}
+
 // UBSan is combined with runtimes that already provide this functionality
 // (e.g., ASan) as well as runtimes that lack it (e.g., scudo). Tried to use
 // weak linkage to resolve this issue which is not portable and breaks on
@@ -417,6 +423,7 @@ void __ubsan::InitializeSuppressions() {
   suppression_ctx = new (suppression_placeholder)
       SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
   suppression_ctx->ParseFromFile(flags()->suppressions);
+  suppression_ctx->Parse(__ubsan_default_suppressions());
 }
 
 bool __ubsan::IsVptrCheckSuppressed(const char *TypeName) {
diff --git a/compiler-rt/lib/ubsan/ubsan_interface.inc b/compiler-rt/lib/ubsan/ubsan_interface.inc
index 0eb109f37d445..7a9cb9b336f6e 100644
--- a/compiler-rt/lib/ubsan/ubsan_interface.inc
+++ b/compiler-rt/lib/ubsan/ubsan_interface.inc
@@ -59,5 +59,6 @@ INTERFACE_FUNCTION(__ubsan_handle_type_mismatch_v1_abort)
 INTERFACE_FUNCTION(__ubsan_handle_vla_bound_not_positive)
 INTERFACE_FUNCTION(__ubsan_handle_vla_bound_not_positive_abort)
 INTERFACE_WEAK_FUNCTION(__ubsan_default_options)
+INTERFACE_WEAK_FUNCTION(__ubsan_default_suppressions)
 INTERFACE_FUNCTION(__ubsan_on_report)
 INTERFACE_FUNCTION(__ubsan_get_current_report_data)
diff --git a/compiler-rt/lib/ubsan/weak_symbols.txt b/compiler-rt/lib/ubsan/weak_symbols.txt
index 69e1bc1857ed6..587a6aee18dff 100644
--- a/compiler-rt/lib/ubsan/weak_symbols.txt
+++ b/compiler-rt/lib/ubsan/weak_symbols.txt
@@ -1 +1,2 @@
 ___ubsan_default_options
+___ubsan_default_suppressions
diff --git a/compiler-rt/test/ubsan/TestCases/Misc/Posix/ubsan_suppressions.cpp b/compiler-rt/test/ubsan/TestCases/Misc/Posix/ubsan_suppressions.cpp
new file mode 100644
index 0000000000000..6936c56bb2256
--- /dev/null
+++ b/compiler-rt/test/ubsan/TestCases/Misc/Posix/ubsan_suppressions.cpp
@@ -0,0 +1,7 @@
+// Test that we use the suppressions from __ubsan_default_suppressions.
+// RUN: %clangxx -fsanitize=undefined %s -o %t && not %run %t 2>&1 | FileCheck %s
+extern "C" {
+  const char *__ubsan_default_suppressions() { return "FooBar"; }
+}
+// CHECK: UndefinedBehaviorSanitizer: failed to parse suppressions
+int main() {}
diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/asan/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/asan/BUILD.gn
index ab8ea1ffb56b0..290aa3f77a7d9 100644
--- a/llvm/utils/gn/secondary/compiler-rt/lib/asan/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/lib/asan/BUILD.gn
@@ -109,6 +109,7 @@ if (current_toolchain == host_toolchain) {
 
         # ubsan
         "-Wl,-U,___ubsan_default_options",
+        "-Wl,-U,___ubsan_default_suppressions",
 
         # sanitizer_common
         "-Wl,-U,___sanitizer_free_hook",
diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/ubsan/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/ubsan/BUILD.gn
index 541b86ad0970e..c6a511c3c714c 100644
--- a/llvm/utils/gn/secondary/compiler-rt/lib/ubsan/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/lib/ubsan/BUILD.gn
@@ -176,6 +176,7 @@ shared_library("ubsan_shared") {
 
       # ubsan
       "-Wl,-U,___ubsan_default_options",
+      "-Wl,-U,___ubsan_default_suppressions",
 
       # sanitizer_common
       "-Wl,-U,___sanitizer_free_hook",

>From b68cc81762ce5fd09d829442c544651124f7bb0b Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <github at kleisauke.nl>
Date: Wed, 29 Apr 2026 15:59:28 +0200
Subject: [PATCH 2/2] Fix CI

---
 .../test/ubsan/TestCases/Misc/Posix/ubsan_suppressions.cpp      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/test/ubsan/TestCases/Misc/Posix/ubsan_suppressions.cpp b/compiler-rt/test/ubsan/TestCases/Misc/Posix/ubsan_suppressions.cpp
index 6936c56bb2256..ffc42ab436664 100644
--- a/compiler-rt/test/ubsan/TestCases/Misc/Posix/ubsan_suppressions.cpp
+++ b/compiler-rt/test/ubsan/TestCases/Misc/Posix/ubsan_suppressions.cpp
@@ -3,5 +3,5 @@
 extern "C" {
   const char *__ubsan_default_suppressions() { return "FooBar"; }
 }
-// CHECK: UndefinedBehaviorSanitizer: failed to parse suppressions
+// CHECK: {{.*}}Sanitizer: failed to parse suppressions
 int main() {}



More information about the llvm-commits mailing list