Skip to content

Commit

Permalink
Add default __assertion_handler to libcxx/include
Browse files Browse the repository at this point in the history
llvm/llvm-project#77883 adds a way for vendors
to override how we handle assertions. If a vendor doesn't want to
override it, `CMakeLists.txt` will copy the provided default template
assertion handler file
(https://github.com/llvm/llvm-project/blob/26a1d6601d727a96f4301d0d8647b5a42760ae0c/libcxx/vendor/llvm/default_assertion_handler.in)
to libcxx's generated include dir, which defaults to
`SYSROOT/include/c++/v1`:
https://github.com/llvm/llvm-project/blob/26a1d6601d727a96f4301d0d8647b5a42760ae0c/libcxx/CMakeLists.txt#L72-L73
https://github.com/llvm/llvm-project/blob/26a1d6601d727a96f4301d0d8647b5a42760ae0c/libcxx/CMakeLists.txt#L439
https://github.com/llvm/llvm-project/blob/26a1d6601d727a96f4301d0d8647b5a42760ae0c/libcxx/include/CMakeLists.txt#L1024

We don't use CMake, so this renames the provided
`vendor/llvm/default_assertion_handler.in` to `__assert_handler` in our
`include` directory, which will be copied to `SYSROOT/include/c++/v1`.
  • Loading branch information
aheejin committed Mar 28, 2024
1 parent e508f3d commit 8d51927
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions system/lib/libcxx/include/__assertion_handler
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___ASSERTION_HANDLER
#define _LIBCPP___ASSERTION_HANDLER

#include <__config>
#include <__verbose_abort>

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

#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG

# define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_VERBOSE_ABORT("%s", message)

#else

// TODO(hardening): use `__builtin_verbose_trap(message)` once that becomes available.
# define _LIBCPP_ASSERTION_HANDLER(message) ((void)message, __builtin_trap())

#endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG

#endif // _LIBCPP___ASSERTION_HANDLER

0 comments on commit 8d51927

Please sign in to comment.