Skip to content

Commit 5eccb0f

Browse files
authored
Update libc++abi to LLVM 14 (#16993)
No major conflicts or changes required.
1 parent 22e3b04 commit 5eccb0f

37 files changed

+1232
-1229
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ See docs/process.md for more on how version tagging works.
2828
and therefore was renamed to `EMTEST_BUILD_VERBOSE`. (#16904)
2929
- compiler-rt updated to LLVM 14. (#16991)
3030
- libc++ updated to LLVM 14. (#17000)
31+
- libc++abi updated to LLVM 14. (#16993)
3132

3233
3.1.10 - 05/02/2022
3334
-------------------

system/lib/libcxxabi/include/__cxxabi_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-------------------------- __cxxabi_config.h -------------------------===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -93,7 +93,7 @@
9393
# if !__has_feature(cxx_exceptions)
9494
# define _LIBCXXABI_NO_EXCEPTIONS
9595
# endif
96-
#elif defined(_LIBCXXABI_COMPILER_GCC) && !__EXCEPTIONS
96+
#elif defined(_LIBCXXABI_COMPILER_GCC) && !defined(__EXCEPTIONS)
9797
# define _LIBCXXABI_NO_EXCEPTIONS
9898
#endif
9999

system/lib/libcxxabi/include/cxxabi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--------------------------- cxxabi.h ---------------------------------===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

system/lib/libcxxabi/readme.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
llvm's libcxxabi
22
----------------
33

4-
These files are from the llvm-project based on release 13.0.0.
4+
These files are from the llvm-project based on release 14.0.0.
55

66
We maintain a local fork of llvm-project that contains any emscripten
77
specific patches:
@@ -10,8 +10,8 @@ specific patches:
1010

1111
The current patch is based on:
1212

13-
tag: llvmorg-13.0.0
14-
git: d7b669b3a30345cfcdb2fde2af6f48aa4b94845d
13+
tag: llvmorg-14.0.0
14+
git: 329fda39c507e8740978d10458451dcdb21563be
1515

1616
Update Instructions
1717
-------------------
@@ -23,4 +23,4 @@ Modifications
2323

2424
For a list of changes from upstream see the libcxxabi files that are part of:
2525

26-
https://github.com/llvm/llvm-project/compare/llvmorg-13.0.0...emscripten-core:emscripten-libs-13.0.0
26+
https://github.com/llvm/llvm-project/compare/llvmorg-14.0.0...emscripten-core:emscripten-libs-14.0.0

system/lib/libcxxabi/src/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ if (MSVC_IDE OR XCODE)
5656
endif()
5757
endif()
5858

59-
# stdlib_stdexcept.cpp depends on libc++ internals.
60-
include_directories("${LIBCXXABI_LIBCXX_PATH}")
59+
# Some files depend on libc++ internals.
60+
include_directories("${LIBCXXABI_LIBCXX_PATH}/src")
6161

6262
if (LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
6363
add_definitions(-DHAVE___CXA_THREAD_ATEXIT_IMPL)
@@ -136,7 +136,8 @@ if ( APPLE )
136136
message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X")
137137
endif()
138138
if (LIBFILE)
139-
find_compiler_rt_dir(LIBDIR)
139+
find_compiler_rt_library(builtins LIBCXXABI_BUILTINS_LIBRARY)
140+
get_filename_component(LIBDIR "${LIBCXXABI_BUILTINS_LIBRARY}" DIRECTORY)
140141
if (NOT IS_DIRECTORY "${LIBDIR}")
141142
message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER")
142143
endif()
@@ -191,7 +192,6 @@ if (LIBCXXABI_ENABLE_SHARED)
191192
SOVERSION "1"
192193
VERSION "${LIBCXXABI_LIBRARY_VERSION}"
193194
DEFINE_SYMBOL ""
194-
POSITION_INDEPENDENT_CODE ON
195195
)
196196

197197
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared")
@@ -244,7 +244,6 @@ if (LIBCXXABI_ENABLE_STATIC)
244244
COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
245245
LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
246246
OUTPUT_NAME "c++abi"
247-
POSITION_INDEPENDENT_CODE ON
248247
)
249248

250249
if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
@@ -294,6 +293,7 @@ if (LIBCXXABI_INSTALL_LIBRARY)
294293
install(TARGETS ${LIBCXXABI_INSTALL_TARGETS}
295294
LIBRARY DESTINATION ${LIBCXXABI_INSTALL_LIBRARY_DIR} COMPONENT cxxabi
296295
ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_LIBRARY_DIR} COMPONENT cxxabi
296+
RUNTIME DESTINATION ${LIBCXXABI_INSTALL_RUNTIME_DIR} COMPONENT cxxabi
297297
)
298298
endif()
299299

system/lib/libcxxabi/src/abort_message.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===------------------------- abort_message.cpp --------------------------===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

system/lib/libcxxabi/src/abort_message.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-------------------------- abort_message.h-----------------------------===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

system/lib/libcxxabi/src/cxa_aux_runtime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===------------------------ cxa_aux_runtime.cpp -------------------------===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

system/lib/libcxxabi/src/cxa_default_handlers.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
//===------------------------- cxa_default_handlers.cpp -------------------===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//
8-
// This file implements the default terminate_handler and unexpected_handler.
8+
// This file implements the default terminate_handler, unexpected_handler and
9+
// new_handler.
910
//===----------------------------------------------------------------------===//
1011

1112
#include <exception>
@@ -15,7 +16,7 @@
1516
#include "cxa_handlers.h"
1617
#include "cxa_exception.h"
1718
#include "private_typeinfo.h"
18-
#include "include/atomic_support.h"
19+
#include "include/atomic_support.h" // from libc++
1920

2021
#if !defined(LIBCXXABI_SILENT_TERMINATE)
2122

@@ -104,6 +105,9 @@ _LIBCPP_SAFE_STATIC std::terminate_handler __cxa_terminate_handler = default_ter
104105
_LIBCXXABI_DATA_VIS
105106
_LIBCPP_SAFE_STATIC std::unexpected_handler __cxa_unexpected_handler = default_unexpected_handler;
106107

108+
_LIBCXXABI_DATA_VIS
109+
_LIBCPP_SAFE_STATIC std::new_handler __cxa_new_handler = 0;
110+
107111
namespace std
108112
{
109113

@@ -125,4 +129,10 @@ set_terminate(terminate_handler func) noexcept
125129
_AO_Acq_Rel);
126130
}
127131

132+
new_handler
133+
set_new_handler(new_handler handler) noexcept
134+
{
135+
return __libcpp_atomic_exchange(&__cxa_new_handler, handler, _AO_Acq_Rel);
136+
}
137+
128138
}

system/lib/libcxxabi/src/cxa_demangle.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-------------------------- cxa_demangle.cpp --------------------------===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -342,21 +342,21 @@ __cxa_demangle(const char *MangledName, char *Buf, size_t *N, int *Status) {
342342

343343
int InternalStatus = demangle_success;
344344
Demangler Parser(MangledName, MangledName + std::strlen(MangledName));
345-
OutputStream S;
345+
OutputBuffer O;
346346

347347
Node *AST = Parser.parse();
348348

349349
if (AST == nullptr)
350350
InternalStatus = demangle_invalid_mangled_name;
351-
else if (!initializeOutputStream(Buf, N, S, 1024))
351+
else if (!initializeOutputBuffer(Buf, N, O, 1024))
352352
InternalStatus = demangle_memory_alloc_failure;
353353
else {
354354
assert(Parser.ForwardTemplateRefs.empty());
355-
AST->print(S);
356-
S += '\0';
355+
AST->print(O);
356+
O += '\0';
357357
if (N != nullptr)
358-
*N = S.getCurrentPosition();
359-
Buf = S.getBuffer();
358+
*N = O.getCurrentPosition();
359+
Buf = O.getBuffer();
360360
}
361361

362362
if (Status)

system/lib/libcxxabi/src/cxa_exception.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===------------------------- cxa_exception.cpp --------------------------===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -17,7 +17,7 @@
1717
#include "cxa_exception.h"
1818
#include "cxa_handlers.h"
1919
#include "fallback_malloc.h"
20-
#include "include/atomic_support.h"
20+
#include "include/atomic_support.h" // from libc++
2121

2222
#if __has_feature(address_sanitizer)
2323
#include <sanitizer/asan_interface.h>
@@ -346,8 +346,10 @@ unwinding with _Unwind_Resume.
346346
According to ARM EHABI 8.4.1, __cxa_end_cleanup() should not clobber any
347347
register, thus we have to write this function in assembly so that we can save
348348
{r1, r2, r3}. We don't have to save r0 because it is the return value and the
349-
first argument to _Unwind_Resume(). In addition, we are saving r4 in order to
350-
align the stack to 16 bytes, even though it is a callee-save register.
349+
first argument to _Unwind_Resume(). In addition, we are saving lr in order to
350+
align the stack to 16 bytes and lr will be used to identify the caller and its
351+
frame information. _Unwind_Resume never return and we need to keep the original
352+
lr so just branch to it.
351353
*/
352354
__attribute__((used)) static _Unwind_Exception *
353355
__cxa_end_cleanup_impl()
@@ -377,18 +379,24 @@ __cxa_end_cleanup_impl()
377379
return &exception_header->unwindHeader;
378380
}
379381

380-
asm (
381-
" .pushsection .text.__cxa_end_cleanup,\"ax\",%progbits\n"
382+
asm(" .pushsection .text.__cxa_end_cleanup,\"ax\",%progbits\n"
382383
" .globl __cxa_end_cleanup\n"
383384
" .type __cxa_end_cleanup,%function\n"
384385
"__cxa_end_cleanup:\n"
385-
" push {r1, r2, r3, r4}\n"
386+
#if defined(__ARM_FEATURE_BTI_DEFAULT)
387+
" bti\n"
388+
#endif
389+
" push {r1, r2, r3, lr}\n"
386390
" bl __cxa_end_cleanup_impl\n"
387391
" pop {r1, r2, r3, r4}\n"
388-
" bl _Unwind_Resume\n"
389-
" bl abort\n"
390-
" .popsection"
391-
);
392+
" mov lr, r4\n"
393+
#if defined(LIBCXXABI_BAREMETAL)
394+
" ldr r4, =_Unwind_Resume\n"
395+
" bx r4\n"
396+
#else
397+
" b _Unwind_Resume\n"
398+
#endif
399+
" .popsection");
392400
#endif // defined(_LIBCXXABI_ARM_EHABI)
393401

394402
/*

system/lib/libcxxabi/src/cxa_exception.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===------------------------- cxa_exception.h ----------------------------===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--------------------- cxa_exception_storage.cpp ----------------------===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -21,25 +21,24 @@ extern "C" {
2121
static __cxa_eh_globals eh_globals;
2222
__cxa_eh_globals *__cxa_get_globals() { return &eh_globals; }
2323
__cxa_eh_globals *__cxa_get_globals_fast() { return &eh_globals; }
24-
}
25-
}
24+
} // extern "C"
25+
} // namespace __cxxabiv1
2626

2727
#elif defined(HAS_THREAD_LOCAL)
2828

2929
namespace __cxxabiv1 {
30-
3130
namespace {
32-
__cxa_eh_globals * __globals () {
31+
__cxa_eh_globals *__globals() {
3332
static thread_local __cxa_eh_globals eh_globals;
3433
return &eh_globals;
35-
}
3634
}
35+
} // namespace
3736

3837
extern "C" {
39-
__cxa_eh_globals * __cxa_get_globals () { return __globals (); }
40-
__cxa_eh_globals * __cxa_get_globals_fast () { return __globals (); }
41-
}
42-
}
38+
__cxa_eh_globals *__cxa_get_globals() { return __globals(); }
39+
__cxa_eh_globals *__cxa_get_globals_fast() { return __globals(); }
40+
} // extern "C"
41+
} // namespace __cxxabiv1
4342

4443
#else
4544

@@ -59,47 +58,46 @@ namespace {
5958
std::__libcpp_tls_key key_;
6059
std::__libcpp_exec_once_flag flag_ = _LIBCPP_EXEC_ONCE_INITIALIZER;
6160

62-
void _LIBCPP_TLS_DESTRUCTOR_CC destruct_ (void *p) {
63-
__free_with_fallback ( p );
64-
if ( 0 != std::__libcpp_tls_set ( key_, NULL ) )
61+
void _LIBCPP_TLS_DESTRUCTOR_CC destruct_(void *p) {
62+
__free_with_fallback(p);
63+
if (0 != std::__libcpp_tls_set(key_, NULL))
6564
abort_message("cannot zero out thread value for __cxa_get_globals()");
66-
}
65+
}
6766

68-
void construct_ () {
69-
if ( 0 != std::__libcpp_tls_create ( &key_, destruct_ ) )
67+
void construct_() {
68+
if (0 != std::__libcpp_tls_create(&key_, destruct_))
7069
abort_message("cannot create thread specific key for __cxa_get_globals()");
71-
}
72-
}
70+
}
71+
} // namespace
7372

7473
extern "C" {
75-
__cxa_eh_globals * __cxa_get_globals () {
76-
// Try to get the globals for this thread
77-
__cxa_eh_globals* retVal = __cxa_get_globals_fast ();
78-
79-
// If this is the first time we've been asked for these globals, create them
80-
if ( NULL == retVal ) {
81-
retVal = static_cast<__cxa_eh_globals*>
82-
(__calloc_with_fallback (1, sizeof (__cxa_eh_globals)));
83-
if ( NULL == retVal )
74+
__cxa_eh_globals *__cxa_get_globals() {
75+
// Try to get the globals for this thread
76+
__cxa_eh_globals *retVal = __cxa_get_globals_fast();
77+
78+
// If this is the first time we've been asked for these globals, create them
79+
if (NULL == retVal) {
80+
retVal = static_cast<__cxa_eh_globals*>(
81+
__calloc_with_fallback(1, sizeof(__cxa_eh_globals)));
82+
if (NULL == retVal)
8483
abort_message("cannot allocate __cxa_eh_globals");
85-
if ( 0 != std::__libcpp_tls_set ( key_, retVal ) )
84+
if (0 != std::__libcpp_tls_set(key_, retVal))
8685
abort_message("std::__libcpp_tls_set failure in __cxa_get_globals()");
87-
}
88-
return retVal;
8986
}
87+
return retVal;
88+
}
9089

9190
// Note that this implementation will reliably return NULL if not
9291
// preceded by a call to __cxa_get_globals(). This is an extension
9392
// to the Itanium ABI and is taken advantage of in several places in
9493
// libc++abi.
95-
__cxa_eh_globals * __cxa_get_globals_fast () {
96-
// First time through, create the key.
94+
__cxa_eh_globals *__cxa_get_globals_fast() {
95+
// First time through, create the key.
9796
if (0 != std::__libcpp_execute_once(&flag_, construct_))
9897
abort_message("execute once failure in __cxa_get_globals_fast()");
99-
// static int init = construct_();
10098
return static_cast<__cxa_eh_globals*>(std::__libcpp_tls_get(key_));
101-
}
99+
}
100+
} // extern "C"
101+
} // namespace __cxxabiv1
102102

103-
}
104-
}
105103
#endif

system/lib/libcxxabi/src/cxa_guard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===---------------------------- cxa_guard.cpp ---------------------------===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

0 commit comments

Comments
 (0)