-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm #79667
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
Changes from all commits
2b52682
3b2f319
0272579
0b5f9a1
4fe695a
4165d2c
7c9c054
9cbf9c8
f4ce424
253d9cd
65c10aa
c2c2ec6
5e5bbf8
f1e8406
3747b5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,22 +29,21 @@ | |
|
|
||
| namespace __cxxabiv1 { | ||
|
|
||
| # if defined(__wasm__) | ||
| typedef void* (*__libcpp_exception_destructor_func)(void*); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could keep the existing comment here |
||
| # elif defined(_WIN32) | ||
| typedef void(__thiscall* __libcpp_exception_destructor_func)(void*); | ||
| # else | ||
| typedef void (*__libcpp_exception_destructor_func)(void*); | ||
| # endif | ||
|
|
||
| extern "C" { | ||
| _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw(); | ||
| _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw(); | ||
|
|
||
| struct __cxa_exception; | ||
| _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception( | ||
| void*, | ||
| std::type_info*, | ||
| # if defined(_WIN32) | ||
| void(__thiscall*)(void*)) throw(); | ||
| # elif defined(__wasm__) | ||
| // In Wasm, a destructor returns its argument | ||
| void* (*)(void*)) throw(); | ||
| # else | ||
| void (*)(void*)) throw(); | ||
| # endif | ||
| _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* | ||
| __cxa_init_primary_exception(void*, std::type_info*, __libcpp_exception_destructor_func) throw(); | ||
| } | ||
|
|
||
| } // namespace __cxxabiv1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,49 +20,41 @@ | |
| #include <__cxxabi_config.h> | ||
|
|
||
| #define _LIBCPPABI_VERSION 15000 | ||
| #define _LIBCXXABI_NORETURN __attribute__((noreturn)) | ||
| #define _LIBCXXABI_NORETURN __attribute__((noreturn)) | ||
| #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold)) | ||
|
|
||
| #ifdef __cplusplus | ||
|
|
||
| namespace std { | ||
| #if defined(_WIN32) | ||
| # if defined(_WIN32) | ||
| class _LIBCXXABI_TYPE_VIS type_info; // forward declaration | ||
| #else | ||
| # else | ||
| class type_info; // forward declaration | ||
| #endif | ||
| } | ||
|
|
||
| # endif | ||
| } // namespace std | ||
|
|
||
| // runtime routines use C calling conventions, but are in __cxxabiv1 namespace | ||
| namespace __cxxabiv1 { | ||
|
|
||
| struct __cxa_exception; | ||
| # if defined(__wasm__) | ||
| typedef void* (*__libcxxabi_exception_destructor_func)(void*); | ||
| # else | ||
| typedef void(_LIBCXXABI_DTOR_FUNC* __libcxxabi_exception_destructor_func)(void*); | ||
| # endif | ||
|
|
||
| extern "C" { | ||
| extern "C" { | ||
|
|
||
| // 2.4.2 Allocating the Exception Object | ||
| extern _LIBCXXABI_FUNC_VIS void * | ||
| __cxa_allocate_exception(size_t thrown_size) _LIBCXXABI_NOEXCEPT; | ||
| extern _LIBCXXABI_FUNC_VIS void | ||
| __cxa_free_exception(void *thrown_exception) _LIBCXXABI_NOEXCEPT; | ||
| extern _LIBCXXABI_FUNC_VIS void* __cxa_allocate_exception(size_t thrown_size) _LIBCXXABI_NOEXCEPT; | ||
| extern _LIBCXXABI_FUNC_VIS void __cxa_free_exception(void* thrown_exception) _LIBCXXABI_NOEXCEPT; | ||
| // This function is an LLVM extension, which mirrors the same extension in libsupc++ and libcxxrt | ||
| extern _LIBCXXABI_FUNC_VIS __cxa_exception* | ||
| #ifdef __wasm__ | ||
| // In Wasm, a destructor returns its argument | ||
| __cxa_init_primary_exception(void* object, std::type_info* tinfo, void*(_LIBCXXABI_DTOR_FUNC* dest)(void*)) _LIBCXXABI_NOEXCEPT; | ||
| #else | ||
| __cxa_init_primary_exception(void* object, std::type_info* tinfo, void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) _LIBCXXABI_NOEXCEPT; | ||
| #endif | ||
| extern _LIBCXXABI_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* tinfo, | ||
| __libcxxabi_exception_destructor_func) _LIBCXXABI_NOEXCEPT; | ||
|
|
||
| // 2.4.3 Throwing the Exception Object | ||
| extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void | ||
| __cxa_throw(void *thrown_exception, std::type_info *tinfo, | ||
| #ifdef __wasm__ | ||
| void *(_LIBCXXABI_DTOR_FUNC *dest)(void *)); | ||
| #else | ||
| void (_LIBCXXABI_DTOR_FUNC *dest)(void *)); | ||
| #endif | ||
| extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_throw(void* thrown_exception, std::type_info* tinfo, | ||
| __libcxxabi_exception_destructor_func); | ||
|
|
||
| // 2.5.3 Exception Handlers | ||
| extern _LIBCXXABI_FUNC_VIS void * | ||
|
|
@@ -74,8 +66,8 @@ extern _LIBCXXABI_FUNC_VIS void __cxa_end_catch(); | |
| extern _LIBCXXABI_FUNC_VIS bool | ||
| __cxa_begin_cleanup(void *exceptionObject) _LIBCXXABI_NOEXCEPT; | ||
| extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup(); | ||
| #endif | ||
| extern _LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type(); | ||
| # 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 | ||
|
|
@@ -88,8 +80,7 @@ extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_rethrow(); | |
| // 2.6 Auxiliary Runtime APIs | ||
| extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_bad_cast(void); | ||
| extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_bad_typeid(void); | ||
| extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void | ||
| __cxa_throw_bad_array_new_length(void); | ||
| extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_throw_bad_array_new_length(void); | ||
|
|
||
| // 3.2.6 Pure Virtual Function API | ||
| extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_pure_virtual(void); | ||
|
|
@@ -98,73 +89,58 @@ extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_pure_virtual(void); | |
| 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 _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 _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 | ||
| # if defined(_LIBCXXABI_GUARD_ABI_ARM) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a lot of formatting changes here that make this hard to review - could you commit the clang-format changes first and then rebase this PR on top? |
||
| 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 _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 | ||
| extern _LIBCXXABI_FUNC_VIS void * | ||
| __cxa_vec_new(size_t element_count, size_t element_size, size_t padding_size, | ||
| void (*constructor)(void *), void (*destructor)(void *)); | ||
| extern _LIBCXXABI_FUNC_VIS void* __cxa_vec_new(size_t element_count, size_t element_size, size_t padding_size, | ||
| void (*constructor)(void*), void (*destructor)(void*)); | ||
|
|
||
| extern _LIBCXXABI_FUNC_VIS void * | ||
| __cxa_vec_new2(size_t element_count, size_t element_size, size_t padding_size, | ||
| void (*constructor)(void *), void (*destructor)(void *), | ||
| void *(*alloc)(size_t), void (*dealloc)(void *)); | ||
| extern _LIBCXXABI_FUNC_VIS void* __cxa_vec_new2(size_t element_count, size_t element_size, size_t padding_size, | ||
| void (*constructor)(void*), void (*destructor)(void*), | ||
| void* (*alloc)(size_t), void (*dealloc)(void*)); | ||
|
|
||
| extern _LIBCXXABI_FUNC_VIS void * | ||
| __cxa_vec_new3(size_t element_count, size_t element_size, size_t padding_size, | ||
| void (*constructor)(void *), void (*destructor)(void *), | ||
| void *(*alloc)(size_t), void (*dealloc)(void *, size_t)); | ||
| extern _LIBCXXABI_FUNC_VIS void* __cxa_vec_new3(size_t element_count, size_t element_size, size_t padding_size, | ||
| void (*constructor)(void*), void (*destructor)(void*), | ||
| void* (*alloc)(size_t), void (*dealloc)(void*, size_t)); | ||
|
|
||
| extern _LIBCXXABI_FUNC_VIS void | ||
| __cxa_vec_ctor(void *array_address, size_t element_count, size_t element_size, | ||
| void (*constructor)(void *), void (*destructor)(void *)); | ||
| extern _LIBCXXABI_FUNC_VIS void __cxa_vec_ctor(void* array_address, size_t element_count, size_t element_size, | ||
| void (*constructor)(void*), void (*destructor)(void*)); | ||
|
|
||
| extern _LIBCXXABI_FUNC_VIS void __cxa_vec_dtor(void *array_address, | ||
| size_t element_count, | ||
| size_t element_size, | ||
| void (*destructor)(void *)); | ||
| extern _LIBCXXABI_FUNC_VIS void __cxa_vec_dtor(void* array_address, size_t element_count, size_t element_size, | ||
| void (*destructor)(void*)); | ||
|
|
||
| extern _LIBCXXABI_FUNC_VIS void __cxa_vec_cleanup(void *array_address, | ||
| size_t element_count, | ||
| size_t element_size, | ||
| void (*destructor)(void *)); | ||
| extern _LIBCXXABI_FUNC_VIS void __cxa_vec_cleanup(void* array_address, size_t element_count, size_t element_size, | ||
| void (*destructor)(void*)); | ||
|
|
||
| extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete(void *array_address, | ||
| size_t element_size, | ||
| size_t padding_size, | ||
| void (*destructor)(void *)); | ||
| extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete(void* array_address, size_t element_size, size_t padding_size, | ||
| void (*destructor)(void*)); | ||
|
|
||
| extern _LIBCXXABI_FUNC_VIS void | ||
| __cxa_vec_delete2(void *array_address, size_t element_size, size_t padding_size, | ||
| void (*destructor)(void *), void (*dealloc)(void *)); | ||
| extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete2(void* array_address, size_t element_size, size_t padding_size, | ||
| void (*destructor)(void*), void (*dealloc)(void*)); | ||
|
|
||
| extern _LIBCXXABI_FUNC_VIS void | ||
| __cxa_vec_delete3(void *__array_address, size_t element_size, | ||
| size_t padding_size, void (*destructor)(void *), | ||
| void (*dealloc)(void *, size_t)); | ||
| extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete3(void* __array_address, size_t element_size, size_t padding_size, | ||
| void (*destructor)(void*), void (*dealloc)(void*, size_t)); | ||
|
|
||
| extern _LIBCXXABI_FUNC_VIS void | ||
| __cxa_vec_cctor(void *dest_array, void *src_array, size_t element_count, | ||
| size_t element_size, void (*constructor)(void *, void *), | ||
| void (*destructor)(void *)); | ||
| extern _LIBCXXABI_FUNC_VIS void __cxa_vec_cctor(void* dest_array, void* src_array, size_t element_count, | ||
| size_t element_size, void (*constructor)(void*, void*), | ||
| void (*destructor)(void*)); | ||
|
|
||
| // 3.3.5.3 Runtime API | ||
| // 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, | ||
| char *output_buffer, | ||
| size_t *length, int *status); | ||
| extern _LIBCXXABI_FUNC_VIS char* __cxa_demangle(const char* mangled_name, char* output_buffer, size_t* length, | ||
| int* status); | ||
|
|
||
| // Apple additions to support C++ 0x exception_ptr class | ||
| // These are primitives to wrap a smart pointer around an exception object | ||
|
|
@@ -180,7 +156,7 @@ __cxa_decrement_exception_refcount(void *primary_exception) _LIBCXXABI_NOEXCEPT; | |
| extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() _LIBCXXABI_NOEXCEPT; | ||
| extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() _LIBCXXABI_NOEXCEPT; | ||
|
|
||
| #if defined(__linux__) || defined(__Fuchsia__) | ||
| # if defined(__linux__) || defined(__Fuchsia__) | ||
| // Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI. | ||
| // https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables | ||
| extern _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*)(void *), void *, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update the comment above to mention why WASM needs this too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, please leave an explicit comment here for WASM. When I ran into this issue it was really difficult to track down, so I really appreciate having explicit comments that show the rational for the special cases.