Skip to content

Update libcxxabi to LLVM 19.1.3 #22935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions system/lib/libcxxabi/include/cxxabi.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup();
#endif
extern _LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type();

// GNU extension
// Calls `terminate` with the current exception being caught. This function is used by GCC when a `noexcept` function
// throws an exception inside a try/catch block and doesn't catch it.
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_call_terminate(void*) throw();

// 2.5.4 Rethrowing Exceptions
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_rethrow();

Expand Down
16 changes: 8 additions & 8 deletions system/lib/libcxxabi/src/aix_state_tab_eh.inc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ static bool state_tab_dbg() {

namespace __state_table_eh {

using destruct_f = void (*)(void*);

// Definition of flags for the state table entry field 'action flag'.
enum FSMEntryCount : intptr_t { beginCatch = -1, endCatch = -2, deleteObject = -3, cleanupLabel = -4, terminate = -5 };

Expand Down Expand Up @@ -145,8 +143,10 @@ struct FSMEntry {
intptr_t nextStatePtr;
};
union {
// Address of the destructor function.
void (*destructor)(void*, size_t);
// Address of the destructor function with 1 argument.
void (*destructor)(void*);
// Address of the destructor function with 2 arguments.
void (*xlCDestructor)(void*, size_t);
// The address of the catch block or cleanup code.
void* landingPad;
};
Expand Down Expand Up @@ -191,12 +191,12 @@ static void invoke_destructor(FSMEntry* fsmEntry, void* addr) {
try {
if (fsmEntry->elementCount == 1) {
_LIBCXXABI_TRACE_STATETAB0("calling scalar destructor\n");
(*fsmEntry->destructor)(addr, dtorArgument);
(*fsmEntry->xlCDestructor)(addr, dtorArgument);
_LIBCXXABI_TRACE_STATETAB0("returned from scalar destructor\n");
} else {
_LIBCXXABI_TRACE_STATETAB0("calling vector destructor\n");
__cxa_vec_cleanup(addr, reinterpret_cast<size_t>(fsmEntry->elementCount), fsmEntry->elemSize,
reinterpret_cast<destruct_f>(fsmEntry->destructor));
fsmEntry->destructor);
_LIBCXXABI_TRACE_STATETAB0("returned from vector destructor\n");
}
} catch (...) {
Expand All @@ -213,7 +213,7 @@ static void invoke_delete(FSMEntry* fsmEntry, void* addr) {
try {
_LIBCXXABI_TRACE_STATETAB0("..calling delete()\n");
// 'destructor' holds a function pointer to delete().
(*fsmEntry->destructor)(objectAddress, fsmEntry->elemSize);
(*fsmEntry->xlCDestructor)(objectAddress, fsmEntry->elemSize);
_LIBCXXABI_TRACE_STATETAB0("..returned from delete()\n");
} catch (...) {
_LIBCXXABI_TRACE_STATETAB0("Uncaught exception in delete(), terminating\n");
Expand Down Expand Up @@ -681,7 +681,7 @@ static uintptr_t* skip_non_cxx_eh_aware_frames(uint32_t* Pc, uintptr_t* Sp) {
// xlclang++ compiled code. If __xlc_exception_handle() is called by
// non-C++ EH aware functions, their frames are skipped until a C++ EH aware
// frame is found.
// Note: make sure __xlc_excpetion_handle() is a non-leaf function. Currently
// Note: make sure __xlc_exception_handle() is a non-leaf function. Currently
// it calls skip_non_cxx_eh_aware_frames(), which in turn calls abort().
_LIBCXXABI_FUNC_VIS uintptr_t __xlc_exception_handle() {
// Get the SP of this function, i.e., __xlc_exception_handle().
Expand Down
5 changes: 5 additions & 0 deletions system/lib/libcxxabi/src/cxa_exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,11 @@ void __cxa_end_catch() {
}
}

void __cxa_call_terminate(void* unwind_arg) throw() {
__cxa_begin_catch(unwind_arg);
std::terminate();
}

// Note: exception_header may be masquerading as a __cxa_dependent_exception
// and that's ok. exceptionType is there too.
// However watch out for foreign exceptions. Return null for them.
Expand Down
4 changes: 2 additions & 2 deletions system/lib/libcxxabi/src/cxa_exception_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "cxa_exception.h"

#include <__threading_support>
#include <__thread/support.h>

#if defined(_LIBCXXABI_HAS_NO_THREADS)

Expand All @@ -24,7 +24,7 @@ extern "C" {
} // extern "C"
} // namespace __cxxabiv1

#elif defined(HAS_THREAD_LOCAL)
#elif __has_feature(cxx_thread_local)

namespace __cxxabiv1 {
namespace {
Expand Down
18 changes: 16 additions & 2 deletions system/lib/libcxxabi/src/cxa_guard_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
#include "__cxxabi_config.h"
#include "include/atomic_support.h" // from libc++
#if defined(__has_include)
# if __has_include(<sys/futex.h>)
# include <sys/futex.h>
# endif
# if __has_include(<sys/syscall.h>)
# include <sys/syscall.h>
# endif
Expand All @@ -55,7 +58,7 @@
# endif
#endif

#include <__threading_support>
#include <__thread/support.h>
#include <cstdint>
#include <cstring>
#include <limits.h>
Expand Down Expand Up @@ -411,7 +414,18 @@ struct InitByteGlobalMutex {
// Futex Implementation
//===----------------------------------------------------------------------===//

#if defined(SYS_futex)
#if defined(__OpenBSD__)
void PlatformFutexWait(int* addr, int expect) {
constexpr int WAIT = 0;
futex(reinterpret_cast<volatile uint32_t*>(addr), WAIT, expect, NULL, NULL);
__tsan_acquire(addr);
}
void PlatformFutexWake(int* addr) {
constexpr int WAKE = 1;
__tsan_release(addr);
futex(reinterpret_cast<volatile uint32_t*>(addr), WAKE, INT_MAX, NULL, NULL);
}
#elif defined(SYS_futex)
void PlatformFutexWait(int* addr, int expect) {
constexpr int WAIT = 0;
syscall(SYS_futex, addr, WAIT, expect, 0);
Expand Down
4 changes: 1 addition & 3 deletions system/lib/libcxxabi/src/cxa_personality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,7 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
if (actionEntry == 0)
{
// Found a cleanup
results.reason = actions & _UA_SEARCH_PHASE
? _URC_CONTINUE_UNWIND
: _URC_HANDLER_FOUND;
results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
return;
}
// Convert 1-based byte offset into
Expand Down
2 changes: 1 addition & 1 deletion system/lib/libcxxabi/src/cxa_thread_atexit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "abort_message.h"
#include "cxxabi.h"
#include <__threading_support>
#include <__thread/support.h>
#ifndef _LIBCXXABI_HAS_NO_THREADS
#if defined(__ELF__) && defined(_LIBCXXABI_LINK_PTHREAD_LIB)
#pragma comment(lib, "pthread")
Expand Down
12 changes: 6 additions & 6 deletions system/lib/libcxxabi/src/demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@
DEMANGLE_NAMESPACE_BEGIN

template <class T, size_t N> class PODSmallVector {
static_assert(std::is_pod<T>::value,
"T is required to be a plain old data type");

static_assert(std::is_trivial<T>::value,
"T is required to be a trivial type");
T *First = nullptr;
T *Last = nullptr;
T *Cap = nullptr;
T Inline[N] = {0};
T Inline[N] = {};

bool isInline() const { return First == Inline; }

Expand Down Expand Up @@ -5542,7 +5541,7 @@ Node *AbstractManglingParser<Alloc, Derived>::parseFloatingLiteral() {
return nullptr;
std::string_view Data(First, N);
for (char C : Data)
if (!std::isxdigit(C))
if (!(C >= '0' && C <= '9') && !(C >= 'a' && C <= 'f'))
return nullptr;
First += N;
if (!consumeIf('E'))
Expand Down Expand Up @@ -5716,6 +5715,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseTemplateParam() {
}

// <template-param-decl> ::= Ty # type parameter
// ::= Tk <concept name> [<template-args>] # constrained type parameter
// ::= Tn <type> # non-type parameter
// ::= Tt <template-param-decl>* E # template parameter
// ::= Tp <template-param-decl> # parameter pack
Expand Down Expand Up @@ -5847,7 +5847,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseTemplateArg() {
}
}

// <template-args> ::= I <template-arg>* E
// <template-args> ::= I <template-arg>* [Q <requires-clause expr>] E
// extension, the abi says <template-arg>+
template <typename Derived, typename Alloc>
Node *
Expand Down
2 changes: 1 addition & 1 deletion system/lib/libcxxabi/src/fallback_malloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "fallback_malloc.h"
#include "abort_message.h"

#include <__threading_support>
#include <__thread/support.h>
#ifndef _LIBCXXABI_HAS_NO_THREADS
#if defined(__ELF__) && defined(_LIBCXXABI_LINK_PTHREAD_LIB)
#pragma comment(lib, "pthread")
Expand Down
34 changes: 23 additions & 11 deletions system/lib/libcxxabi/src/private_typeinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,25 @@
#include <cstdint>
#include <cassert>
#include <string.h>
#include "abort_message.h"

#ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST
#include "abort_message.h"
#include <sys/syslog.h>
#include <atomic>
#endif

#if __has_feature(ptrauth_calls)
#include <ptrauth.h>
#endif

template <typename T>
static inline T* strip_vtable(T* vtable) {
#if __has_feature(ptrauth_calls)
vtable = ptrauth_strip(vtable, ptrauth_key_cxx_vtable_pointer);
#endif
return vtable;
}

static inline
bool
is_equal(const std::type_info* x, const std::type_info* y, bool use_strcmp)
Expand Down Expand Up @@ -102,10 +114,10 @@ void dyn_cast_get_derived_info(derived_object_info* info, const void* static_ptr
reinterpret_cast<const uint8_t*>(vtable) + offset_to_ti_proxy;
info->dynamic_type = *(reinterpret_cast<const __class_type_info* const*>(ptr_to_ti_proxy));
#else
void **vtable = *static_cast<void ** const *>(static_ptr);
info->offset_to_derived = reinterpret_cast<ptrdiff_t>(vtable[-2]);
info->dynamic_ptr = static_cast<const char*>(static_ptr) + info->offset_to_derived;
info->dynamic_type = static_cast<const __class_type_info*>(vtable[-1]);
void** vtable = strip_vtable(*static_cast<void** const*>(static_ptr));
info->offset_to_derived = reinterpret_cast<ptrdiff_t>(vtable[-2]);
info->dynamic_ptr = static_cast<const char*>(static_ptr) + info->offset_to_derived;
info->dynamic_type = static_cast<const __class_type_info*>(vtable[-1]);
#endif
}

Expand Down Expand Up @@ -470,7 +482,7 @@ __class_type_info::can_catch(const __shim_type_info* thrown_type,
if (thrown_class_type == 0)
return false;
// bullet 2
assert(adjustedPtr && "catching a class without an object?");
_LIBCXXABI_ASSERT(adjustedPtr, "catching a class without an object?");
__dynamic_cast_info info = {thrown_class_type, 0, this, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, nullptr};
info.number_of_dst_type = 1;
thrown_class_type->has_unambiguous_public_base(&info, adjustedPtr, public_path);
Expand Down Expand Up @@ -560,7 +572,7 @@ __base_class_type_info::has_unambiguous_public_base(__dynamic_cast_info* info,
find the layout. */
offset_to_base = __offset_flags >> __offset_shift;
if (is_virtual) {
const char* vtable = *static_cast<const char* const*>(adjustedPtr);
const char* vtable = strip_vtable(*static_cast<const char* const*>(adjustedPtr));
offset_to_base = update_offset_to_base(vtable, offset_to_base);
}
} else if (!is_virtual) {
Expand Down Expand Up @@ -1500,8 +1512,8 @@ __base_class_type_info::search_above_dst(__dynamic_cast_info* info,
ptrdiff_t offset_to_base = __offset_flags >> __offset_shift;
if (__offset_flags & __virtual_mask)
{
const char* vtable = *static_cast<const char*const*>(current_ptr);
offset_to_base = update_offset_to_base(vtable, offset_to_base);
const char* vtable = strip_vtable(*static_cast<const char* const*>(current_ptr));
offset_to_base = update_offset_to_base(vtable, offset_to_base);
}
__base_type->search_above_dst(info, dst_ptr,
static_cast<const char*>(current_ptr) + offset_to_base,
Expand All @@ -1520,8 +1532,8 @@ __base_class_type_info::search_below_dst(__dynamic_cast_info* info,
ptrdiff_t offset_to_base = __offset_flags >> __offset_shift;
if (__offset_flags & __virtual_mask)
{
const char* vtable = *static_cast<const char*const*>(current_ptr);
offset_to_base = update_offset_to_base(vtable, offset_to_base);
const char* vtable = strip_vtable(*static_cast<const char* const*>(current_ptr));
offset_to_base = update_offset_to_base(vtable, offset_to_base);
}
__base_type->search_below_dst(info,
static_cast<const char*>(current_ptr) + offset_to_base,
Expand Down
Loading