[libcxx-commits] [libcxx] [libc++][hardening] Introduce a dylib function to log hardening errors. (PR #148266)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 11 11:42:53 PDT 2025


================
@@ -0,0 +1,45 @@
+// -*- 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___LOG_HARDENING_FAILURE
+#define _LIBCPP___LOG_HARDENING_FAILURE
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// This function should never be called directly from the code -- it should only be called through the
+// `_LIBCPP_LOG_HARDENING_FAILURE` macro.
+_LIBCPP_AVAILABILITY_LOG_HARDENING_FAILURE _LIBCPP_OVERRIDABLE_FUNC_VIS void
+__libcpp_log_hardening_failure(const char* message) _NOEXCEPT;
+
+// _LIBCPP_LOG_HARDENING_FAILURE(message)
----------------
ldionne wrote:

We might want to slightly generalize this into  `_LIBCPP_LOG_FATAL_ERROR`? And we could also accept an enum with a category so we can extend the reasons for logging later on. Alternatively, we might want to make this just `_LIBCPP_LOG_ERROR` since we're accepting a reason, so the reason could be `HARDENING`, `FATAL` or whatever we have a use case for.

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


More information about the libcxx-commits mailing list