[libcxx-commits] [libcxx] WIP [libc++][hardening] Overhaul the termination mechanism for hardening (PR #77823)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 11 13:46:24 PST 2024


================
@@ -0,0 +1,23 @@
+// -*- C++ -*-
----------------
ldionne wrote:

More discussion!

We could actually always use the overriding mechanism but provide our default definition for the assertion handler. That way, the code path for customizing the handler would always be tested, by definition. Something like:

```c++
// in CMakeLists.txt
set(LIBCXX_ASSERTION_HANDLER "libcxx/vendor/llvm/assertion_handler.in" CACHE STR)

// in libcxx/include/__assertion_handler.in
#ifndef _LIBCPP___ASSERTION_HANDLER
#define _LIBCPP___ASSERTION_HANDLER

#include <__availability>
#include <__config>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#  pragma GCC system_header
#endif

copy-paste the contents of @LIBCXX_ASSERTION_HANDLER@ at CMake configuration time

#endif // _LIBCPP___ASSERTION_HANDLER

// in libcxx/vendor/llvm/assertion_handler.in
#if HARDENING_MODE == DEBUG
#   define _LIBCPP_VERBOSE_TRAP(message) ::std::__libcpp_verbose_abort(...)
#else
#   define _LIBCPP_VERBOSE_TRAP(message) ((void)message, __builtin_trap())
#endif
```


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


More information about the libcxx-commits mailing list