Skip to content

Commit e044b22

Browse files
committed
Merge branch 'varconst/hardening-semantics-log_fatal_error' into varconst/hardening-semantics-introduce
2 parents cde8697 + 01eb85d commit e044b22

File tree

9 files changed

+84
-55
lines changed

9 files changed

+84
-55
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/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@
534534
{'is_defined': True, 'name': '__ZNKSt3__115basic_streambufIwNS_11char_traitsIwEEE6getlocEv', 'type': 'FUNC'}
535535
{'is_defined': True, 'name': '__ZNKSt3__115basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEE3strEv', 'type': 'FUNC'}
536536
{'is_defined': True, 'name': '__ZNKSt3__115error_condition7messageEv', 'type': 'FUNC'}
537+
{'is_defined': True, 'name': '__ZNKSt3__117bad_function_call4whatEv', 'type': 'FUNC'}
537538
{'is_defined': True, 'name': '__ZNKSt3__117moneypunct_bynameIcLb0EE11do_groupingEv', 'type': 'FUNC'}
538539
{'is_defined': True, 'name': '__ZNKSt3__117moneypunct_bynameIcLb0EE13do_neg_formatEv', 'type': 'FUNC'}
539540
{'is_defined': True, 'name': '__ZNKSt3__117moneypunct_bynameIcLb0EE13do_pos_formatEv', 'type': 'FUNC'}
@@ -944,6 +945,7 @@
944945
{'is_defined': True, 'name': '__ZNSt3__110to_wstringEx', 'type': 'FUNC'}
945946
{'is_defined': True, 'name': '__ZNSt3__110to_wstringEy', 'type': 'FUNC'}
946947
{'is_defined': True, 'name': '__ZNSt3__111__call_onceERVmPvPFvS2_E', 'type': 'FUNC'}
948+
{'is_defined': True, 'name': '__ZNSt3__111__log_errorENS_15_LogErrorReasonEPKc', 'type': 'FUNC'}
947949
{'is_defined': True, 'name': '__ZNSt3__111__money_getIcE13__gather_infoEbRKNS_6localeERNS_10money_base7patternERcS8_RNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEESF_SF_SF_Ri', 'type': 'FUNC'}
948950
{'is_defined': True, 'name': '__ZNSt3__111__money_getIwE13__gather_infoEbRKNS_6localeERNS_10money_base7patternERwS8_RNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERNS9_IwNSA_IwEENSC_IwEEEESJ_SJ_Ri', 'type': 'FUNC'}
949951
{'is_defined': True, 'name': '__ZNSt3__111__money_putIcE13__gather_infoEbbRKNS_6localeERNS_10money_base7patternERcS8_RNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEESF_SF_Ri', 'type': 'FUNC'}
@@ -1125,6 +1127,7 @@
11251127
{'is_defined': True, 'name': '__ZNSt3__112system_errorD0Ev', 'type': 'FUNC'}
11261128
{'is_defined': True, 'name': '__ZNSt3__112system_errorD1Ev', 'type': 'FUNC'}
11271129
{'is_defined': True, 'name': '__ZNSt3__112system_errorD2Ev', 'type': 'FUNC'}
1130+
{'is_defined': True, 'name': '__ZNSt3__113__hash_memoryEPKvm', 'type': 'FUNC'}
11281131
{'is_defined': True, 'name': '__ZNSt3__113basic_filebufIcNS_11char_traitsIcEEE11__read_modeEv', 'type': 'FUNC'}
11291132
{'is_defined': True, 'name': '__ZNSt3__113basic_filebufIcNS_11char_traitsIcEEE12__write_modeEv', 'type': 'FUNC'}
11301133
{'is_defined': True, 'name': '__ZNSt3__113basic_filebufIcNS_11char_traitsIcEEE4openEPKcj', 'type': 'FUNC'}
@@ -1305,7 +1308,6 @@
13051308
{'is_defined': True, 'name': '__ZNSt3__113shared_futureIvED1Ev', 'type': 'FUNC'}
13061309
{'is_defined': True, 'name': '__ZNSt3__113shared_futureIvED2Ev', 'type': 'FUNC'}
13071310
{'is_defined': True, 'name': '__ZNSt3__113shared_futureIvEaSERKS1_', 'type': 'FUNC'}
1308-
{'is_defined': True, 'name': '__ZNSt3__113__hash_memoryEPKvm', 'type': 'FUNC'}
13091311
{'is_defined': True, 'name': '__ZNSt3__114__num_get_base10__get_baseERNS_8ios_baseE', 'type': 'FUNC'}
13101312
{'is_defined': True, 'name': '__ZNSt3__114__num_get_base5__srcE', 'size': 0, 'type': 'OBJECT'}
13111313
{'is_defined': True, 'name': '__ZNSt3__114__num_put_base12__format_intEPcPKcbj', 'type': 'FUNC'}
@@ -1508,7 +1510,6 @@
15081510
{'is_defined': True, 'name': '__ZNSt3__117bad_function_callD0Ev', 'type': 'FUNC'}
15091511
{'is_defined': True, 'name': '__ZNSt3__117bad_function_callD1Ev', 'type': 'FUNC'}
15101512
{'is_defined': True, 'name': '__ZNSt3__117bad_function_callD2Ev', 'type': 'FUNC'}
1511-
{'is_defined': True, 'name': '__ZNKSt3__117bad_function_call4whatEv', 'type': 'FUNC'}
15121513
{'is_defined': True, 'name': '__ZNSt3__117iostream_categoryEv', 'type': 'FUNC'}
15131514
{'is_defined': True, 'name': '__ZNSt3__117moneypunct_bynameIcLb0EE4initEPKc', 'type': 'FUNC'}
15141515
{'is_defined': True, 'name': '__ZNSt3__117moneypunct_bynameIcLb1EE4initEPKc', 'type': 'FUNC'}

libcxx/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ 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
3433
memory.cpp
34+
log_error.cpp
3535
memory_resource.cpp
3636
new_handler.cpp
3737
new_helpers.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_security_failure(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_security_failure(message);
58+
}
59+
}
60+
4961
_LIBCPP_END_NAMESPACE_STD

libcxx/utils/libcxx/test/features.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,14 @@ def check_gdb(cfg):
894894
cfg.available_features,
895895
),
896896
),
897+
# Tests that require __log_error support in the built library
898+
Feature(
899+
name="availability-log_error-missing",
900+
when=lambda cfg: BooleanExpression.evaluate(
901+
"!libcpp-has-no-availability-markup && (stdlib=apple-libc++ && !_target-has-llvm-21)",
902+
cfg.available_features,
903+
),
904+
),
897905
# Tests that require std::pmr support in the built library
898906
Feature(
899907
name="availability-pmr-missing",

0 commit comments

Comments
 (0)