Skip to content

Commit 43d6840

Browse files
authored
Update libcxxabi to llvm-12 (#14288)
Followup to #14280 Changes from upstream can be seen at: llvm/llvm-project@llvmorg-12.0.0...emscripten-core:emscripten-libs-12.0.0 Fixes: #14244
1 parent ae20c84 commit 43d6840

23 files changed

+569
-628
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ See docs/process.md for more on how version tagging works.
2020

2121
2.0.23
2222
------
23+
- libcxxabi updated to llvm-12. (#14288)
2324
- libcxx updated to llvm-12. (#14249)
2425
- compiler-rt updated to llvm-12. (#14280)
2526

system/lib/libcxxabi/include/__cxxabi_config.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
#define __has_attribute(_attribute_) 0
1919
#endif
2020

21+
#if defined(__clang__)
22+
# define _LIBCXXABI_COMPILER_CLANG
23+
# ifndef __apple_build_version__
24+
# define _LIBCXXABI_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
25+
# endif
26+
#elif defined(__GNUC__)
27+
# define _LIBCXXABI_COMPILER_GCC
28+
#elif defined(_MSC_VER)
29+
# define _LIBCXXABI_COMPILER_MSVC
30+
#elif defined(__IBMCPP__)
31+
# define _LIBCXXABI_COMPILER_IBM
32+
#endif
33+
2134
#if defined(_WIN32)
2235
#if defined(_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
2336
#define _LIBCXXABI_HIDDEN
@@ -53,7 +66,7 @@
5366
#endif
5467
#endif
5568

56-
#if defined(_WIN32)
69+
#if defined(_LIBCXXABI_COMPILER_MSVC)
5770
#define _LIBCXXABI_WEAK
5871
#else
5972
#define _LIBCXXABI_WEAK __attribute__((__weak__))
@@ -72,8 +85,16 @@
7285
#endif
7386

7487
// wasm32 follows the arm32 ABI convention of using 32-bit guard.
75-
#if defined(__arm__) || defined(__wasm32__)
88+
#if defined(__arm__) || defined(__wasm32__) || defined(__ARM64_ARCH_8_32__)
7689
# define _LIBCXXABI_GUARD_ABI_ARM
7790
#endif
7891

92+
#if defined(_LIBCXXABI_COMPILER_CLANG)
93+
# if !__has_feature(cxx_exceptions)
94+
# define _LIBCXXABI_NO_EXCEPTIONS
95+
# endif
96+
#elif defined(_LIBCXXABI_COMPILER_GCC) && !__EXCEPTIONS
97+
# define _LIBCXXABI_NO_EXCEPTIONS
98+
#endif
99+
79100
#endif // ____CXXABI_CONFIG_H

system/lib/libcxxabi/include/cxxabi.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#define _LIBCPPABI_VERSION 1002
2323
#define _LIBCXXABI_NORETURN __attribute__((noreturn))
24+
#define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
2425

2526
#ifdef __cplusplus
2627

@@ -82,13 +83,13 @@ extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_deleted_virtual(void);
8283

8384
// 3.3.2 One-time Construction API
8485
#if defined(_LIBCXXABI_GUARD_ABI_ARM)
85-
extern _LIBCXXABI_FUNC_VIS int __cxa_guard_acquire(uint32_t *);
86-
extern _LIBCXXABI_FUNC_VIS void __cxa_guard_release(uint32_t *);
87-
extern _LIBCXXABI_FUNC_VIS void __cxa_guard_abort(uint32_t *);
86+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint32_t *);
87+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint32_t *);
88+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint32_t *);
8889
#else
89-
extern _LIBCXXABI_FUNC_VIS int __cxa_guard_acquire(uint64_t *);
90-
extern _LIBCXXABI_FUNC_VIS void __cxa_guard_release(uint64_t *);
91-
extern _LIBCXXABI_FUNC_VIS void __cxa_guard_abort(uint64_t *);
90+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint64_t *);
91+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint64_t *);
92+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint64_t *);
9293
#endif
9394

9495
// 3.3.3 Array Construction and Destruction API
@@ -140,9 +141,9 @@ __cxa_vec_cctor(void *dest_array, void *src_array, size_t element_count,
140141
void (*destructor)(void *));
141142

142143
// 3.3.5.3 Runtime API
143-
extern _LIBCXXABI_FUNC_VIS int __cxa_atexit(void (*f)(void *), void *p,
144-
void *d);
145-
extern _LIBCXXABI_FUNC_VIS int __cxa_finalize(void *);
144+
// These functions are part of the C++ ABI, but they are not defined in libc++abi:
145+
// int __cxa_atexit(void (*)(void *), void *, void *);
146+
// void __cxa_finalize(void *);
146147

147148
// 3.4 Demangler API
148149
extern _LIBCXXABI_FUNC_VIS char *__cxa_demangle(const char *mangled_name,

system/lib/libcxxabi/readme.txt

Lines changed: 3 additions & 3 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 10.0.0.
4+
These files are from the llvm-project based on release 12.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-10.0.0
14-
git: d32170dbd5b0d54436537b6b75beaf44324e0c28
13+
tag: llvmorg-12.0.0
14+
git: d28af7c654d8db0b68c175db5ce212d74fb5e9bc
1515

1616
Update Instructions
1717
-------------------

system/lib/libcxxabi/src/CMakeLists.txt

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set(LIBCXXABI_SOURCES
77
cxa_exception_storage.cpp
88
cxa_guard.cpp
99
cxa_handlers.cpp
10-
cxa_unexpected.cpp
1110
cxa_vector.cpp
1211
cxa_virtual.cpp
1312
# C++ STL files
@@ -21,7 +20,9 @@ set(LIBCXXABI_SOURCES
2120
)
2221

2322
if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
24-
list(APPEND LIBCXXABI_SOURCES stdlib_new_delete.cpp)
23+
list(APPEND LIBCXXABI_SOURCES
24+
stdlib_new_delete.cpp
25+
)
2526
endif()
2627

2728
if (LIBCXXABI_ENABLE_EXCEPTIONS)
@@ -60,6 +61,10 @@ if (LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
6061
add_definitions(-DHAVE___CXA_THREAD_ATEXIT_IMPL)
6162
endif()
6263

64+
if (LIBCXXABI_ENABLE_FORGIVING_DYNAMIC_CAST)
65+
add_definitions(-D_LIBCXXABI_FORGIVING_DYNAMIC_CAST)
66+
endif()
67+
6368
if (APPLE)
6469
add_library_flags_if(LIBCXXABI_HAS_SYSTEM_LIB System)
6570
else()
@@ -95,6 +100,9 @@ if (MINGW)
95100
# MINGW_LIBRARIES is defined in config-ix.cmake
96101
list(APPEND LIBCXXABI_LIBRARIES ${MINGW_LIBRARIES})
97102
endif()
103+
if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
104+
list(APPEND LIBCXXABI_LIBRARIES android_support)
105+
endif()
98106

99107
if (NOT LIBCXXABI_USE_COMPILER_RT)
100108
add_library_flags_if(LIBCXXABI_HAS_GCC_LIB gcc)
@@ -128,6 +136,17 @@ if ( APPLE )
128136
add_link_flags("-Wl,-rpath,${LIBDIR}")
129137
endif()
130138
endif()
139+
140+
# Make sure we link in CrashReporterClient if we find it -- it's used by
141+
# abort() on Apple platforms when building the system dylib.
142+
find_library(CrashReporterClient NAMES libCrashReporterClient.a
143+
PATHS "${CMAKE_OSX_SYSROOT}/usr/local/lib")
144+
if (CrashReporterClient)
145+
message(STATUS "Linking with CrashReporterClient at ${CrashReporterClient}")
146+
add_library_flags("${CrashReporterClient}")
147+
else()
148+
message(STATUS "Could not find CrashReporterClient, not linking against it")
149+
endif()
131150
endif()
132151

133152
split_list(LIBCXXABI_COMPILE_FLAGS)
@@ -143,18 +162,9 @@ if (NOT TARGET pstl::ParallelSTL)
143162
message(STATUS "Could not find ParallelSTL, libc++abi will not attempt to use it but the build may fail if the libc++ in use needs it to be available.")
144163
endif()
145164

146-
if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "^(armv6|armv7|armv7s)$")
147-
set(LIBCXXABI_USE_SJLJ_EXCEPTIONS ON)
148-
else()
149-
set(LIBCXXABI_USE_SJLJ_EXCEPTIONS OFF)
150-
endif()
151-
152165
# Build the shared library.
153166
if (LIBCXXABI_ENABLE_SHARED)
154167
add_library(cxxabi_shared SHARED ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
155-
if(COMMAND llvm_setup_rpath)
156-
llvm_setup_rpath(cxxabi_shared)
157-
endif()
158168
target_link_libraries(cxxabi_shared PRIVATE ${LIBCXXABI_SHARED_LIBRARIES} ${LIBCXXABI_LIBRARIES})
159169
if (TARGET pstl::ParallelSTL)
160170
target_link_libraries(cxxabi_shared PUBLIC pstl::ParallelSTL)
@@ -164,9 +174,9 @@ if (LIBCXXABI_ENABLE_SHARED)
164174
CXX_EXTENSIONS
165175
OFF
166176
CXX_STANDARD
167-
11
177+
20
168178
CXX_STANDARD_REQUIRED
169-
ON
179+
OFF
170180
COMPILE_FLAGS
171181
"${LIBCXXABI_COMPILE_FLAGS}"
172182
LINK_FLAGS
@@ -189,18 +199,32 @@ if (LIBCXXABI_ENABLE_SHARED)
189199
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
190200
endif()
191201

202+
add_library(cxxabi-reexports INTERFACE)
203+
192204
# -exported_symbols_list is only available on Apple platforms
193205
if (APPLE)
194-
target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/itanium-base.exp")
206+
function(export_symbols file)
207+
target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${file}")
208+
endfunction()
209+
function(reexport_symbols file)
210+
export_symbols("${file}")
211+
target_link_libraries(cxxabi-reexports INTERFACE "-Wl,-reexported_symbols_list,${file}")
212+
endfunction()
213+
214+
export_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/itanium-base.exp")
195215

196216
if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
197-
target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/new-delete.exp")
217+
reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/new-delete.exp")
198218
endif()
199219

200-
if (LIBCXXABI_USE_SJLJ_EXCEPTIONS)
201-
target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-sjlj.exp")
202-
else()
203-
target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-v0.exp")
220+
if (LIBCXXABI_ENABLE_EXCEPTIONS)
221+
reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/exceptions.exp")
222+
223+
if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "^(armv6|armv7|armv7s)$")
224+
reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-sjlj.exp")
225+
else()
226+
reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-v0.exp")
227+
endif()
204228
endif()
205229
endif()
206230
endif()
@@ -217,9 +241,9 @@ if (LIBCXXABI_ENABLE_STATIC)
217241
CXX_EXTENSIONS
218242
OFF
219243
CXX_STANDARD
220-
11
244+
20
221245
CXX_STANDARD_REQUIRED
222-
ON
246+
OFF
223247
COMPILE_FLAGS
224248
"${LIBCXXABI_COMPILE_FLAGS}"
225249
LINK_FLAGS
@@ -255,10 +279,10 @@ if (LIBCXXABI_ENABLE_STATIC)
255279
set(MERGE_ARCHIVES_LIBTOOL "--use-libtool" "--libtool" "${CMAKE_LIBTOOL}")
256280
endif()
257281

258-
# Merge the the libc++abi.a and libunwind.a into one.
282+
# Merge the libc++abi.a and libunwind.a into one.
259283
if(LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
260284
add_custom_command(TARGET cxxabi_static POST_BUILD
261-
COMMAND ${PYTHON_EXECUTABLE} ${LIBCXXABI_LIBCXX_PATH}/utils/merge_archives.py
285+
COMMAND ${Python3_EXECUTABLE} ${LIBCXXABI_LIBCXX_PATH}/utils/merge_archives.py
262286
ARGS
263287
-o "$<TARGET_LINKER_FILE:cxxabi_static>"
264288
--ar "${CMAKE_AR}"
@@ -292,7 +316,4 @@ if (NOT CMAKE_CONFIGURATION_TYPES AND LIBCXXABI_INSTALL_LIBRARY)
292316
-DCMAKE_INSTALL_COMPONENT=cxxabi
293317
-DCMAKE_INSTALL_DO_STRIP=1
294318
-P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
295-
296-
# TODO: This is a legacy target name and should be removed at some point.
297-
add_custom_target(install-libcxxabi DEPENDS install-cxxabi)
298319
endif()

system/lib/libcxxabi/src/abort_message.cpp

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,74 +12,76 @@
1212
#include "abort_message.h"
1313

1414
#ifdef __BIONIC__
15-
#include <android/api-level.h>
16-
#if __ANDROID_API__ >= 21
17-
#include <syslog.h>
18-
extern "C" void android_set_abort_message(const char* msg);
19-
#else
20-
#include <assert.h>
21-
#endif // __ANDROID_API__ >= 21
15+
# include <android/api-level.h>
16+
# if __ANDROID_API__ >= 21
17+
# include <syslog.h>
18+
extern "C" void android_set_abort_message(const char* msg);
19+
# else
20+
# include <assert.h>
21+
# endif // __ANDROID_API__ >= 21
2222
#endif // __BIONIC__
2323

24-
#ifdef __APPLE__
25-
# if defined(__has_include) && __has_include(<CrashReporterClient.h>)
26-
# define HAVE_CRASHREPORTERCLIENT_H
27-
# include <CrashReporterClient.h>
28-
# endif
24+
#if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
25+
# include <CrashReporterClient.h>
26+
# define _LIBCXXABI_USE_CRASHREPORTER_CLIENT
2927
#endif
3028

3129
void abort_message(const char* format, ...)
3230
{
33-
// write message to stderr
31+
// Write message to stderr. We do this before formatting into a
32+
// variable-size buffer so that we still get some information if
33+
// formatting into the variable-sized buffer fails.
3434
#if !defined(NDEBUG) || !defined(LIBCXXABI_BAREMETAL)
35-
#ifdef __APPLE__
36-
fprintf(stderr, "libc++abi.dylib: ");
37-
#endif
35+
{
3836
#if defined(__EMSCRIPTEN__) && defined(NDEBUG)
39-
// Just trap in a non-debug build. These internal libcxxabi assertions are
40-
// very rare, and it's not worth linking in vfprintf stdio support or
41-
// even minimal logging for them, as we'll have a proper call stack, which
42-
// will show a call into "abort_message", and can help debugging. (In a
43-
// debug build that won't be inlined.)
44-
__builtin_trap();
37+
// Just trap in a non-debug build. These internal libcxxabi assertions are
38+
// very rare, and it's not worth linking in vfprintf stdio support or
39+
// even minimal logging for them, as we'll have a proper call stack, which
40+
// will show a call into "abort_message", and can help debugging. (In a
41+
// debug build that won't be inlined.)
42+
__builtin_trap();
4543
#else
44+
fprintf(stderr, "libc++abi: ");
45+
va_list list;
46+
va_start(list, format);
47+
vfprintf(stderr, format, list);
48+
va_end(list);
49+
fprintf(stderr, "\n");
50+
#endif
51+
}
52+
#endif
53+
54+
// Format the arguments into an allocated buffer. We leak the buffer on
55+
// purpose, since we're about to abort() anyway.
56+
#if defined(_LIBCXXABI_USE_CRASHREPORTER_CLIENT)
57+
char* buffer;
4658
va_list list;
4759
va_start(list, format);
48-
vfprintf(stderr, format, list);
60+
vasprintf(&buffer, format, list);
4961
va_end(list);
50-
fprintf(stderr, "\n");
51-
#endif // EMSCRIPTEN
52-
#endif
5362

54-
#if defined(__APPLE__) && defined(HAVE_CRASHREPORTERCLIENT_H)
55-
// record message in crash report
56-
char* buffer;
57-
va_list list2;
58-
va_start(list2, format);
59-
vasprintf(&buffer, format, list2);
60-
va_end(list2);
6163
CRSetCrashLogMessage(buffer);
6264
#elif defined(__BIONIC__)
6365
char* buffer;
64-
va_list list2;
65-
va_start(list2, format);
66-
vasprintf(&buffer, format, list2);
67-
va_end(list2);
66+
va_list list;
67+
va_start(list, format);
68+
vasprintf(&buffer, format, list);
69+
va_end(list);
6870

69-
#if __ANDROID_API__ >= 21
71+
# if __ANDROID_API__ >= 21
7072
// Show error in tombstone.
7173
android_set_abort_message(buffer);
7274

7375
// Show error in logcat.
7476
openlog("libc++abi", 0, 0);
7577
syslog(LOG_CRIT, "%s", buffer);
7678
closelog();
77-
#else
79+
# else
7880
// The good error reporting wasn't available in Android until L. Since we're
7981
// about to abort anyway, just call __assert2, which will log _somewhere_
8082
// (tombstone and/or logcat) in older releases.
8183
__assert2(__FILE__, __LINE__, __func__, buffer);
82-
#endif // __ANDROID_API__ >= 21
84+
# endif // __ANDROID_API__ >= 21
8385
#endif // __BIONIC__
8486

8587
abort();

0 commit comments

Comments
 (0)