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

Konstantin Varlamov via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 17 16:53:26 PDT 2025


================
@@ -0,0 +1,50 @@
+// -*- 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_ERROR
+#define _LIBCPP___LOG_ERROR
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+enum class _LogErrorReason {
+  // Where possible, it logs in a way that indicates a fatal error (which might include capturing the stack trace).
+  _HardeningFailure
+};
+
+// This function should never be called directly from the code -- it should only be called through the
+// `_LIBCPP_LOG_ERROR` macro.
+_LIBCPP_AVAILABILITY_LOG_ERROR _LIBCPP_EXPORTED_FROM_ABI void
+__log_error(_LogErrorReason __reason, const char* __message) _NOEXCEPT;
----------------
var-const wrote:

> `__log_hardening_failue` shouldn't terminate, right?

Yes, it's a regular, non-terminating, function.

> The platform-specific APIs do look like they're terminating though. Or am I mis-reading this?

They do not terminate. On Apple platforms, `os_fault_with_payload` produces crash data as if a crash occurred but doesn't actually crash the program. On Android, I don't think logging with `syslog` ever terminates regardless of the severity level, and `android_set_abort_message`, to the best of my knowledge, merely copies the error message to some global location.

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


More information about the libcxx-commits mailing list