[libcxx-commits] [libcxx] [libc++][hardening] Add an experimental function to log hardening errors (PR #149452)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 22 04:23:25 PDT 2025


================
@@ -0,0 +1,40 @@
+// -*- 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
+
+#if _LIBCPP_HAS_EXPERIMENTAL_HARDENING_OBSERVE_SEMANTIC
+
+_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_EXPORTED_FROM_ABI void __log_hardening_failure(const char* __message) _NOEXCEPT;
----------------
philnik777 wrote:

Regarding the discussion whether we should include a size parameter:
I agree that this isn't the most important function in terms of performance. I still think it's worth going over options, since there may very well be cases where it does matter.

I agree that it's probably fine to just pass a `char*`, since there is indeed not that much benefit to adding the size parameter if most system API calls (IMO unfortunately) only provide an unsized version.

Going the other way, do we expect this to be so rarely called that it should be considered cold? If that is indeed the case (which it should arguable be - I don't know whether reality disagrees), I think we should mark it as `[[gnu::cold]]`.

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


More information about the libcxx-commits mailing list