Skip to content

Merge Emscripten downstream changes to emscripten-libs-16 #7

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
Oct 7, 2023
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
4 changes: 4 additions & 0 deletions compiler-rt/emscripten_tempret.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.section .globals,"",@

.globaltype tempRet0, i32
tempRet0:

.section .text,"",@

.globl setTempRet0
setTempRet0:
.functype setTempRet0 (i32) -> ()
Expand Down
4 changes: 4 additions & 0 deletions compiler-rt/stack_limits.S
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@

.globaltype __stack_pointer, PTR

.section .globals,"",@

# TODO(sbc): It would be nice if these we initialized directly
# using PTR.const rather than using the `emscripten_stack_init`
.globaltype __stack_end, PTR
__stack_end:
.globaltype __stack_base, PTR
__stack_base:

.section .text,"",@

emscripten_stack_get_base:
.functype emscripten_stack_get_base () -> (PTR)
global.get __stack_base
Expand Down
19 changes: 10 additions & 9 deletions libcxxabi/include/cxxabi.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,25 @@ extern "C" {

// 2.4.2 Allocating the Exception Object
extern _LIBCXXABI_FUNC_VIS void *
__cxa_allocate_exception(size_t thrown_size) _NOEXCEPT;
__cxa_allocate_exception(size_t thrown_size) throw();
extern _LIBCXXABI_FUNC_VIS void
__cxa_free_exception(void *thrown_exception) _NOEXCEPT;
__cxa_free_exception(void *thrown_exception) throw();

// 2.4.3 Throwing the Exception Object
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
__cxa_throw(void *thrown_exception, std::type_info *tinfo,
#ifdef __USING_WASM_EXCEPTIONS__
// In Wasm, a destructor returns its argument
void *(_LIBCXXABI_DTOR_FUNC *dest)(void *));
#else
void (_LIBCXXABI_DTOR_FUNC *dest)(void *));
#endif

// 2.5.3 Exception Handlers
extern _LIBCXXABI_FUNC_VIS void *
__cxa_get_exception_ptr(void *exceptionObject) _NOEXCEPT;
__cxa_get_exception_ptr(void *exceptionObject) throw();
extern _LIBCXXABI_FUNC_VIS void *
__cxa_begin_catch(void *exceptionObject) _NOEXCEPT;
__cxa_begin_catch(void *exceptionObject) throw();
extern _LIBCXXABI_FUNC_VIS void __cxa_end_catch();
#if defined(_LIBCXXABI_ARM_EHABI)
extern _LIBCXXABI_FUNC_VIS bool
Expand Down Expand Up @@ -152,17 +153,17 @@ extern _LIBCXXABI_FUNC_VIS char *__cxa_demangle(const char *mangled_name,

// Apple additions to support C++ 0x exception_ptr class
// These are primitives to wrap a smart pointer around an exception object
extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() _NOEXCEPT;
extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() throw();
extern _LIBCXXABI_FUNC_VIS void
__cxa_rethrow_primary_exception(void *primary_exception);
extern _LIBCXXABI_FUNC_VIS void
__cxa_increment_exception_refcount(void *primary_exception) _NOEXCEPT;
__cxa_increment_exception_refcount(void *primary_exception) throw();
extern _LIBCXXABI_FUNC_VIS void
__cxa_decrement_exception_refcount(void *primary_exception) _NOEXCEPT;
__cxa_decrement_exception_refcount(void *primary_exception) throw();

// Apple extension to support std::uncaught_exception()
extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() _NOEXCEPT;
extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() _NOEXCEPT;
extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() throw();
extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() throw();

#if defined(__linux__) || defined(__Fuchsia__)
// Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI.
Expand Down
41 changes: 23 additions & 18 deletions libcxxabi/src/cxa_exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ extern "C" {
// object. Zero-fill the object. If memory can't be allocated, call
// std::terminate. Return a pointer to the memory to be used for the
// user's exception object.
void *__cxa_allocate_exception(size_t thrown_size) _NOEXCEPT {
void *__cxa_allocate_exception(size_t thrown_size) throw() {
size_t actual_size = cxa_exception_size_from_exception_thrown_size(thrown_size);

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


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

#if defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
#if defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
extern "C" {
void __throw_exception_with_stack_trace(_Unwind_Exception*);
} // extern "C"
#endif

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

#ifdef __USING_SJLJ_EXCEPTIONS__
_Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
#elif __USING_WASM_EXCEPTIONS__
#ifdef NDEBUG
_Unwind_RaiseException(&exception_header->unwindHeader);
#else
#elif defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
// In debug mode, call a JS library function to use WebAssembly.Exception JS
// API, which enables us to include stack traces
__throw_exception_with_stack_trace(&exception_header->unwindHeader);
#endif
#else
_Unwind_RaiseException(&exception_header->unwindHeader);
#endif
Expand All @@ -312,7 +308,7 @@ The adjusted pointer is computed by the personality routine during phase 1

Requires: exception is native
*/
void *__cxa_get_exception_ptr(void *unwind_exception) _NOEXCEPT {
void *__cxa_get_exception_ptr(void *unwind_exception) throw() {
#if defined(_LIBCXXABI_ARM_EHABI)
return reinterpret_cast<void*>(
static_cast<_Unwind_Control_Block*>(unwind_exception)->barrier_cache.bitpattern[0]);
Expand All @@ -327,7 +323,7 @@ void *__cxa_get_exception_ptr(void *unwind_exception) _NOEXCEPT {
The routine to be called before the cleanup. This will save __cxa_exception in
__cxa_eh_globals, so that __cxa_end_cleanup() can recover later.
*/
bool __cxa_begin_cleanup(void *unwind_arg) _NOEXCEPT {
bool __cxa_begin_cleanup(void *unwind_arg) throw() {
_Unwind_Exception* unwind_exception = static_cast<_Unwind_Exception*>(unwind_arg);
__cxa_eh_globals* globals = __cxa_get_globals();
__cxa_exception* exception_header =
Expand Down Expand Up @@ -451,7 +447,7 @@ to terminate or unexpected during unwinding.
_Unwind_Exception and return a pointer to that.
*/
void*
__cxa_begin_catch(void* unwind_arg) _NOEXCEPT
__cxa_begin_catch(void* unwind_arg) throw()
{
_Unwind_Exception* unwind_exception = static_cast<_Unwind_Exception*>(unwind_arg);
bool native_exception = __isOurExceptionClass(unwind_exception);
Expand Down Expand Up @@ -644,6 +640,10 @@ void __cxa_rethrow() {
}
#ifdef __USING_SJLJ_EXCEPTIONS__
_Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
#elif defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
// In debug mode, call a JS library function to use WebAssembly.Exception JS
// API, which enables us to include stack traces
__throw_exception_with_stack_trace(&exception_header->unwindHeader);
#else
_Unwind_RaiseException(&exception_header->unwindHeader);
#endif
Expand All @@ -667,7 +667,7 @@ void __cxa_rethrow() {
Requires: If thrown_object is not NULL, it is a native exception.
*/
void
__cxa_increment_exception_refcount(void *thrown_object) _NOEXCEPT {
__cxa_increment_exception_refcount(void *thrown_object) throw() {
if (thrown_object != NULL )
{
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
Expand All @@ -684,7 +684,7 @@ __cxa_increment_exception_refcount(void *thrown_object) _NOEXCEPT {
Requires: If thrown_object is not NULL, it is a native exception.
*/
_LIBCXXABI_NO_CFI
void __cxa_decrement_exception_refcount(void *thrown_object) _NOEXCEPT {
void __cxa_decrement_exception_refcount(void *thrown_object) throw() {
if (thrown_object != NULL )
{
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
Expand All @@ -707,7 +707,7 @@ void __cxa_decrement_exception_refcount(void *thrown_object) _NOEXCEPT {
been no exceptions thrown, ever, on this thread, we can return NULL without
the need to allocate the exception-handling globals.
*/
void *__cxa_current_primary_exception() _NOEXCEPT {
void *__cxa_current_primary_exception() throw() {
// get the current exception
__cxa_eh_globals* globals = __cxa_get_globals_fast();
if (NULL == globals)
Expand Down Expand Up @@ -769,8 +769,13 @@ __cxa_rethrow_primary_exception(void* thrown_object)
dep_exception_header->unwindHeader.exception_cleanup = dependent_exception_cleanup;
#ifdef __USING_SJLJ_EXCEPTIONS__
_Unwind_SjLj_RaiseException(&dep_exception_header->unwindHeader);
#elif defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
// In debug mode, call a JS library function to use
// WebAssembly.Exception JS API, which enables us to include stack
// traces
__throw_exception_with_stack_trace(&exception_header->unwindHeader);
#else
_Unwind_RaiseException(&dep_exception_header->unwindHeader);
_Unwind_RaiseException(&exception_header->unwindHeader);
#endif
// Some sort of unwinding error. Note that terminate is a handler.
__cxa_begin_catch(&dep_exception_header->unwindHeader);
Expand All @@ -779,10 +784,10 @@ __cxa_rethrow_primary_exception(void* thrown_object)
}

bool
__cxa_uncaught_exception() _NOEXCEPT { return __cxa_uncaught_exceptions() != 0; }
__cxa_uncaught_exception() throw() { return __cxa_uncaught_exceptions() != 0; }

unsigned int
__cxa_uncaught_exceptions() _NOEXCEPT
__cxa_uncaught_exceptions() throw()
{
// This does not report foreign exceptions in flight
__cxa_eh_globals* globals = __cxa_get_globals_fast();
Expand Down
2 changes: 1 addition & 1 deletion libcxxabi/src/cxa_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
// Manage the exception object itself.
std::type_info *exceptionType;
#ifdef __USING_WASM_EXCEPTIONS__
// In wasm, destructors return their argument
// In Wasm, a destructor returns its argument
void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
#else
void (_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
Expand Down
12 changes: 8 additions & 4 deletions libcxxabi/src/cxa_exception_emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
//
//===----------------------------------------------------------------------===//

#ifdef __EMSCRIPTEN__

#include "cxxabi.h"
#include "cxa_exception.h"
#include "include/atomic_support.h"
Expand Down Expand Up @@ -85,7 +87,7 @@ extern "C" {
// object. Zero-fill the object. If memory can't be allocated, call
// std::terminate. Return a pointer to the memory to be used for the
// user's exception object.
void *__cxa_allocate_exception(size_t thrown_size) _NOEXCEPT {
void *__cxa_allocate_exception(size_t thrown_size) throw() {
size_t actual_size = cxa_exception_size_from_exception_thrown_size(thrown_size);

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


// Free a __cxa_exception object allocated with __cxa_allocate_exception.
void __cxa_free_exception(void *thrown_object) _NOEXCEPT {
void __cxa_free_exception(void *thrown_object) throw() {
// Compute the size of the padding before the header.
char *raw_buffer =
((char *)cxa_exception_from_thrown_object(thrown_object));
Expand All @@ -115,7 +117,7 @@ void __cxa_free_exception(void *thrown_object) _NOEXCEPT {
Requires: If thrown_object is not NULL, it is a native exception.
*/
void
__cxa_increment_exception_refcount(void *thrown_object) _NOEXCEPT {
__cxa_increment_exception_refcount(void *thrown_object) throw() {
if (thrown_object != NULL )
{
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
Expand All @@ -133,7 +135,7 @@ __cxa_increment_exception_refcount(void *thrown_object) _NOEXCEPT {
Requires: If thrown_object is not NULL, it is a native exception.
*/
_LIBCXXABI_NO_CFI
void __cxa_decrement_exception_refcount(void *thrown_object) _NOEXCEPT {
void __cxa_decrement_exception_refcount(void *thrown_object) throw() {
if (thrown_object != NULL )
{
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
Expand All @@ -153,3 +155,5 @@ void __cxa_decrement_exception_refcount(void *thrown_object) _NOEXCEPT {
} // extern "C"

} // abi

#endif // __EMSCRIPTEN__
4 changes: 4 additions & 0 deletions libcxxabi/src/cxa_exception_js_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef __EMSCRIPTEN__

#include "cxxabi.h"

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

} // namespace __cxxabiv1

#endif // __EMSCRIPTEN__
4 changes: 2 additions & 2 deletions libcxxabi/src/cxa_noexception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ __cxa_uncaught_exceptions() throw() { return 0; }
// DISABLE_EXCEPTION_CATCHING is set but DISABLE_EXCEPTION_THROWING is not.
// TODO(sbc): Perhaps just call std::terminate here. It could
// just be some test code that needs updating.
void *__cxa_allocate_exception(size_t thrown_size) _NOEXCEPT {
void *__cxa_allocate_exception(size_t thrown_size) throw() {
char* allocation = (char*)malloc(thrown_size + sizeof(__cxa_exception));
return allocation + sizeof(__cxa_exception);
}
Expand All @@ -68,7 +68,7 @@ cxa_exception_from_thrown_object(void* thrown_object)
}

// Free a __cxa_exception object allocated with __cxa_allocate_exception.
void __cxa_free_exception(void *thrown_object) _NOEXCEPT {
void __cxa_free_exception(void *thrown_object) throw() {
// Compute the size of the padding before the header.
char *raw_buffer =
((char *)cxa_exception_from_thrown_object(thrown_object));
Expand Down
Loading