Skip to content

Update libcxxabi to llvm-12 #14288

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

Merged
merged 1 commit into from
May 26, 2021
Merged
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
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ See docs/process.md for more on how version tagging works.

2.0.23
------
- libcxxabi updated to llvm-12. (#14288)
- libcxx updated to llvm-12. (#14249)
- compiler-rt updated to llvm-12. (#14280)

Expand Down
25 changes: 23 additions & 2 deletions system/lib/libcxxabi/include/__cxxabi_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
#define __has_attribute(_attribute_) 0
#endif

#if defined(__clang__)
# define _LIBCXXABI_COMPILER_CLANG
# ifndef __apple_build_version__
# define _LIBCXXABI_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
# endif
#elif defined(__GNUC__)
# define _LIBCXXABI_COMPILER_GCC
#elif defined(_MSC_VER)
# define _LIBCXXABI_COMPILER_MSVC
#elif defined(__IBMCPP__)
# define _LIBCXXABI_COMPILER_IBM
#endif

#if defined(_WIN32)
#if defined(_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
#define _LIBCXXABI_HIDDEN
Expand Down Expand Up @@ -53,7 +66,7 @@
#endif
#endif

#if defined(_WIN32)
#if defined(_LIBCXXABI_COMPILER_MSVC)
#define _LIBCXXABI_WEAK
#else
#define _LIBCXXABI_WEAK __attribute__((__weak__))
Expand All @@ -72,8 +85,16 @@
#endif

// wasm32 follows the arm32 ABI convention of using 32-bit guard.
#if defined(__arm__) || defined(__wasm32__)
#if defined(__arm__) || defined(__wasm32__) || defined(__ARM64_ARCH_8_32__)
# define _LIBCXXABI_GUARD_ABI_ARM
#endif

#if defined(_LIBCXXABI_COMPILER_CLANG)
# if !__has_feature(cxx_exceptions)
# define _LIBCXXABI_NO_EXCEPTIONS
# endif
#elif defined(_LIBCXXABI_COMPILER_GCC) && !__EXCEPTIONS
# define _LIBCXXABI_NO_EXCEPTIONS
#endif

#endif // ____CXXABI_CONFIG_H
19 changes: 10 additions & 9 deletions system/lib/libcxxabi/include/cxxabi.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#define _LIBCPPABI_VERSION 1002
#define _LIBCXXABI_NORETURN __attribute__((noreturn))
#define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))

#ifdef __cplusplus

Expand Down Expand Up @@ -82,13 +83,13 @@ extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_deleted_virtual(void);

// 3.3.2 One-time Construction API
#if defined(_LIBCXXABI_GUARD_ABI_ARM)
extern _LIBCXXABI_FUNC_VIS int __cxa_guard_acquire(uint32_t *);
extern _LIBCXXABI_FUNC_VIS void __cxa_guard_release(uint32_t *);
extern _LIBCXXABI_FUNC_VIS void __cxa_guard_abort(uint32_t *);
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint32_t *);
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint32_t *);
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint32_t *);
#else
extern _LIBCXXABI_FUNC_VIS int __cxa_guard_acquire(uint64_t *);
extern _LIBCXXABI_FUNC_VIS void __cxa_guard_release(uint64_t *);
extern _LIBCXXABI_FUNC_VIS void __cxa_guard_abort(uint64_t *);
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint64_t *);
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint64_t *);
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint64_t *);
#endif

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

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

// 3.4 Demangler API
extern _LIBCXXABI_FUNC_VIS char *__cxa_demangle(const char *mangled_name,
Expand Down
6 changes: 3 additions & 3 deletions system/lib/libcxxabi/readme.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
llvm's libcxxabi
----------------

These files are from the llvm-project based on release 10.0.0.
These files are from the llvm-project based on release 12.0.0.

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

The current patch is based on:

tag: llvmorg-10.0.0
git: d32170dbd5b0d54436537b6b75beaf44324e0c28
tag: llvmorg-12.0.0
git: d28af7c654d8db0b68c175db5ce212d74fb5e9bc

Update Instructions
-------------------
Expand Down
73 changes: 47 additions & 26 deletions system/lib/libcxxabi/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ set(LIBCXXABI_SOURCES
cxa_exception_storage.cpp
cxa_guard.cpp
cxa_handlers.cpp
cxa_unexpected.cpp
cxa_vector.cpp
cxa_virtual.cpp
# C++ STL files
Expand All @@ -21,7 +20,9 @@ set(LIBCXXABI_SOURCES
)

if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
list(APPEND LIBCXXABI_SOURCES stdlib_new_delete.cpp)
list(APPEND LIBCXXABI_SOURCES
stdlib_new_delete.cpp
)
endif()

if (LIBCXXABI_ENABLE_EXCEPTIONS)
Expand Down Expand Up @@ -60,6 +61,10 @@ if (LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
add_definitions(-DHAVE___CXA_THREAD_ATEXIT_IMPL)
endif()

if (LIBCXXABI_ENABLE_FORGIVING_DYNAMIC_CAST)
add_definitions(-D_LIBCXXABI_FORGIVING_DYNAMIC_CAST)
endif()

if (APPLE)
add_library_flags_if(LIBCXXABI_HAS_SYSTEM_LIB System)
else()
Expand Down Expand Up @@ -95,6 +100,9 @@ if (MINGW)
# MINGW_LIBRARIES is defined in config-ix.cmake
list(APPEND LIBCXXABI_LIBRARIES ${MINGW_LIBRARIES})
endif()
if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
list(APPEND LIBCXXABI_LIBRARIES android_support)
endif()

if (NOT LIBCXXABI_USE_COMPILER_RT)
add_library_flags_if(LIBCXXABI_HAS_GCC_LIB gcc)
Expand Down Expand Up @@ -128,6 +136,17 @@ if ( APPLE )
add_link_flags("-Wl,-rpath,${LIBDIR}")
endif()
endif()

# Make sure we link in CrashReporterClient if we find it -- it's used by
# abort() on Apple platforms when building the system dylib.
find_library(CrashReporterClient NAMES libCrashReporterClient.a
PATHS "${CMAKE_OSX_SYSROOT}/usr/local/lib")
if (CrashReporterClient)
message(STATUS "Linking with CrashReporterClient at ${CrashReporterClient}")
add_library_flags("${CrashReporterClient}")
else()
message(STATUS "Could not find CrashReporterClient, not linking against it")
endif()
endif()

split_list(LIBCXXABI_COMPILE_FLAGS)
Expand All @@ -143,18 +162,9 @@ if (NOT TARGET pstl::ParallelSTL)
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.")
endif()

if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "^(armv6|armv7|armv7s)$")
set(LIBCXXABI_USE_SJLJ_EXCEPTIONS ON)
else()
set(LIBCXXABI_USE_SJLJ_EXCEPTIONS OFF)
endif()

# Build the shared library.
if (LIBCXXABI_ENABLE_SHARED)
add_library(cxxabi_shared SHARED ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
if(COMMAND llvm_setup_rpath)
llvm_setup_rpath(cxxabi_shared)
endif()
target_link_libraries(cxxabi_shared PRIVATE ${LIBCXXABI_SHARED_LIBRARIES} ${LIBCXXABI_LIBRARIES})
if (TARGET pstl::ParallelSTL)
target_link_libraries(cxxabi_shared PUBLIC pstl::ParallelSTL)
Expand All @@ -164,9 +174,9 @@ if (LIBCXXABI_ENABLE_SHARED)
CXX_EXTENSIONS
OFF
CXX_STANDARD
11
20
CXX_STANDARD_REQUIRED
ON
OFF
COMPILE_FLAGS
"${LIBCXXABI_COMPILE_FLAGS}"
LINK_FLAGS
Expand All @@ -189,18 +199,32 @@ if (LIBCXXABI_ENABLE_SHARED)
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
endif()

add_library(cxxabi-reexports INTERFACE)

# -exported_symbols_list is only available on Apple platforms
if (APPLE)
target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/itanium-base.exp")
function(export_symbols file)
target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${file}")
endfunction()
function(reexport_symbols file)
export_symbols("${file}")
target_link_libraries(cxxabi-reexports INTERFACE "-Wl,-reexported_symbols_list,${file}")
endfunction()

export_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/itanium-base.exp")

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

if (LIBCXXABI_USE_SJLJ_EXCEPTIONS)
target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-sjlj.exp")
else()
target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-v0.exp")
if (LIBCXXABI_ENABLE_EXCEPTIONS)
reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/exceptions.exp")

if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "^(armv6|armv7|armv7s)$")
reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-sjlj.exp")
else()
reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-v0.exp")
endif()
endif()
endif()
endif()
Expand All @@ -217,9 +241,9 @@ if (LIBCXXABI_ENABLE_STATIC)
CXX_EXTENSIONS
OFF
CXX_STANDARD
11
20
CXX_STANDARD_REQUIRED
ON
OFF
COMPILE_FLAGS
"${LIBCXXABI_COMPILE_FLAGS}"
LINK_FLAGS
Expand Down Expand Up @@ -255,10 +279,10 @@ if (LIBCXXABI_ENABLE_STATIC)
set(MERGE_ARCHIVES_LIBTOOL "--use-libtool" "--libtool" "${CMAKE_LIBTOOL}")
endif()

# Merge the the libc++abi.a and libunwind.a into one.
# Merge the libc++abi.a and libunwind.a into one.
if(LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
add_custom_command(TARGET cxxabi_static POST_BUILD
COMMAND ${PYTHON_EXECUTABLE} ${LIBCXXABI_LIBCXX_PATH}/utils/merge_archives.py
COMMAND ${Python3_EXECUTABLE} ${LIBCXXABI_LIBCXX_PATH}/utils/merge_archives.py
ARGS
-o "$<TARGET_LINKER_FILE:cxxabi_static>"
--ar "${CMAKE_AR}"
Expand Down Expand Up @@ -292,7 +316,4 @@ if (NOT CMAKE_CONFIGURATION_TYPES AND LIBCXXABI_INSTALL_LIBRARY)
-DCMAKE_INSTALL_COMPONENT=cxxabi
-DCMAKE_INSTALL_DO_STRIP=1
-P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")

# TODO: This is a legacy target name and should be removed at some point.
add_custom_target(install-libcxxabi DEPENDS install-cxxabi)
endif()
82 changes: 42 additions & 40 deletions system/lib/libcxxabi/src/abort_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,74 +12,76 @@
#include "abort_message.h"

#ifdef __BIONIC__
#include <android/api-level.h>
#if __ANDROID_API__ >= 21
#include <syslog.h>
extern "C" void android_set_abort_message(const char* msg);
#else
#include <assert.h>
#endif // __ANDROID_API__ >= 21
# include <android/api-level.h>
# if __ANDROID_API__ >= 21
# include <syslog.h>
extern "C" void android_set_abort_message(const char* msg);
# else
# include <assert.h>
# endif // __ANDROID_API__ >= 21
#endif // __BIONIC__

#ifdef __APPLE__
# if defined(__has_include) && __has_include(<CrashReporterClient.h>)
# define HAVE_CRASHREPORTERCLIENT_H
# include <CrashReporterClient.h>
# endif
#if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
# include <CrashReporterClient.h>
# define _LIBCXXABI_USE_CRASHREPORTER_CLIENT
#endif

void abort_message(const char* format, ...)
{
// write message to stderr
// Write message to stderr. We do this before formatting into a
// variable-size buffer so that we still get some information if
// formatting into the variable-sized buffer fails.
#if !defined(NDEBUG) || !defined(LIBCXXABI_BAREMETAL)
#ifdef __APPLE__
fprintf(stderr, "libc++abi.dylib: ");
#endif
{
#if defined(__EMSCRIPTEN__) && defined(NDEBUG)
// Just trap in a non-debug build. These internal libcxxabi assertions are
// very rare, and it's not worth linking in vfprintf stdio support or
// even minimal logging for them, as we'll have a proper call stack, which
// will show a call into "abort_message", and can help debugging. (In a
// debug build that won't be inlined.)
__builtin_trap();
// Just trap in a non-debug build. These internal libcxxabi assertions are
// very rare, and it's not worth linking in vfprintf stdio support or
// even minimal logging for them, as we'll have a proper call stack, which
// will show a call into "abort_message", and can help debugging. (In a
// debug build that won't be inlined.)
__builtin_trap();
#else
fprintf(stderr, "libc++abi: ");
va_list list;
va_start(list, format);
vfprintf(stderr, format, list);
va_end(list);
fprintf(stderr, "\n");
#endif
}
#endif

// Format the arguments into an allocated buffer. We leak the buffer on
// purpose, since we're about to abort() anyway.
#if defined(_LIBCXXABI_USE_CRASHREPORTER_CLIENT)
char* buffer;
va_list list;
va_start(list, format);
vfprintf(stderr, format, list);
vasprintf(&buffer, format, list);
va_end(list);
fprintf(stderr, "\n");
#endif // EMSCRIPTEN
#endif

#if defined(__APPLE__) && defined(HAVE_CRASHREPORTERCLIENT_H)
// record message in crash report
char* buffer;
va_list list2;
va_start(list2, format);
vasprintf(&buffer, format, list2);
va_end(list2);
CRSetCrashLogMessage(buffer);
#elif defined(__BIONIC__)
char* buffer;
va_list list2;
va_start(list2, format);
vasprintf(&buffer, format, list2);
va_end(list2);
va_list list;
va_start(list, format);
vasprintf(&buffer, format, list);
va_end(list);

#if __ANDROID_API__ >= 21
# if __ANDROID_API__ >= 21
// Show error in tombstone.
android_set_abort_message(buffer);

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

abort();
Expand Down
Loading