Skip to content

Commit ef34ade

Browse files
committed
Address feedback
1 parent 1fcfec3 commit ef34ade

File tree

7 files changed

+73
-53
lines changed

7 files changed

+73
-53
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ set(files
535535
__locale_dir/time.h
536536
__locale_dir/wbuffer_convert.h
537537
__locale_dir/wstring_convert.h
538-
__log_hardening_failure
538+
__log_error
539539
__math/abs.h
540540
__math/copysign.h
541541
__math/error_functions.h

libcxx/include/__configuration/availability.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@
304304
#define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15
305305
#define _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE
306306

307-
// This controls whether the library provides a function to log hardening failures without terminating the program (for
308-
// the `observe` assertion semantic).
309-
#define _LIBCPP_AVAILABILITY_HAS_LOG_HARDENING_FAILURE _LIBCPP_INTRODUCED_IN_LLVM_21
310-
#define _LIBCPP_AVAILABILITY_LOG_HARDENING_FAILURE _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE
307+
// This controls whether the library provides a function to log errors without terminating the program (used in
308+
// particular by the `observe` assertion semantic).
309+
#define _LIBCPP_AVAILABILITY_HAS_LOG_ERROR _LIBCPP_INTRODUCED_IN_LLVM_21
310+
#define _LIBCPP_AVAILABILITY_LOG_ERROR _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE
311311

312312
// This controls the availability of the C++17 std::pmr library,
313313
// which is implemented in large part in the built library.

libcxx/include/__log_error

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP___LOG_ERROR
11+
#define _LIBCPP___LOG_ERROR
12+
13+
#include <__config>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
21+
enum class _LogErrorReason {
22+
// Where possible, it logs in a way that indicates a fatal error (which might include capturing the stack trace).
23+
_HardeningFailure
24+
};
25+
26+
// This function should never be called directly from the code -- it should only be called through the
27+
// `_LIBCPP_LOG_ERROR` macro.
28+
_LIBCPP_AVAILABILITY_LOG_ERROR _LIBCPP_EXPORTED_FROM_ABI void
29+
__log_error(_LogErrorReason __reason, const char* __message) _NOEXCEPT;
30+
31+
// _LIBCPP_LOG_ERROR(message)
32+
//
33+
// This macro is used to log an error without terminating the program (as is the case for hardening failures if the
34+
// `observe` assertion semantic is used, for example).
35+
36+
#if !defined(_LIBCPP_LOG_ERROR)
37+
38+
# if !_LIBCPP_AVAILABILITY_HAS_LOG_ERROR
39+
// The decltype is there to suppress -Wunused warnings in this configuration.
40+
void __use(const char*);
41+
# define _LIBCPP_LOG_ERROR(__message) (decltype(::std::__use(__message))())
42+
# else
43+
# define _LIBCPP_LOG_ERROR(__reason, __message) ::std::__log_error(__reason, __message)
44+
# endif
45+
46+
#endif // !defined(_LIBCPP_LOG_ERROR)
47+
48+
_LIBCPP_END_NAMESPACE_STD
49+
50+
#endif // _LIBCPP___LOG_ERROR

libcxx/include/__log_hardening_failure

Lines changed: 0 additions & 45 deletions
This file was deleted.

libcxx/include/module.modulemap.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,6 +2353,9 @@ module std [system] {
23532353
header "__std_mbstate_t.h"
23542354
export *
23552355
}
2356+
module log_error {
2357+
header "__log_error"
2358+
}
23562359
module verbose_abort {
23572360
header "__verbose_abort"
23582361
}

libcxx/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ set(LIBCXX_SOURCES
3030
include/ryu/ryu.h
3131
include/to_chars_floating_point.h
3232
include/from_chars_floating_point.h
33-
log_hardening_failure.cpp
33+
log_error.cpp
3434
memory.cpp
3535
memory_resource.cpp
3636
new_handler.cpp

libcxx/src/log_hardening_failure.cpp renamed to libcxx/src/log_error.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <__config>
10-
#include <__log_hardening_failure>
10+
#include <__log_error>
1111
#include <cstdio>
1212

1313
#ifdef __BIONIC__
@@ -21,7 +21,9 @@ extern "C" void android_set_abort_message(const char* msg);
2121

2222
_LIBCPP_BEGIN_NAMESPACE_STD
2323

24-
_LIBCPP_WEAK void __libcpp_log_hardening_failure(const char* message) noexcept {
24+
namespace {
25+
26+
void log_fatal_error(const char* message) noexcept {
2527
// On Apple platforms, use the `os_fault_with_payload` OS function that simulates a crash.
2628
#if defined(__APPLE__) && __has_include(<os/reason_private.h>)
2729
os_fault_with_payload(
@@ -46,4 +48,14 @@ _LIBCPP_WEAK void __libcpp_log_hardening_failure(const char* message) noexcept {
4648
#endif
4749
}
4850

51+
} // namespace
52+
53+
void __log_error(_LogErrorReason reason, const char* message) noexcept {
54+
switch (reason) {
55+
case _LogErrorReason::_HardeningFailure:
56+
default:
57+
log_fatal_error(message);
58+
}
59+
}
60+
4961
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)