Skip to content

Commit 4f1ce89

Browse files
committed
[libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm
The wasm unwind build appears to be dysfunctional, likely because the author has only supplied a customized LLVM build on request, rather than a fully functional patch. This patch fixes the build Apply formatting patch proposed by github bot use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined [libunwind] logAPI functions should also be built [libcxxabi] Fix function signatures for wasm wasm does not define the function signatures correctly for cxxabi Fix them Fix formatting issues for libcxxabi's wasm eh change Merge remote-tracking branch 'parent/main' into wasmlibunwindfix remove unwanted changes in unwind-wasm.c Make Unwind-wasm.c compile correctly without workaround in CMakeLists.txt using __wasm__ macro to guard against all wasm eh build fix UnwindLevel.c's formatting issue ISO C requires a translation unit to contain at least one declaration [-Werror,-Wempty-translation-unit] compiler-rt does not define CMP_RESULT correct on wasm64 Fixed Merge code
1 parent 8917afa commit 4f1ce89

File tree

14 files changed

+423
-543
lines changed

14 files changed

+423
-543
lines changed

compiler-rt/lib/builtins/fp_compare_impl.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// functions. We need to ensure that the return value is sign-extended in the
1313
// same way as GCC expects (since otherwise GCC-generated __builtin_isinf
1414
// returns true for finite 128-bit floating-point numbers).
15-
#ifdef __aarch64__
15+
#if defined(__aarch64__) || defined(__wasm__)
1616
// AArch64 GCC overrides libgcc_cmp_return to use int instead of long.
1717
typedef int CMP_RESULT;
1818
#elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4

libcxx/include/__exception/exception_ptr.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,21 @@
2929

3030
namespace __cxxabiv1 {
3131

32+
# if defined(__wasm__)
33+
typedef void* (*__libcpp_exception_destructor_func)(void*);
34+
# elif defined(_WIN32)
35+
typedef void(__thiscall* __libcpp_exception_destructor_func)(void*);
36+
# else
37+
typedef void (*__libcpp_exception_destructor_func)(void*);
38+
# endif
39+
3240
extern "C" {
3341
_LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
3442
_LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
3543

3644
struct __cxa_exception;
37-
_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
38-
void*,
39-
std::type_info*,
40-
# if defined(_WIN32)
41-
void(__thiscall*)(void*)) throw();
42-
# elif defined(__wasm__)
43-
// In Wasm, a destructor returns its argument
44-
void* (*)(void*)) throw();
45-
# else
46-
void (*)(void*)) throw();
47-
# endif
45+
_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception*
46+
__cxa_init_primary_exception(void*, std::type_info*, __libcpp_exception_destructor_func) throw();
4847
}
4948

5049
} // namespace __cxxabiv1

libcxxabi/include/cxxabi.h

Lines changed: 74 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -20,71 +20,59 @@
2020
#include <__cxxabi_config.h>
2121

2222
#define _LIBCPPABI_VERSION 15000
23-
#define _LIBCXXABI_NORETURN __attribute__((noreturn))
23+
#define _LIBCXXABI_NORETURN __attribute__((noreturn))
2424
#define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
2525

2626
#ifdef __cplusplus
2727

2828
namespace std {
29-
#if defined(_WIN32)
29+
# if defined(_WIN32)
3030
class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
31-
#else
31+
# else
3232
class type_info; // forward declaration
33-
#endif
34-
}
35-
33+
# endif
34+
} // namespace std
3635

3736
// runtime routines use C calling conventions, but are in __cxxabiv1 namespace
3837
namespace __cxxabiv1 {
3938

4039
struct __cxa_exception;
40+
# if defined(__wasm__)
41+
typedef void* (*__libcxxabi_exception_destructor_func)(void*);
42+
# else
43+
typedef void(_LIBCXXABI_DTOR_FUNC* __libcxxabi_exception_destructor_func)(void*);
44+
# endif
4145

42-
extern "C" {
46+
extern "C" {
4347

4448
// 2.4.2 Allocating the Exception Object
45-
extern _LIBCXXABI_FUNC_VIS void *
46-
__cxa_allocate_exception(size_t thrown_size) throw();
47-
extern _LIBCXXABI_FUNC_VIS void
48-
__cxa_free_exception(void *thrown_exception) throw();
49+
extern _LIBCXXABI_FUNC_VIS void* __cxa_allocate_exception(size_t thrown_size) throw();
50+
extern _LIBCXXABI_FUNC_VIS void __cxa_free_exception(void* thrown_exception) throw();
4951
// This function is an LLVM extension, which mirrors the same extension in libsupc++ and libcxxrt
50-
extern _LIBCXXABI_FUNC_VIS __cxa_exception*
51-
#ifdef __wasm__
52-
// In Wasm, a destructor returns its argument
53-
__cxa_init_primary_exception(void* object, std::type_info* tinfo, void*(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
54-
#else
55-
__cxa_init_primary_exception(void* object, std::type_info* tinfo, void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
56-
#endif
52+
extern _LIBCXXABI_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* tinfo,
53+
__libcxxabi_exception_destructor_func) throw();
5754

5855
// 2.4.3 Throwing the Exception Object
59-
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
60-
__cxa_throw(void *thrown_exception, std::type_info *tinfo,
61-
#ifdef __wasm__
62-
void *(_LIBCXXABI_DTOR_FUNC *dest)(void *));
63-
#else
64-
void (_LIBCXXABI_DTOR_FUNC *dest)(void *));
65-
#endif
56+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_throw(void* thrown_exception, std::type_info* tinfo,
57+
__libcxxabi_exception_destructor_func);
6658

6759
// 2.5.3 Exception Handlers
68-
extern _LIBCXXABI_FUNC_VIS void *
69-
__cxa_get_exception_ptr(void *exceptionObject) throw();
70-
extern _LIBCXXABI_FUNC_VIS void *
71-
__cxa_begin_catch(void *exceptionObject) throw();
60+
extern _LIBCXXABI_FUNC_VIS void* __cxa_get_exception_ptr(void* exceptionObject) throw();
61+
extern _LIBCXXABI_FUNC_VIS void* __cxa_begin_catch(void* exceptionObject) throw();
7262
extern _LIBCXXABI_FUNC_VIS void __cxa_end_catch();
73-
#if defined(_LIBCXXABI_ARM_EHABI)
74-
extern _LIBCXXABI_FUNC_VIS bool
75-
__cxa_begin_cleanup(void *exceptionObject) throw();
63+
# if defined(_LIBCXXABI_ARM_EHABI)
64+
extern _LIBCXXABI_FUNC_VIS bool __cxa_begin_cleanup(void* exceptionObject) throw();
7665
extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup();
77-
#endif
78-
extern _LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type();
66+
# endif
67+
extern _LIBCXXABI_FUNC_VIS std::type_info* __cxa_current_exception_type();
7968

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

8372
// 2.6 Auxiliary Runtime APIs
8473
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_bad_cast(void);
8574
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_bad_typeid(void);
86-
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
87-
__cxa_throw_bad_array_new_length(void);
75+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_throw_bad_array_new_length(void);
8876

8977
// 3.2.6 Pure Virtual Function API
9078
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_pure_virtual(void);
@@ -93,94 +81,75 @@ extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_pure_virtual(void);
9381
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_deleted_virtual(void);
9482

9583
// 3.3.2 One-time Construction API
96-
#if defined(_LIBCXXABI_GUARD_ABI_ARM)
97-
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint32_t *);
98-
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint32_t *);
99-
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint32_t *);
100-
#else
101-
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint64_t *);
102-
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint64_t *);
103-
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint64_t *);
104-
#endif
84+
# if defined(_LIBCXXABI_GUARD_ABI_ARM)
85+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint32_t*);
86+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint32_t*);
87+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint32_t*);
88+
# else
89+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint64_t*);
90+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint64_t*);
91+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint64_t*);
92+
# endif
10593

10694
// 3.3.3 Array Construction and Destruction API
107-
extern _LIBCXXABI_FUNC_VIS void *
108-
__cxa_vec_new(size_t element_count, size_t element_size, size_t padding_size,
109-
void (*constructor)(void *), void (*destructor)(void *));
110-
111-
extern _LIBCXXABI_FUNC_VIS void *
112-
__cxa_vec_new2(size_t element_count, size_t element_size, size_t padding_size,
113-
void (*constructor)(void *), void (*destructor)(void *),
114-
void *(*alloc)(size_t), void (*dealloc)(void *));
115-
116-
extern _LIBCXXABI_FUNC_VIS void *
117-
__cxa_vec_new3(size_t element_count, size_t element_size, size_t padding_size,
118-
void (*constructor)(void *), void (*destructor)(void *),
119-
void *(*alloc)(size_t), void (*dealloc)(void *, size_t));
120-
121-
extern _LIBCXXABI_FUNC_VIS void
122-
__cxa_vec_ctor(void *array_address, size_t element_count, size_t element_size,
123-
void (*constructor)(void *), void (*destructor)(void *));
124-
125-
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_dtor(void *array_address,
126-
size_t element_count,
127-
size_t element_size,
128-
void (*destructor)(void *));
129-
130-
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_cleanup(void *array_address,
131-
size_t element_count,
132-
size_t element_size,
133-
void (*destructor)(void *));
134-
135-
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete(void *array_address,
136-
size_t element_size,
137-
size_t padding_size,
138-
void (*destructor)(void *));
139-
140-
extern _LIBCXXABI_FUNC_VIS void
141-
__cxa_vec_delete2(void *array_address, size_t element_size, size_t padding_size,
142-
void (*destructor)(void *), void (*dealloc)(void *));
143-
144-
extern _LIBCXXABI_FUNC_VIS void
145-
__cxa_vec_delete3(void *__array_address, size_t element_size,
146-
size_t padding_size, void (*destructor)(void *),
147-
void (*dealloc)(void *, size_t));
148-
149-
extern _LIBCXXABI_FUNC_VIS void
150-
__cxa_vec_cctor(void *dest_array, void *src_array, size_t element_count,
151-
size_t element_size, void (*constructor)(void *, void *),
152-
void (*destructor)(void *));
95+
extern _LIBCXXABI_FUNC_VIS void* __cxa_vec_new(size_t element_count, size_t element_size, size_t padding_size,
96+
void (*constructor)(void*), void (*destructor)(void*));
97+
98+
extern _LIBCXXABI_FUNC_VIS void* __cxa_vec_new2(size_t element_count, size_t element_size, size_t padding_size,
99+
void (*constructor)(void*), void (*destructor)(void*),
100+
void* (*alloc)(size_t), void (*dealloc)(void*));
101+
102+
extern _LIBCXXABI_FUNC_VIS void* __cxa_vec_new3(size_t element_count, size_t element_size, size_t padding_size,
103+
void (*constructor)(void*), void (*destructor)(void*),
104+
void* (*alloc)(size_t), void (*dealloc)(void*, size_t));
105+
106+
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_ctor(void* array_address, size_t element_count, size_t element_size,
107+
void (*constructor)(void*), void (*destructor)(void*));
108+
109+
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_dtor(void* array_address, size_t element_count, size_t element_size,
110+
void (*destructor)(void*));
111+
112+
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_cleanup(void* array_address, size_t element_count, size_t element_size,
113+
void (*destructor)(void*));
114+
115+
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete(void* array_address, size_t element_size, size_t padding_size,
116+
void (*destructor)(void*));
117+
118+
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete2(void* array_address, size_t element_size, size_t padding_size,
119+
void (*destructor)(void*), void (*dealloc)(void*));
120+
121+
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete3(void* __array_address, size_t element_size, size_t padding_size,
122+
void (*destructor)(void*), void (*dealloc)(void*, size_t));
123+
124+
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_cctor(void* dest_array, void* src_array, size_t element_count,
125+
size_t element_size, void (*constructor)(void*, void*),
126+
void (*destructor)(void*));
153127

154128
// 3.3.5.3 Runtime API
155129
// These functions are part of the C++ ABI, but they are not defined in libc++abi:
156130
// int __cxa_atexit(void (*)(void *), void *, void *);
157131
// void __cxa_finalize(void *);
158132

159133
// 3.4 Demangler API
160-
extern _LIBCXXABI_FUNC_VIS char *__cxa_demangle(const char *mangled_name,
161-
char *output_buffer,
162-
size_t *length, int *status);
134+
extern _LIBCXXABI_FUNC_VIS char* __cxa_demangle(const char* mangled_name, char* output_buffer, size_t* length,
135+
int* status);
163136

164137
// Apple additions to support C++ 0x exception_ptr class
165138
// These are primitives to wrap a smart pointer around an exception object
166-
extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() throw();
167-
extern _LIBCXXABI_FUNC_VIS void
168-
__cxa_rethrow_primary_exception(void *primary_exception);
169-
extern _LIBCXXABI_FUNC_VIS void
170-
__cxa_increment_exception_refcount(void *primary_exception) throw();
171-
extern _LIBCXXABI_FUNC_VIS void
172-
__cxa_decrement_exception_refcount(void *primary_exception) throw();
139+
extern _LIBCXXABI_FUNC_VIS void* __cxa_current_primary_exception() throw();
140+
extern _LIBCXXABI_FUNC_VIS void __cxa_rethrow_primary_exception(void* primary_exception);
141+
extern _LIBCXXABI_FUNC_VIS void __cxa_increment_exception_refcount(void* primary_exception) throw();
142+
extern _LIBCXXABI_FUNC_VIS void __cxa_decrement_exception_refcount(void* primary_exception) throw();
173143

174144
// Apple extension to support std::uncaught_exception()
175145
extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() throw();
176146
extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() throw();
177147

178-
#if defined(__linux__) || defined(__Fuchsia__)
148+
# if defined(__linux__) || defined(__Fuchsia__)
179149
// Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI.
180150
// https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables
181-
extern _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*)(void *), void *,
182-
void *) throw();
183-
#endif
151+
extern _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*)(void*), void*, void*) throw();
152+
# endif
184153

185154
} // extern "C"
186155
} // namespace __cxxabiv1

0 commit comments

Comments
 (0)