[libcxx-commits] [libcxx] [libc++][hardening] Use `__builtin_verbose_trap` if it's available. (PR #84870)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 10 08:18:23 PDT 2024


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/84870

>From ea44facce3c00321cfae9da00835dec0ca5792e4 Mon Sep 17 00:00:00 2001
From: Konstantin Varlamov <varconst at apple.com>
Date: Mon, 11 Mar 2024 21:46:39 -0700
Subject: [PATCH 1/2] [libc++][hardening] Use `__builtin_verbose_trap` if it's
 available.

Keep falling back to `__builtin_trap` on older versions of Clang.
---
 libcxx/vendor/llvm/default_assertion_handler.in | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libcxx/vendor/llvm/default_assertion_handler.in b/libcxx/vendor/llvm/default_assertion_handler.in
index 8bc0553c078b3..8b892ff7b565e 100644
--- a/libcxx/vendor/llvm/default_assertion_handler.in
+++ b/libcxx/vendor/llvm/default_assertion_handler.in
@@ -23,8 +23,11 @@
 
 #else
 
-// TODO(hardening): use `__builtin_verbose_trap(message)` once that becomes available.
-#  define _LIBCPP_ASSERTION_HANDLER(message) ((void)message, __builtin_trap())
+#  if __has_builtin(__builtin_verbose_trap)
+#    define _LIBCPP_ASSERTION_HANDLER(message) (__builtin_verbose_trap(message))
+#  else
+#    define _LIBCPP_ASSERTION_HANDLER(message) ((void)message, __builtin_trap())
+#  endif
 
 #endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
 

>From 2a930defc5514a8025ae6cb562f9d12f3db6937a Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 10 Jul 2024 11:18:07 -0400
Subject: [PATCH 2/2] Add category to __builtin_verbose_trap

---
 libcxx/vendor/llvm/default_assertion_handler.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/vendor/llvm/default_assertion_handler.in b/libcxx/vendor/llvm/default_assertion_handler.in
index 8b892ff7b565e..9bd831c227798 100644
--- a/libcxx/vendor/llvm/default_assertion_handler.in
+++ b/libcxx/vendor/llvm/default_assertion_handler.in
@@ -24,7 +24,7 @@
 #else
 
 #  if __has_builtin(__builtin_verbose_trap)
-#    define _LIBCPP_ASSERTION_HANDLER(message) (__builtin_verbose_trap(message))
+#    define _LIBCPP_ASSERTION_HANDLER(message) __builtin_verbose_trap("libc++", message)
 #  else
 #    define _LIBCPP_ASSERTION_HANDLER(message) ((void)message, __builtin_trap())
 #  endif



More information about the libcxx-commits mailing list