Skip to content

Commit 3aeefe6

Browse files
authored
Merge downstream changes from Emscripten (#7)
1 parent b52556f commit 3aeefe6

12 files changed

+92
-62
lines changed

compiler-rt/emscripten_tempret.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
.section .globals,"",@
2+
13
.globaltype tempRet0, i32
24
tempRet0:
35

6+
.section .text,"",@
7+
48
.globl setTempRet0
59
setTempRet0:
610
.functype setTempRet0 (i32) -> ()

compiler-rt/stack_limits.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616

1717
.globaltype __stack_pointer, PTR
1818

19+
.section .globals,"",@
20+
1921
# TODO(sbc): It would be nice if these we initialized directly
2022
# using PTR.const rather than using the `emscripten_stack_init`
2123
.globaltype __stack_end, PTR
2224
__stack_end:
2325
.globaltype __stack_base, PTR
2426
__stack_base:
2527

28+
.section .text,"",@
29+
2630
emscripten_stack_get_base:
2731
.functype emscripten_stack_get_base () -> (PTR)
2832
global.get __stack_base

libcxxabi/include/cxxabi.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,25 @@ extern "C" {
4040

4141
// 2.4.2 Allocating the Exception Object
4242
extern _LIBCXXABI_FUNC_VIS void *
43-
__cxa_allocate_exception(size_t thrown_size) _NOEXCEPT;
43+
__cxa_allocate_exception(size_t thrown_size) throw();
4444
extern _LIBCXXABI_FUNC_VIS void
45-
__cxa_free_exception(void *thrown_exception) _NOEXCEPT;
45+
__cxa_free_exception(void *thrown_exception) throw();
4646

4747
// 2.4.3 Throwing the Exception Object
4848
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
4949
__cxa_throw(void *thrown_exception, std::type_info *tinfo,
5050
#ifdef __USING_WASM_EXCEPTIONS__
51+
// In Wasm, a destructor returns its argument
5152
void *(_LIBCXXABI_DTOR_FUNC *dest)(void *));
5253
#else
5354
void (_LIBCXXABI_DTOR_FUNC *dest)(void *));
5455
#endif
5556

5657
// 2.5.3 Exception Handlers
5758
extern _LIBCXXABI_FUNC_VIS void *
58-
__cxa_get_exception_ptr(void *exceptionObject) _NOEXCEPT;
59+
__cxa_get_exception_ptr(void *exceptionObject) throw();
5960
extern _LIBCXXABI_FUNC_VIS void *
60-
__cxa_begin_catch(void *exceptionObject) _NOEXCEPT;
61+
__cxa_begin_catch(void *exceptionObject) throw();
6162
extern _LIBCXXABI_FUNC_VIS void __cxa_end_catch();
6263
#if defined(_LIBCXXABI_ARM_EHABI)
6364
extern _LIBCXXABI_FUNC_VIS bool
@@ -152,17 +153,17 @@ extern _LIBCXXABI_FUNC_VIS char *__cxa_demangle(const char *mangled_name,
152153

153154
// Apple additions to support C++ 0x exception_ptr class
154155
// These are primitives to wrap a smart pointer around an exception object
155-
extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() _NOEXCEPT;
156+
extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() throw();
156157
extern _LIBCXXABI_FUNC_VIS void
157158
__cxa_rethrow_primary_exception(void *primary_exception);
158159
extern _LIBCXXABI_FUNC_VIS void
159-
__cxa_increment_exception_refcount(void *primary_exception) _NOEXCEPT;
160+
__cxa_increment_exception_refcount(void *primary_exception) throw();
160161
extern _LIBCXXABI_FUNC_VIS void
161-
__cxa_decrement_exception_refcount(void *primary_exception) _NOEXCEPT;
162+
__cxa_decrement_exception_refcount(void *primary_exception) throw();
162163

163164
// Apple extension to support std::uncaught_exception()
164-
extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() _NOEXCEPT;
165-
extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() _NOEXCEPT;
165+
extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() throw();
166+
extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() throw();
166167

167168
#if defined(__linux__) || defined(__Fuchsia__)
168169
// Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI.

libcxxabi/src/cxa_exception.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ extern "C" {
180180
// object. Zero-fill the object. If memory can't be allocated, call
181181
// std::terminate. Return a pointer to the memory to be used for the
182182
// user's exception object.
183-
void *__cxa_allocate_exception(size_t thrown_size) _NOEXCEPT {
183+
void *__cxa_allocate_exception(size_t thrown_size) throw() {
184184
size_t actual_size = cxa_exception_size_from_exception_thrown_size(thrown_size);
185185

186186
// Allocate extra space before the __cxa_exception header to ensure the
@@ -198,7 +198,7 @@ void *__cxa_allocate_exception(size_t thrown_size) _NOEXCEPT {
198198

199199

200200
// Free a __cxa_exception object allocated with __cxa_allocate_exception.
201-
void __cxa_free_exception(void *thrown_object) _NOEXCEPT {
201+
void __cxa_free_exception(void *thrown_object) throw() {
202202
// Compute the size of the padding before the header.
203203
size_t header_offset = get_cxa_exception_offset();
204204
char *raw_buffer =
@@ -254,15 +254,15 @@ will call terminate, assuming that there was no handler for the
254254
exception.
255255
*/
256256

257-
#if defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
257+
#if defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
258258
extern "C" {
259259
void __throw_exception_with_stack_trace(_Unwind_Exception*);
260260
} // extern "C"
261261
#endif
262262

263263
void
264264
#ifdef __USING_WASM_EXCEPTIONS__
265-
// In wasm, destructors return their argument
265+
// In Wasm, a destructor returns its argument
266266
__cxa_throw(void *thrown_object, std::type_info *tinfo, void *(_LIBCXXABI_DTOR_FUNC *dest)(void *)) {
267267
#else
268268
__cxa_throw(void *thrown_object, std::type_info *tinfo, void (_LIBCXXABI_DTOR_FUNC *dest)(void *)) {
@@ -287,14 +287,10 @@ __cxa_throw(void *thrown_object, std::type_info *tinfo, void (_LIBCXXABI_DTOR_FU
287287

288288
#ifdef __USING_SJLJ_EXCEPTIONS__
289289
_Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
290-
#elif __USING_WASM_EXCEPTIONS__
291-
#ifdef NDEBUG
292-
_Unwind_RaiseException(&exception_header->unwindHeader);
293-
#else
290+
#elif defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
294291
// In debug mode, call a JS library function to use WebAssembly.Exception JS
295292
// API, which enables us to include stack traces
296293
__throw_exception_with_stack_trace(&exception_header->unwindHeader);
297-
#endif
298294
#else
299295
_Unwind_RaiseException(&exception_header->unwindHeader);
300296
#endif
@@ -312,7 +308,7 @@ The adjusted pointer is computed by the personality routine during phase 1
312308
313309
Requires: exception is native
314310
*/
315-
void *__cxa_get_exception_ptr(void *unwind_exception) _NOEXCEPT {
311+
void *__cxa_get_exception_ptr(void *unwind_exception) throw() {
316312
#if defined(_LIBCXXABI_ARM_EHABI)
317313
return reinterpret_cast<void*>(
318314
static_cast<_Unwind_Control_Block*>(unwind_exception)->barrier_cache.bitpattern[0]);
@@ -327,7 +323,7 @@ void *__cxa_get_exception_ptr(void *unwind_exception) _NOEXCEPT {
327323
The routine to be called before the cleanup. This will save __cxa_exception in
328324
__cxa_eh_globals, so that __cxa_end_cleanup() can recover later.
329325
*/
330-
bool __cxa_begin_cleanup(void *unwind_arg) _NOEXCEPT {
326+
bool __cxa_begin_cleanup(void *unwind_arg) throw() {
331327
_Unwind_Exception* unwind_exception = static_cast<_Unwind_Exception*>(unwind_arg);
332328
__cxa_eh_globals* globals = __cxa_get_globals();
333329
__cxa_exception* exception_header =
@@ -451,7 +447,7 @@ to terminate or unexpected during unwinding.
451447
_Unwind_Exception and return a pointer to that.
452448
*/
453449
void*
454-
__cxa_begin_catch(void* unwind_arg) _NOEXCEPT
450+
__cxa_begin_catch(void* unwind_arg) throw()
455451
{
456452
_Unwind_Exception* unwind_exception = static_cast<_Unwind_Exception*>(unwind_arg);
457453
bool native_exception = __isOurExceptionClass(unwind_exception);
@@ -644,6 +640,10 @@ void __cxa_rethrow() {
644640
}
645641
#ifdef __USING_SJLJ_EXCEPTIONS__
646642
_Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
643+
#elif defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
644+
// In debug mode, call a JS library function to use WebAssembly.Exception JS
645+
// API, which enables us to include stack traces
646+
__throw_exception_with_stack_trace(&exception_header->unwindHeader);
647647
#else
648648
_Unwind_RaiseException(&exception_header->unwindHeader);
649649
#endif
@@ -667,7 +667,7 @@ void __cxa_rethrow() {
667667
Requires: If thrown_object is not NULL, it is a native exception.
668668
*/
669669
void
670-
__cxa_increment_exception_refcount(void *thrown_object) _NOEXCEPT {
670+
__cxa_increment_exception_refcount(void *thrown_object) throw() {
671671
if (thrown_object != NULL )
672672
{
673673
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
@@ -684,7 +684,7 @@ __cxa_increment_exception_refcount(void *thrown_object) _NOEXCEPT {
684684
Requires: If thrown_object is not NULL, it is a native exception.
685685
*/
686686
_LIBCXXABI_NO_CFI
687-
void __cxa_decrement_exception_refcount(void *thrown_object) _NOEXCEPT {
687+
void __cxa_decrement_exception_refcount(void *thrown_object) throw() {
688688
if (thrown_object != NULL )
689689
{
690690
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
@@ -707,7 +707,7 @@ void __cxa_decrement_exception_refcount(void *thrown_object) _NOEXCEPT {
707707
been no exceptions thrown, ever, on this thread, we can return NULL without
708708
the need to allocate the exception-handling globals.
709709
*/
710-
void *__cxa_current_primary_exception() _NOEXCEPT {
710+
void *__cxa_current_primary_exception() throw() {
711711
// get the current exception
712712
__cxa_eh_globals* globals = __cxa_get_globals_fast();
713713
if (NULL == globals)
@@ -769,8 +769,13 @@ __cxa_rethrow_primary_exception(void* thrown_object)
769769
dep_exception_header->unwindHeader.exception_cleanup = dependent_exception_cleanup;
770770
#ifdef __USING_SJLJ_EXCEPTIONS__
771771
_Unwind_SjLj_RaiseException(&dep_exception_header->unwindHeader);
772+
#elif defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
773+
// In debug mode, call a JS library function to use
774+
// WebAssembly.Exception JS API, which enables us to include stack
775+
// traces
776+
__throw_exception_with_stack_trace(&exception_header->unwindHeader);
772777
#else
773-
_Unwind_RaiseException(&dep_exception_header->unwindHeader);
778+
_Unwind_RaiseException(&exception_header->unwindHeader);
774779
#endif
775780
// Some sort of unwinding error. Note that terminate is a handler.
776781
__cxa_begin_catch(&dep_exception_header->unwindHeader);
@@ -779,10 +784,10 @@ __cxa_rethrow_primary_exception(void* thrown_object)
779784
}
780785

781786
bool
782-
__cxa_uncaught_exception() _NOEXCEPT { return __cxa_uncaught_exceptions() != 0; }
787+
__cxa_uncaught_exception() throw() { return __cxa_uncaught_exceptions() != 0; }
783788

784789
unsigned int
785-
__cxa_uncaught_exceptions() _NOEXCEPT
790+
__cxa_uncaught_exceptions() throw()
786791
{
787792
// This does not report foreign exceptions in flight
788793
__cxa_eh_globals* globals = __cxa_get_globals_fast();

libcxxabi/src/cxa_exception.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
6464
// Manage the exception object itself.
6565
std::type_info *exceptionType;
6666
#ifdef __USING_WASM_EXCEPTIONS__
67-
// In wasm, destructors return their argument
67+
// In Wasm, a destructor returns its argument
6868
void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
6969
#else
7070
void (_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);

libcxxabi/src/cxa_exception_emscripten.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
#ifdef __EMSCRIPTEN__
15+
1416
#include "cxxabi.h"
1517
#include "cxa_exception.h"
1618
#include "include/atomic_support.h"
@@ -85,7 +87,7 @@ extern "C" {
8587
// object. Zero-fill the object. If memory can't be allocated, call
8688
// std::terminate. Return a pointer to the memory to be used for the
8789
// user's exception object.
88-
void *__cxa_allocate_exception(size_t thrown_size) _NOEXCEPT {
90+
void *__cxa_allocate_exception(size_t thrown_size) throw() {
8991
size_t actual_size = cxa_exception_size_from_exception_thrown_size(thrown_size);
9092

9193
char *raw_buffer =
@@ -100,7 +102,7 @@ void *__cxa_allocate_exception(size_t thrown_size) _NOEXCEPT {
100102

101103

102104
// Free a __cxa_exception object allocated with __cxa_allocate_exception.
103-
void __cxa_free_exception(void *thrown_object) _NOEXCEPT {
105+
void __cxa_free_exception(void *thrown_object) throw() {
104106
// Compute the size of the padding before the header.
105107
char *raw_buffer =
106108
((char *)cxa_exception_from_thrown_object(thrown_object));
@@ -115,7 +117,7 @@ void __cxa_free_exception(void *thrown_object) _NOEXCEPT {
115117
Requires: If thrown_object is not NULL, it is a native exception.
116118
*/
117119
void
118-
__cxa_increment_exception_refcount(void *thrown_object) _NOEXCEPT {
120+
__cxa_increment_exception_refcount(void *thrown_object) throw() {
119121
if (thrown_object != NULL )
120122
{
121123
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
@@ -133,7 +135,7 @@ __cxa_increment_exception_refcount(void *thrown_object) _NOEXCEPT {
133135
Requires: If thrown_object is not NULL, it is a native exception.
134136
*/
135137
_LIBCXXABI_NO_CFI
136-
void __cxa_decrement_exception_refcount(void *thrown_object) _NOEXCEPT {
138+
void __cxa_decrement_exception_refcount(void *thrown_object) throw() {
137139
if (thrown_object != NULL )
138140
{
139141
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
@@ -153,3 +155,5 @@ void __cxa_decrement_exception_refcount(void *thrown_object) _NOEXCEPT {
153155
} // extern "C"
154156

155157
} // abi
158+
159+
#endif // __EMSCRIPTEN__

libcxxabi/src/cxa_exception_js_utils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#ifdef __EMSCRIPTEN__
2+
13
#include "cxxabi.h"
24

35
#include "cxa_exception.h"
@@ -103,3 +105,5 @@ char* __get_exception_terminate_message(void* thrown_object) {
103105
} // extern "C"
104106

105107
} // namespace __cxxabiv1
108+
109+
#endif // __EMSCRIPTEN__

libcxxabi/src/cxa_noexception.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ __cxa_uncaught_exceptions() throw() { return 0; }
5454
// DISABLE_EXCEPTION_CATCHING is set but DISABLE_EXCEPTION_THROWING is not.
5555
// TODO(sbc): Perhaps just call std::terminate here. It could
5656
// just be some test code that needs updating.
57-
void *__cxa_allocate_exception(size_t thrown_size) _NOEXCEPT {
57+
void *__cxa_allocate_exception(size_t thrown_size) throw() {
5858
char* allocation = (char*)malloc(thrown_size + sizeof(__cxa_exception));
5959
return allocation + sizeof(__cxa_exception);
6060
}
@@ -68,7 +68,7 @@ cxa_exception_from_thrown_object(void* thrown_object)
6868
}
6969

7070
// Free a __cxa_exception object allocated with __cxa_allocate_exception.
71-
void __cxa_free_exception(void *thrown_object) _NOEXCEPT {
71+
void __cxa_free_exception(void *thrown_object) throw() {
7272
// Compute the size of the padding before the header.
7373
char *raw_buffer =
7474
((char *)cxa_exception_from_thrown_object(thrown_object));

0 commit comments

Comments
 (0)