authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-01-17 05:25:15+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-04-25 21:49:39+02:00
log80212b03ff792ddfff82092b35aa7ed0fdf937a8
tree67b5207200c4a36b4c4f00ded143d782e2f8db1c
parent520af6966041b891442ab34ac13b0f6861a09fc0
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

libcxxabi: update to LLVM 22


11 files changed, 235 insertions(+), 71 deletions(-)

lib/libcxxabi/include/__cxxabi_config.h+42-23
...@@ -14,10 +14,6 @@...@@ -14,10 +14,6 @@
14#define _LIBCXXABI_ARM_EHABI14#define _LIBCXXABI_ARM_EHABI
15#endif15#endif
1616
17#if !defined(__has_attribute)
18#define __has_attribute(_attribute_) 0
19#endif
20
21#if defined(__clang__)17#if defined(__clang__)
22# define _LIBCXXABI_COMPILER_CLANG18# define _LIBCXXABI_COMPILER_CLANG
23# ifndef __apple_build_version__19# ifndef __apple_build_version__
...@@ -25,10 +21,6 @@...@@ -25,10 +21,6 @@
25# endif21# endif
26#elif defined(__GNUC__)22#elif defined(__GNUC__)
27# define _LIBCXXABI_COMPILER_GCC23# define _LIBCXXABI_COMPILER_GCC
28#elif defined(_MSC_VER)
29# define _LIBCXXABI_COMPILER_MSVC
30#elif defined(__IBMCPP__)
31# define _LIBCXXABI_COMPILER_IBM
32#endif24#endif
3325
34#if defined(_WIN32)26#if defined(_WIN32)
...@@ -66,17 +58,7 @@...@@ -66,17 +58,7 @@
66 #endif58 #endif
67#endif59#endif
6860
69#if defined(_LIBCXXABI_COMPILER_MSVC)
70#define _LIBCXXABI_WEAK
71#else
72#define _LIBCXXABI_WEAK __attribute__((__weak__))61#define _LIBCXXABI_WEAK __attribute__((__weak__))
73#endif
74
75#if defined(__clang__)
76#define _LIBCXXABI_COMPILER_CLANG
77#elif defined(__GNUC__)
78#define _LIBCXXABI_COMPILER_GCC
79#endif
8062
81#if __has_attribute(__no_sanitize__) && defined(_LIBCXXABI_COMPILER_CLANG)63#if __has_attribute(__no_sanitize__) && defined(_LIBCXXABI_COMPILER_CLANG)
82#define _LIBCXXABI_NO_CFI __attribute__((__no_sanitize__("cfi")))64#define _LIBCXXABI_NO_CFI __attribute__((__no_sanitize__("cfi")))
...@@ -89,11 +71,7 @@...@@ -89,11 +71,7 @@
89# define _LIBCXXABI_GUARD_ABI_ARM71# define _LIBCXXABI_GUARD_ABI_ARM
90#endif72#endif
9173
92#if defined(_LIBCXXABI_COMPILER_CLANG)74#if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L
93# if !__has_feature(cxx_exceptions)
94# define _LIBCXXABI_NO_EXCEPTIONS
95# endif
96#elif defined(_LIBCXXABI_COMPILER_GCC) && !defined(__EXCEPTIONS)
97# define _LIBCXXABI_NO_EXCEPTIONS75# define _LIBCXXABI_NO_EXCEPTIONS
98#endif76#endif
9977
...@@ -103,6 +81,47 @@...@@ -103,6 +81,47 @@
103#define _LIBCXXABI_DTOR_FUNC81#define _LIBCXXABI_DTOR_FUNC
104#endif82#endif
10583
84#if __has_include(<ptrauth.h>)
85# include <ptrauth.h>
86#endif
87
88#if __has_feature(ptrauth_calls)
89
90// ptrauth_string_discriminator("__cxa_exception::actionRecord") == 0xFC91
91# define __ptrauth_cxxabi_action_record __ptrauth(ptrauth_key_process_dependent_data, 1, 0xFC91)
92
93// ptrauth_string_discriminator("__cxa_exception::languageSpecificData") == 0xE8EE
94# define __ptrauth_cxxabi_lsd __ptrauth(ptrauth_key_process_dependent_data, 1, 0xE8EE)
95
96// ptrauth_string_discriminator("__cxa_exception::catchTemp") == 0xFA58
97# define __ptrauth_cxxabi_catch_temp_disc 0xFA58
98# define __ptrauth_cxxabi_catch_temp_key ptrauth_key_process_dependent_data
99# define __ptrauth_cxxabi_catch_temp __ptrauth(__ptrauth_cxxabi_catch_temp_key, 1, __ptrauth_cxxabi_catch_temp_disc)
100
101// ptrauth_string_discriminator("__cxa_exception::adjustedPtr") == 0x99E4
102# define __ptrauth_cxxabi_adjusted_ptr __ptrauth(ptrauth_key_process_dependent_data, 1, 0x99E4)
103
104// ptrauth_string_discriminator("__cxa_exception::unexpectedHandler") == 0x99A9
105# define __ptrauth_cxxabi_unexpected_handler __ptrauth(ptrauth_key_function_pointer, 1, 0x99A9)
106
107// ptrauth_string_discriminator("__cxa_exception::terminateHandler") == 0x0886)
108# define __ptrauth_cxxabi_terminate_handler __ptrauth(ptrauth_key_function_pointer, 1, 0x886)
109
110// ptrauth_string_discriminator("__cxa_exception::exceptionDestructor") == 0xC088
111# define __ptrauth_cxxabi_exception_destructor __ptrauth(ptrauth_key_function_pointer, 1, 0xC088)
112
113#else
114
115# define __ptrauth_cxxabi_action_record
116# define __ptrauth_cxxabi_lsd
117# define __ptrauth_cxxabi_catch_temp
118# define __ptrauth_cxxabi_adjusted_ptr
119# define __ptrauth_cxxabi_unexpected_handler
120# define __ptrauth_cxxabi_terminate_handler
121# define __ptrauth_cxxabi_exception_destructor
122
123#endif
124
106#if __cplusplus < 201103L125#if __cplusplus < 201103L
107# define _LIBCXXABI_NOEXCEPT throw()126# define _LIBCXXABI_NOEXCEPT throw()
108#else127#else
lib/libcxxabi/src/cxa_exception.cpp+4-2
...@@ -192,7 +192,9 @@ void *__cxa_allocate_exception(size_t thrown_size) throw() {...@@ -192,7 +192,9 @@ void *__cxa_allocate_exception(size_t thrown_size) throw() {
192 std::terminate();192 std::terminate();
193 __cxa_exception *exception_header =193 __cxa_exception *exception_header =
194 static_cast<__cxa_exception *>((void *)(raw_buffer + header_offset));194 static_cast<__cxa_exception *>((void *)(raw_buffer + header_offset));
195 ::memset(exception_header, 0, actual_size);195 // We warn on memset to a non-trivially castable type. We might want to
196 // change that diagnostic to not fire on a trivially obvious zero fill.
197 ::memset(static_cast<void*>(exception_header), 0, actual_size);
196 return thrown_object_from_cxa_exception(exception_header);198 return thrown_object_from_cxa_exception(exception_header);
197}199}
198200
...@@ -226,7 +228,7 @@ __cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* tinf...@@ -226,7 +228,7 @@ __cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* tinf
226}228}
227229
228// This function shall allocate a __cxa_dependent_exception and230// This function shall allocate a __cxa_dependent_exception and
229// return a pointer to it. (Really to the object, not past its' end).231// return a pointer to it. (Really to the object, not past its end).
230// Otherwise, it will work like __cxa_allocate_exception.232// Otherwise, it will work like __cxa_allocate_exception.
231void * __cxa_allocate_dependent_exception () {233void * __cxa_allocate_dependent_exception () {
232 size_t actual_size = sizeof(__cxa_dependent_exception);234 size_t actual_size = sizeof(__cxa_dependent_exception);
lib/libcxxabi/src/cxa_exception.h+16-14
...@@ -47,10 +47,10 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {...@@ -47,10 +47,10 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
47 // In Wasm, a destructor returns its argument47 // In Wasm, a destructor returns its argument
48 void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);48 void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
49#else49#else
50 void (_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);50 void (_LIBCXXABI_DTOR_FUNC *__ptrauth_cxxabi_exception_destructor exceptionDestructor)(void *);
51#endif51#endif
52 std::unexpected_handler unexpectedHandler;52 std::unexpected_handler __ptrauth_cxxabi_unexpected_handler unexpectedHandler;
53 std::terminate_handler terminateHandler;53 std::terminate_handler __ptrauth_cxxabi_terminate_handler terminateHandler;
5454
55 __cxa_exception *nextException;55 __cxa_exception *nextException;
5656
...@@ -61,10 +61,10 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {...@@ -61,10 +61,10 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
61 int propagationCount;61 int propagationCount;
62#else62#else
63 int handlerSwitchValue;63 int handlerSwitchValue;
64 const unsigned char *actionRecord;64 const unsigned char *__ptrauth_cxxabi_action_record actionRecord;
65 const unsigned char *languageSpecificData;65 const unsigned char *__ptrauth_cxxabi_lsd languageSpecificData;
66 void *catchTemp;66 void *__ptrauth_cxxabi_catch_temp catchTemp;
67 void *adjustedPtr;67 void *__ptrauth_cxxabi_adjusted_ptr adjustedPtr;
68#endif68#endif
6969
70#if !defined(__LP64__) && !defined(_WIN64) && !defined(_LIBCXXABI_ARM_EHABI)70#if !defined(__LP64__) && !defined(_WIN64) && !defined(_LIBCXXABI_ARM_EHABI)
...@@ -79,6 +79,8 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {...@@ -79,6 +79,8 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
79// http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html79// http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html
80// The layout of this structure MUST match the layout of __cxa_exception, with80// The layout of this structure MUST match the layout of __cxa_exception, with
81// primaryException instead of referenceCount.81// primaryException instead of referenceCount.
82// The pointer authentication schemas specified here must also match those of
83// the corresponding members in __cxa_exception.
82struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {84struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
83#if defined(__LP64__) || defined(_WIN64) || defined(_LIBCXXABI_ARM_EHABI)85#if defined(__LP64__) || defined(_WIN64) || defined(_LIBCXXABI_ARM_EHABI)
84 void* reserve; // padding.86 void* reserve; // padding.
...@@ -86,9 +88,9 @@ struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {...@@ -86,9 +88,9 @@ struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
86#endif88#endif
8789
88 std::type_info *exceptionType;90 std::type_info *exceptionType;
89 void (_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);91 void (_LIBCXXABI_DTOR_FUNC *__ptrauth_cxxabi_exception_destructor exceptionDestructor)(void *);
90 std::unexpected_handler unexpectedHandler;92 std::unexpected_handler __ptrauth_cxxabi_unexpected_handler unexpectedHandler;
91 std::terminate_handler terminateHandler;93 std::terminate_handler __ptrauth_cxxabi_terminate_handler terminateHandler;
9294
93 __cxa_exception *nextException;95 __cxa_exception *nextException;
9496
...@@ -99,10 +101,10 @@ struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {...@@ -99,10 +101,10 @@ struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
99 int propagationCount;101 int propagationCount;
100#else102#else
101 int handlerSwitchValue;103 int handlerSwitchValue;
102 const unsigned char *actionRecord;104 const unsigned char *__ptrauth_cxxabi_action_record actionRecord;
103 const unsigned char *languageSpecificData;105 const unsigned char *__ptrauth_cxxabi_lsd languageSpecificData;
104 void * catchTemp;106 void *__ptrauth_cxxabi_catch_temp catchTemp;
105 void *adjustedPtr;107 void *__ptrauth_cxxabi_adjusted_ptr adjustedPtr;
106#endif108#endif
107109
108#if !defined(__LP64__) && !defined(_WIN64) && !defined(_LIBCXXABI_ARM_EHABI)110#if !defined(__LP64__) && !defined(_WIN64) && !defined(_LIBCXXABI_ARM_EHABI)
lib/libcxxabi/src/cxa_personality.cpp+125-12
...@@ -20,7 +20,52 @@...@@ -20,7 +20,52 @@
20#include "cxa_exception.h"20#include "cxa_exception.h"
21#include "cxa_handlers.h"21#include "cxa_handlers.h"
22#include "private_typeinfo.h"22#include "private_typeinfo.h"
23#include "unwind.h"23
24#if __has_feature(ptrauth_calls)
25
26// CXXABI depends on defintions in libunwind as pointer auth couples the
27// definitions
28# include "libunwind.h"
29
30// The actual value of the discriminators listed below is not important.
31// The derivation of the constants is only being included for the purpose
32// of maintaining a record of how they were originally produced.
33
34// ptrauth_string_discriminator("scan_results::languageSpecificData") == 0xE50D)
35# define __ptrauth_scan_results_lsd __ptrauth(ptrauth_key_process_dependent_code, 1, 0xE50D)
36
37// ptrauth_string_discriminator("scan_results::actionRecord") == 0x9823
38# define __ptrauth_scan_results_action_record __ptrauth(ptrauth_key_process_dependent_code, 1, 0x9823)
39
40// scan result is broken up as we have a manual re-sign that requires each component
41# define __ptrauth_scan_results_landingpad_key ptrauth_key_process_dependent_code
42// ptrauth_string_discriminator("scan_results::landingPad") == 0xD27C
43# define __ptrauth_scan_results_landingpad_disc 0xD27C
44# define __ptrauth_scan_results_landingpad \
45 __ptrauth(__ptrauth_scan_results_landingpad_key, 1, __ptrauth_scan_results_landingpad_disc)
46
47// `__ptrauth_restricted_intptr` is a feature of apple clang that predates
48// support for direct application of `__ptrauth` to integer types. This
49// guard is necessary to support compilation with those compiler.
50# if __has_extension(ptrauth_restricted_intptr_qualifier)
51# define __ptrauth_scan_results_landingpad_intptr \
52 __ptrauth_restricted_intptr(__ptrauth_scan_results_landingpad_key, 1, __ptrauth_scan_results_landingpad_disc)
53# else
54# define __ptrauth_scan_results_landingpad_intptr \
55 __ptrauth(__ptrauth_scan_results_landingpad_key, 1, __ptrauth_scan_results_landingpad_disc)
56# endif
57
58#else
59# define __ptrauth_scan_results_lsd
60# define __ptrauth_scan_results_action_record
61# define __ptrauth_scan_results_landingpad
62# define __ptrauth_scan_results_landingpad_intptr
63#endif
64
65// The functions defined in this file are magic functions called only by the compiler.
66#ifdef __clang__
67# pragma clang diagnostic ignored "-Wmissing-prototypes"
68#endif
2469
25// TODO: This is a temporary workaround for libc++abi to recognize that it's being70// TODO: This is a temporary workaround for libc++abi to recognize that it's being
26// built against LLVM's libunwind. LLVM's libunwind started reporting _LIBUNWIND_VERSION71// built against LLVM's libunwind. LLVM's libunwind started reporting _LIBUNWIND_VERSION
...@@ -527,12 +572,17 @@ get_thrown_object_ptr(_Unwind_Exception* unwind_exception)...@@ -527,12 +572,17 @@ get_thrown_object_ptr(_Unwind_Exception* unwind_exception)
527namespace572namespace
528{573{
529574
575typedef const uint8_t *__ptrauth_scan_results_lsd lsd_ptr_t;
576typedef const uint8_t *__ptrauth_scan_results_action_record action_ptr_t;
577typedef uintptr_t __ptrauth_scan_results_landingpad_intptr landing_pad_t;
578typedef void *__ptrauth_scan_results_landingpad landing_pad_ptr_t;
579
530struct scan_results580struct scan_results
531{581{
532 int64_t ttypeIndex; // > 0 catch handler, < 0 exception spec handler, == 0 a cleanup582 int64_t ttypeIndex; // > 0 catch handler, < 0 exception spec handler, == 0 a cleanup
533 const uint8_t* actionRecord; // Currently unused. Retained to ease future maintenance.583 action_ptr_t actionRecord; // Currently unused. Retained to ease future maintenance.
534 const uint8_t* languageSpecificData; // Needed only for __cxa_call_unexpected584 lsd_ptr_t languageSpecificData; // Needed only for __cxa_call_unexpected
535 uintptr_t landingPad; // null -> nothing found, else something found585 landing_pad_t landingPad; // null -> nothing found, else something found
536 void* adjustedPtr; // Used in cxa_exception.cpp586 void* adjustedPtr; // Used in cxa_exception.cpp
537 _Unwind_Reason_Code reason; // One of _URC_FATAL_PHASE1_ERROR,587 _Unwind_Reason_Code reason; // One of _URC_FATAL_PHASE1_ERROR,
538 // _URC_FATAL_PHASE2_ERROR,588 // _URC_FATAL_PHASE2_ERROR,
...@@ -557,7 +607,23 @@ set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context,...@@ -557,7 +607,23 @@ set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context,
557 reinterpret_cast<uintptr_t>(unwind_exception));607 reinterpret_cast<uintptr_t>(unwind_exception));
558 _Unwind_SetGR(context, __builtin_eh_return_data_regno(1),608 _Unwind_SetGR(context, __builtin_eh_return_data_regno(1),
559 static_cast<uintptr_t>(results.ttypeIndex));609 static_cast<uintptr_t>(results.ttypeIndex));
610#if __has_feature(ptrauth_calls)
611 auto stackPointer = _Unwind_GetGR(context, UNW_REG_SP);
612 // We manually re-sign the IP as the __ptrauth qualifiers cannot
613 // express the required relationship with the destination address
614 const auto existingDiscriminator =
615 ptrauth_blend_discriminator(&results.landingPad,
616 __ptrauth_scan_results_landingpad_disc);
617 unw_word_t newIP /* opaque __ptrauth(ptrauth_key_return_address, stackPointer, 0) */ =
618 (unw_word_t)ptrauth_auth_and_resign(*(void* const*)&results.landingPad,
619 __ptrauth_scan_results_landingpad_key,
620 existingDiscriminator,
621 ptrauth_key_return_address,
622 stackPointer);
623 _Unwind_SetIP(context, newIP);
624#else
560 _Unwind_SetIP(context, results.landingPad);625 _Unwind_SetIP(context, results.landingPad);
626#endif
561}627}
562628
563/*629/*
...@@ -691,12 +757,12 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,...@@ -691,12 +757,12 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
691 // The call sites are ordered in increasing value of start757 // The call sites are ordered in increasing value of start
692 uintptr_t start = readEncodedPointer(&callSitePtr, callSiteEncoding);758 uintptr_t start = readEncodedPointer(&callSitePtr, callSiteEncoding);
693 uintptr_t length = readEncodedPointer(&callSitePtr, callSiteEncoding);759 uintptr_t length = readEncodedPointer(&callSitePtr, callSiteEncoding);
694 uintptr_t landingPad = readEncodedPointer(&callSitePtr, callSiteEncoding);760 landing_pad_t landingPad = readEncodedPointer(&callSitePtr, callSiteEncoding);
695 uintptr_t actionEntry = readULEB128(&callSitePtr);761 uintptr_t actionEntry = readULEB128(&callSitePtr);
696 if ((start <= ipOffset) && (ipOffset < (start + length)))762 if ((start <= ipOffset) && (ipOffset < (start + length)))
697#else // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__763#else // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
698 // ip is 1-based index into this table764 // ip is 1-based index into this table
699 uintptr_t landingPad = readULEB128(&callSitePtr);765 landing_pad_t landingPad = readULEB128(&callSitePtr);
700 uintptr_t actionEntry = readULEB128(&callSitePtr);766 uintptr_t actionEntry = readULEB128(&callSitePtr);
701 if (--ip == 0)767 if (--ip == 0)
702#endif // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__768#endif // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
...@@ -903,6 +969,57 @@ _UA_CLEANUP_PHASE...@@ -903,6 +969,57 @@ _UA_CLEANUP_PHASE
903*/969*/
904970
905#if !defined(_LIBCXXABI_ARM_EHABI)971#if !defined(_LIBCXXABI_ARM_EHABI)
972
973// We use these helper functions to work around the behavior of casting between
974// integers (even those that are authenticated) and authenticated pointers.
975// Because the schemas being used are address discriminated we cannot use a
976// trivial value union to coerce the types so instead we perform the re-signing
977// manually.
978using __cxa_catch_temp_type = decltype(__cxa_exception::catchTemp);
979static inline void set_landing_pad(scan_results& results,
980 const __cxa_catch_temp_type& source) {
981#if __has_feature(ptrauth_calls)
982 const uintptr_t sourceDiscriminator =
983 ptrauth_blend_discriminator(&source, __ptrauth_cxxabi_catch_temp_disc);
984 const uintptr_t targetDiscriminator =
985 ptrauth_blend_discriminator(&results.landingPad,
986 __ptrauth_scan_results_landingpad_disc);
987 uintptr_t reauthenticatedLandingPad =
988 (uintptr_t)ptrauth_auth_and_resign(*reinterpret_cast<void* const*>(&source),
989 __ptrauth_cxxabi_catch_temp_key,
990 sourceDiscriminator,
991 __ptrauth_scan_results_landingpad_key,
992 targetDiscriminator);
993 memmove(reinterpret_cast<void *>(&results.landingPad),
994 reinterpret_cast<void *>(&reauthenticatedLandingPad),
995 sizeof(reauthenticatedLandingPad));
996#else
997 results.landingPad = reinterpret_cast<landing_pad_t>(source);
998#endif
999}
1000
1001static inline void get_landing_pad(__cxa_catch_temp_type &dest,
1002 const scan_results &results) {
1003#if __has_feature(ptrauth_calls)
1004 const uintptr_t sourceDiscriminator =
1005 ptrauth_blend_discriminator(&results.landingPad,
1006 __ptrauth_scan_results_landingpad_disc);
1007 const uintptr_t targetDiscriminator =
1008 ptrauth_blend_discriminator(&dest, __ptrauth_cxxabi_catch_temp_disc);
1009 uintptr_t reauthenticatedPointer =
1010 (uintptr_t)ptrauth_auth_and_resign(*reinterpret_cast<void* const*>(&results.landingPad),
1011 __ptrauth_scan_results_landingpad_key,
1012 sourceDiscriminator,
1013 __ptrauth_cxxabi_catch_temp_key,
1014 targetDiscriminator);
1015 memmove(reinterpret_cast<void *>(&dest),
1016 reinterpret_cast<void *>(&reauthenticatedPointer),
1017 sizeof(reauthenticatedPointer));
1018#else
1019 dest = reinterpret_cast<__cxa_catch_temp_type>(results.landingPad);
1020#endif
1021}
1022
906#ifdef __WASM_EXCEPTIONS__1023#ifdef __WASM_EXCEPTIONS__
907_Unwind_Reason_Code __gxx_personality_wasm01024_Unwind_Reason_Code __gxx_personality_wasm0
908#elif defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)1025#elif defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
...@@ -935,8 +1052,7 @@ __gxx_personality_v0...@@ -935,8 +1052,7 @@ __gxx_personality_v0
935 results.ttypeIndex = exception_header->handlerSwitchValue;1052 results.ttypeIndex = exception_header->handlerSwitchValue;
936 results.actionRecord = exception_header->actionRecord;1053 results.actionRecord = exception_header->actionRecord;
937 results.languageSpecificData = exception_header->languageSpecificData;1054 results.languageSpecificData = exception_header->languageSpecificData;
938 results.landingPad =1055 set_landing_pad(results, exception_header->catchTemp);
939 reinterpret_cast<uintptr_t>(exception_header->catchTemp);
940 results.adjustedPtr = exception_header->adjustedPtr;1056 results.adjustedPtr = exception_header->adjustedPtr;
9411057
942 // Jump to the handler.1058 // Jump to the handler.
...@@ -970,7 +1086,7 @@ __gxx_personality_v0...@@ -970,7 +1086,7 @@ __gxx_personality_v0
970 exc->handlerSwitchValue = static_cast<int>(results.ttypeIndex);1086 exc->handlerSwitchValue = static_cast<int>(results.ttypeIndex);
971 exc->actionRecord = results.actionRecord;1087 exc->actionRecord = results.actionRecord;
972 exc->languageSpecificData = results.languageSpecificData;1088 exc->languageSpecificData = results.languageSpecificData;
973 exc->catchTemp = reinterpret_cast<void*>(results.landingPad);1089 get_landing_pad(exc->catchTemp, results);
974 exc->adjustedPtr = results.adjustedPtr;1090 exc->adjustedPtr = results.adjustedPtr;
975#ifdef __WASM_EXCEPTIONS__1091#ifdef __WASM_EXCEPTIONS__
976 // Wasm only uses a single phase (_UA_SEARCH_PHASE), so save the1092 // Wasm only uses a single phase (_UA_SEARCH_PHASE), so save the
...@@ -1009,9 +1125,6 @@ __gxx_personality_seh0(PEXCEPTION_RECORD ms_exc, void *this_frame,...@@ -1009,9 +1125,6 @@ __gxx_personality_seh0(PEXCEPTION_RECORD ms_exc, void *this_frame,
10091125
1010#else1126#else
10111127
1012extern "C" _Unwind_Reason_Code __gnu_unwind_frame(_Unwind_Exception*,
1013 _Unwind_Context*);
1014
1015// Helper function to unwind one frame.1128// Helper function to unwind one frame.
1016// ARM EHABI 7.3 and 7.4: If the personality function returns _URC_CONTINUE_UNWIND, the1129// ARM EHABI 7.3 and 7.4: If the personality function returns _URC_CONTINUE_UNWIND, the
1017// personality routine should update the virtual register set (VRS) according to the1130// personality routine should update the virtual register set (VRS) according to the
lib/libcxxabi/src/cxa_thread_atexit.cpp+2-1
...@@ -106,6 +106,7 @@ namespace {...@@ -106,6 +106,7 @@ namespace {
106106
107#endif // HAVE___CXA_THREAD_ATEXIT_IMPL107#endif // HAVE___CXA_THREAD_ATEXIT_IMPL
108108
109#if defined(__linux__) || defined(__Fuchsia__)
109extern "C" {110extern "C" {
110111
111 _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(Dtor dtor, void* obj, void* dso_symbol) throw() {112 _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(Dtor dtor, void* obj, void* dso_symbol) throw() {
...@@ -140,6 +141,6 @@ extern "C" {...@@ -140,6 +141,6 @@ extern "C" {
140 }141 }
141#endif // HAVE___CXA_THREAD_ATEXIT_IMPL142#endif // HAVE___CXA_THREAD_ATEXIT_IMPL
142 }143 }
143
144} // extern "C"144} // extern "C"
145#endif // defined(__linux__) || defined(__Fuchsia__)
145} // namespace __cxxabiv1146} // namespace __cxxabiv1
lib/libcxxabi/src/demangle/DemangleConfig.h+4
...@@ -115,4 +115,8 @@...@@ -115,4 +115,8 @@
115#define DEMANGLE_NAMESPACE_BEGIN namespace { namespace itanium_demangle {115#define DEMANGLE_NAMESPACE_BEGIN namespace { namespace itanium_demangle {
116#define DEMANGLE_NAMESPACE_END } }116#define DEMANGLE_NAMESPACE_END } }
117117
118// The DEMANGLE_ABI macro resolves to nothing when building libc++abi. Only
119// the llvm copy defines DEMANGLE_ABI as a visibility attribute.
120#define DEMANGLE_ABI
121
118#endif // LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H122#endif // LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H
lib/libcxxabi/src/demangle/ItaniumDemangle.h+9-6
...@@ -1366,7 +1366,7 @@ public:...@@ -1366,7 +1366,7 @@ public:
1366 template <typename Fn> void match(Fn F) const { F(Name, Params, Requires); }1366 template <typename Fn> void match(Fn F) const { F(Name, Params, Requires); }
13671367
1368 void printLeft(OutputBuffer &OB) const override {1368 void printLeft(OutputBuffer &OB) const override {
1369 ScopedOverride<unsigned> LT(OB.GtIsGt, 0);1369 ScopedOverride<bool> LT(OB.TemplateTracker.InsideTemplate, true);
1370 OB += "template<";1370 OB += "template<";
1371 Params.printWithComma(OB);1371 Params.printWithComma(OB);
1372 OB += "> typename ";1372 OB += "> typename ";
...@@ -1550,7 +1550,7 @@ public:...@@ -1550,7 +1550,7 @@ public:
1550 NodeArray getParams() { return Params; }1550 NodeArray getParams() { return Params; }
15511551
1552 void printLeft(OutputBuffer &OB) const override {1552 void printLeft(OutputBuffer &OB) const override {
1553 ScopedOverride<unsigned> LT(OB.GtIsGt, 0);1553 ScopedOverride<bool> LT(OB.TemplateTracker.InsideTemplate, true);
1554 OB += "<";1554 OB += "<";
1555 Params.printWithComma(OB);1555 Params.printWithComma(OB);
1556 OB += ">";1556 OB += ">";
...@@ -1824,7 +1824,7 @@ public:...@@ -1824,7 +1824,7 @@ public:
18241824
1825 void printDeclarator(OutputBuffer &OB) const {1825 void printDeclarator(OutputBuffer &OB) const {
1826 if (!TemplateParams.empty()) {1826 if (!TemplateParams.empty()) {
1827 ScopedOverride<unsigned> LT(OB.GtIsGt, 0);1827 ScopedOverride<bool> LT(OB.TemplateTracker.InsideTemplate, true);
1828 OB += "<";1828 OB += "<";
1829 TemplateParams.printWithComma(OB);1829 TemplateParams.printWithComma(OB);
1830 OB += ">";1830 OB += ">";
...@@ -1885,7 +1885,9 @@ public:...@@ -1885,7 +1885,9 @@ public:
1885 }1885 }
18861886
1887 void printLeft(OutputBuffer &OB) const override {1887 void printLeft(OutputBuffer &OB) const override {
1888 bool ParenAll = OB.isGtInsideTemplateArgs() &&1888 // If we're printing a '<' inside of a template argument, and we haven't
1889 // yet parenthesized the expression, do so now.
1890 bool ParenAll = !OB.isInParensInTemplateArgs() &&
1889 (InfixOperator == ">" || InfixOperator == ">>");1891 (InfixOperator == ">" || InfixOperator == ">>");
1890 if (ParenAll)1892 if (ParenAll)
1891 OB.printOpen();1893 OB.printOpen();
...@@ -2061,7 +2063,7 @@ public:...@@ -2061,7 +2063,7 @@ public:
2061 void printLeft(OutputBuffer &OB) const override {2063 void printLeft(OutputBuffer &OB) const override {
2062 OB += CastKind;2064 OB += CastKind;
2063 {2065 {
2064 ScopedOverride<unsigned> LT(OB.GtIsGt, 0);2066 ScopedOverride<bool> LT(OB.TemplateTracker.InsideTemplate, true);
2065 OB += "<";2067 OB += "<";
2066 OB.printLeft(*To);2068 OB.printLeft(*To);
2067 OB += ">";2069 OB += ">";
...@@ -3049,7 +3051,8 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {...@@ -3049,7 +3051,8 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
3049 Node *parse(bool ParseParams = true);3051 Node *parse(bool ParseParams = true);
3050};3052};
30513053
3052const char* parse_discriminator(const char* first, const char* last);3054DEMANGLE_ABI const char *parse_discriminator(const char *first,
3055 const char *last);
30533056
3054// <name> ::= <nested-name> // N3057// <name> ::= <nested-name> // N
3055// ::= <local-name> # See Scope Encoding below // Z3058// ::= <local-name> # See Scope Encoding below // Z
lib/libcxxabi/src/demangle/Utility.h+21-7
...@@ -81,7 +81,7 @@ public:...@@ -81,7 +81,7 @@ public:
81 OutputBuffer(const OutputBuffer &) = delete;81 OutputBuffer(const OutputBuffer &) = delete;
82 OutputBuffer &operator=(const OutputBuffer &) = delete;82 OutputBuffer &operator=(const OutputBuffer &) = delete;
8383
84 virtual ~OutputBuffer() {}84 virtual ~OutputBuffer() = default;
8585
86 operator std::string_view() const {86 operator std::string_view() const {
87 return std::string_view(Buffer, CurrentPosition);87 return std::string_view(Buffer, CurrentPosition);
...@@ -104,18 +104,32 @@ public:...@@ -104,18 +104,32 @@ public:
104 unsigned CurrentPackIndex = std::numeric_limits<unsigned>::max();104 unsigned CurrentPackIndex = std::numeric_limits<unsigned>::max();
105 unsigned CurrentPackMax = std::numeric_limits<unsigned>::max();105 unsigned CurrentPackMax = std::numeric_limits<unsigned>::max();
106106
107 /// When zero, we're printing template args and '>' needs to be parenthesized.107 struct {
108 /// Use a counter so we can simply increment inside parentheses.108 /// The depth of '(' and ')' inside the currently printed template
109 unsigned GtIsGt = 1;109 /// arguments.
110 unsigned ParenDepth = 0;
110111
111 bool isGtInsideTemplateArgs() const { return GtIsGt == 0; }112 /// True if we're currently printing a template argument.
113 bool InsideTemplate = false;
114 } TemplateTracker;
115
116 /// Returns true if we're currently between a '(' and ')' when printing
117 /// template args.
118 bool isInParensInTemplateArgs() const {
119 return TemplateTracker.ParenDepth > 0;
120 }
121
122 /// Returns true if we're printing template args.
123 bool isInsideTemplateArgs() const { return TemplateTracker.InsideTemplate; }
112124
113 void printOpen(char Open = '(') {125 void printOpen(char Open = '(') {
114 GtIsGt++;126 if (isInsideTemplateArgs())
127 TemplateTracker.ParenDepth++;
115 *this += Open;128 *this += Open;
116 }129 }
117 void printClose(char Close = ')') {130 void printClose(char Close = ')') {
118 GtIsGt--;131 if (isInsideTemplateArgs())
132 TemplateTracker.ParenDepth--;
119 *this += Close;133 *this += Close;
120 }134 }
121135
lib/libcxxabi/src/fallback_malloc.cpp+1-1
...@@ -16,7 +16,7 @@...@@ -16,7 +16,7 @@
16#endif16#endif
17#endif17#endif
1818
19#include <__memory/aligned_alloc.h>19#include "include/aligned_alloc.h" // from libc++
20#include <__assert>20#include <__assert>
21#include <stdlib.h> // for malloc, calloc, free21#include <stdlib.h> // for malloc, calloc, free
22#include <string.h> // for memset22#include <string.h> // for memset
lib/libcxxabi/src/private_typeinfo.cpp+6
...@@ -831,6 +831,10 @@ bool __pointer_to_member_type_info::can_catch_nested(...@@ -831,6 +831,10 @@ bool __pointer_to_member_type_info::can_catch_nested(
831#pragma clang diagnostic ignored "-Wmissing-field-initializers"831#pragma clang diagnostic ignored "-Wmissing-field-initializers"
832#endif832#endif
833833
834#pragma GCC diagnostic push
835// __dynamic_cast is called by the compiler, so there is no prototype
836#pragma GCC diagnostic ignored "-Wmissing-prototypes"
837
834// __dynamic_cast838// __dynamic_cast
835839
836// static_ptr: pointer to an object of type static_type; nonnull, and since the840// static_ptr: pointer to an object of type static_type; nonnull, and since the
...@@ -953,6 +957,8 @@ __dynamic_cast(const void *static_ptr, const __class_type_info *static_type,...@@ -953,6 +957,8 @@ __dynamic_cast(const void *static_ptr, const __class_type_info *static_type,
953 return const_cast<void*>(dst_ptr);957 return const_cast<void*>(dst_ptr);
954}958}
955959
960#pragma GCC diagnostic pop
961
956#ifdef __clang__962#ifdef __clang__
957#pragma clang diagnostic pop963#pragma clang diagnostic pop
958#endif964#endif
lib/libcxxabi/src/stdlib_new_delete.cpp+5-5
...@@ -8,8 +8,8 @@...@@ -8,8 +8,8 @@
88
9#include "__cxxabi_config.h"9#include "__cxxabi_config.h"
10#include "abort_message.h"10#include "abort_message.h"
11#include "include/aligned_alloc.h" // from libc++
11#include "include/overridable_function.h" // from libc++12#include "include/overridable_function.h" // from libc++
12#include <__memory/aligned_alloc.h>
13#include <cstddef>13#include <cstddef>
14#include <cstdlib>14#include <cstdlib>
15#include <new>15#include <new>
...@@ -63,7 +63,7 @@ static void* operator_new_impl(std::size_t size) {...@@ -63,7 +63,7 @@ static void* operator_new_impl(std::size_t size) {
63 return p;63 return p;
64}64}
6565
66_LIBCPP_OVERRIDABLE_FUNCTION(void*, operator new, (std::size_t size)) _THROW_BAD_ALLOC {66OVERRIDABLE_FUNCTION void* operator new(std::size_t size) _THROW_BAD_ALLOC {
67 void* p = operator_new_impl(size);67 void* p = operator_new_impl(size);
68 if (p == nullptr)68 if (p == nullptr)
69 __throw_bad_alloc_shim();69 __throw_bad_alloc_shim();
...@@ -94,7 +94,7 @@ _LIBCPP_WEAK void* operator new(size_t size, const std::nothrow_t&) noexcept {...@@ -94,7 +94,7 @@ _LIBCPP_WEAK void* operator new(size_t size, const std::nothrow_t&) noexcept {
94#endif94#endif
95}95}
9696
97_LIBCPP_OVERRIDABLE_FUNCTION(void*, operator new[], (size_t size)) _THROW_BAD_ALLOC { return ::operator new(size); }97OVERRIDABLE_FUNCTION void* operator new[](size_t size) _THROW_BAD_ALLOC { return ::operator new(size); }
9898
99_LIBCPP_WEAK void* operator new[](size_t size, const std::nothrow_t&) noexcept {99_LIBCPP_WEAK void* operator new[](size_t size, const std::nothrow_t&) noexcept {
100#if !_LIBCPP_HAS_EXCEPTIONS100#if !_LIBCPP_HAS_EXCEPTIONS
...@@ -154,7 +154,7 @@ static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignm...@@ -154,7 +154,7 @@ static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignm
154 return p;154 return p;
155}155}
156156
157_LIBCPP_OVERRIDABLE_FUNCTION(void*, operator new, (std::size_t size, std::align_val_t alignment)) _THROW_BAD_ALLOC {157OVERRIDABLE_FUNCTION void* operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
158 void* p = operator_new_aligned_impl(size, alignment);158 void* p = operator_new_aligned_impl(size, alignment);
159 if (p == nullptr)159 if (p == nullptr)
160 __throw_bad_alloc_shim();160 __throw_bad_alloc_shim();
...@@ -185,7 +185,7 @@ _LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const s...@@ -185,7 +185,7 @@ _LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const s
185# endif185# endif
186}186}
187187
188_LIBCPP_OVERRIDABLE_FUNCTION(void*, operator new[], (size_t size, std::align_val_t alignment)) _THROW_BAD_ALLOC {188OVERRIDABLE_FUNCTION void* operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
189 return ::operator new(size, alignment);189 return ::operator new(size, alignment);
190}190}
191191