Skip to content

Commit 3bd640c

Browse files
authored
Patches from emscripten 3.1.73 (#12)
This adds additional downstream changes to the branch, which were added after LLVM 18 update until now.
1 parent f0ef087 commit 3bd640c

File tree

10 files changed

+82
-39
lines changed

10 files changed

+82
-39
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ uptr GetPageSize() {
12511251
# endif // !SANITIZER_ANDROID
12521252

12531253
# if SANITIZER_EMSCRIPTEN
1254-
extern "C" uptr emscripten_get_module_name(char *buf, uptr buf_len);
1254+
extern "C" void _emscripten_get_progname(char *buf, int buf_len);
12551255
# endif
12561256

12571257
uptr ReadBinaryName(/*out*/ char *buf, uptr buf_len) {
@@ -1260,7 +1260,8 @@ uptr ReadBinaryName(/*out*/ char *buf, uptr buf_len) {
12601260
CHECK_NE(default_module_name, NULL);
12611261
return internal_snprintf(buf, buf_len, "%s", default_module_name);
12621262
# elif SANITIZER_EMSCRIPTEN
1263-
return emscripten_get_module_name(buf, buf_len);
1263+
_emscripten_get_progname(buf, buf_len);
1264+
return internal_strlen(buf);
12641265
# else
12651266
# if SANITIZER_FREEBSD || SANITIZER_NETBSD
12661267
# if SANITIZER_FREEBSD

libcxxabi/include/cxxabi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ __cxa_init_primary_exception(void* object, std::type_info* tinfo, void(_LIBCXXAB
5858
// 2.4.3 Throwing the Exception Object
5959
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
6060
__cxa_throw(void *thrown_exception, std::type_info *tinfo,
61-
#ifdef __USING_WASM_EXCEPTIONS__
61+
#ifdef __wasm__
6262
void *(_LIBCXXABI_DTOR_FUNC *dest)(void *));
6363
#else
6464
void (_LIBCXXABI_DTOR_FUNC *dest)(void *));

libcxxabi/src/cxa_exception.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void __cxa_free_exception(void *thrown_object) throw() {
207207
}
208208

209209
__cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* tinfo,
210-
#ifdef __USING_WASM_EXCEPTIONS__
210+
#ifdef __wasm__
211211
// In Wasm, a destructor returns its argument
212212
void *(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw() {
213213
#else
@@ -272,14 +272,14 @@ will call terminate, assuming that there was no handler for the
272272
exception.
273273
*/
274274

275-
#if defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
275+
#if defined(__EMSCRIPTEN__) && defined(__WASM_EXCEPTIONS__) && !defined(NDEBUG)
276276
extern "C" {
277277
void __throw_exception_with_stack_trace(_Unwind_Exception*);
278278
} // extern "C"
279279
#endif
280280

281281
void
282-
#ifdef __USING_WASM_EXCEPTIONS__
282+
#ifdef __wasm__
283283
// In Wasm, a destructor returns its argument
284284
__cxa_throw(void *thrown_object, std::type_info *tinfo, void *(_LIBCXXABI_DTOR_FUNC *dest)(void *)) {
285285
#else
@@ -298,7 +298,7 @@ __cxa_throw(void *thrown_object, std::type_info *tinfo, void (_LIBCXXABI_DTOR_FU
298298

299299
#ifdef __USING_SJLJ_EXCEPTIONS__
300300
_Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
301-
#elif defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
301+
#elif defined(__EMSCRIPTEN__) && defined(__WASM_EXCEPTIONS__) && !defined(NDEBUG)
302302
// In debug mode, call a JS library function to use WebAssembly.Exception JS
303303
// API, which enables us to include stack traces
304304
__throw_exception_with_stack_trace(&exception_header->unwindHeader);
@@ -651,7 +651,7 @@ void __cxa_rethrow() {
651651
}
652652
#ifdef __USING_SJLJ_EXCEPTIONS__
653653
_Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
654-
#elif defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
654+
#elif defined(__EMSCRIPTEN__) && defined(__WASM_EXCEPTIONS__) && !defined(NDEBUG)
655655
// In debug mode, call a JS library function to use WebAssembly.Exception JS
656656
// API, which enables us to include stack traces
657657
__throw_exception_with_stack_trace(&exception_header->unwindHeader);
@@ -780,7 +780,7 @@ __cxa_rethrow_primary_exception(void* thrown_object)
780780
dep_exception_header->unwindHeader.exception_cleanup = dependent_exception_cleanup;
781781
#ifdef __USING_SJLJ_EXCEPTIONS__
782782
_Unwind_SjLj_RaiseException(&dep_exception_header->unwindHeader);
783-
#elif defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
783+
#elif defined(__EMSCRIPTEN__) && defined(__WASM_EXCEPTIONS__) && !defined(NDEBUG)
784784
// In debug mode, call a JS library function to use
785785
// WebAssembly.Exception JS API, which enables us to include stack
786786
// traces

libcxxabi/src/cxa_exception.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace __cxxabiv1 {
2121

22-
#ifdef __USING_EMSCRIPTEN_EXCEPTIONS__
22+
#ifdef __EMSCRIPTEN_EXCEPTIONS__
2323

2424
struct _LIBCXXABI_HIDDEN __cxa_exception {
2525
size_t referenceCount;
@@ -63,7 +63,7 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
6363

6464
// Manage the exception object itself.
6565
std::type_info *exceptionType;
66-
#ifdef __USING_WASM_EXCEPTIONS__
66+
#ifdef __wasm__
6767
// In Wasm, a destructor returns its argument
6868
void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
6969
#else
@@ -184,7 +184,7 @@ extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast ();
184184
extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception ();
185185
extern "C" _LIBCXXABI_FUNC_VIS void __cxa_free_dependent_exception (void * dependent_exception);
186186

187-
#endif // !__USING_EMSCRIPTEN_EXCEPTIONS__
187+
#endif // !__EMSCRIPTEN_EXCEPTIONS__
188188

189189
} // namespace __cxxabiv1
190190

libcxxabi/src/cxa_handlers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ __attribute__((noreturn))
7373
void
7474
terminate() noexcept
7575
{
76-
#if !defined(_LIBCXXABI_NO_EXCEPTIONS) && !defined(__USING_EMSCRIPTEN_EXCEPTIONS__)
76+
#if !defined(_LIBCXXABI_NO_EXCEPTIONS) && !defined(__EMSCRIPTEN_EXCEPTIONS__)
7777
// If there might be an uncaught exception
7878
using namespace __cxxabiv1;
7979
__cxa_eh_globals* globals = __cxa_get_globals_fast();

libcxxabi/src/cxa_noexception.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ void __cxa_free_exception(void *thrown_object) throw() {
7474
((char *)cxa_exception_from_thrown_object(thrown_object));
7575
free((void *)raw_buffer);
7676
}
77+
78+
// This function is called from make_exception_ptr in libcxx unless
79+
// -fno-exceptions is not given. We have definitions of this function in
80+
// cxa_exception.cpp and cxa_exception_emscripten.cpp, but unlike other
81+
// platforms, we use those files only when one of Emscripten EH or Wasm EH is
82+
// used, and we use this cxa_noexceptions.cpp in case of -fignore-exceptions,
83+
// which is our default. So we add a definition here to prevent a link failure.
84+
__cxa_exception*
85+
__cxa_init_primary_exception(void* object,
86+
std::type_info* tinfo,
87+
void*(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw() {
88+
__cxa_exception* exception_header = cxa_exception_from_thrown_object(object);
89+
return exception_header;
90+
}
7791
#endif
7892

7993
} // extern "C"

libcxxabi/src/cxa_personality.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extern "C" EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD,
7070
+------------------+--+-----+-----+------------------------+--------------------------+
7171
| callSiteTableLength | (ULEB128) | Call Site Table length, used to find Action table |
7272
+---------------------+-----------+---------------------------------------------------+
73-
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__)
73+
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__WASM_EXCEPTIONS__)
7474
+---------------------+-----------+------------------------------------------------+
7575
| Beginning of Call Site Table The current ip lies within the |
7676
| ... (start, length) range of one of these |
@@ -84,7 +84,7 @@ extern "C" EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD,
8484
| +-------------+---------------------------------+------------------------------+ |
8585
| ... |
8686
+----------------------------------------------------------------------------------+
87-
#else // __USING_SJLJ_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
87+
#else // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
8888
+---------------------+-----------+------------------------------------------------+
8989
| Beginning of Call Site Table The current ip is a 1-based index into |
9090
| ... this table. Or it is -1 meaning no |
@@ -97,7 +97,7 @@ extern "C" EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD,
9797
| +-------------+---------------------------------+------------------------------+ |
9898
| ... |
9999
+----------------------------------------------------------------------------------+
100-
#endif // __USING_SJLJ_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
100+
#endif // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
101101
+---------------------------------------------------------------------+
102102
| Beginning of Action Table ttypeIndex == 0 : cleanup |
103103
| ... ttypeIndex > 0 : catch |
@@ -547,7 +547,7 @@ void
547547
set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context,
548548
const scan_results& results)
549549
{
550-
#if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__USING_WASM_EXCEPTIONS__)
550+
#if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__WASM_EXCEPTIONS__)
551551
#define __builtin_eh_return_data_regno(regno) regno
552552
#elif defined(__ibmxl__)
553553
// IBM xlclang++ compiler does not support __builtin_eh_return_data_regno.
@@ -642,7 +642,7 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
642642
// Get beginning current frame's code (as defined by the
643643
// emitted dwarf code)
644644
uintptr_t funcStart = _Unwind_GetRegionStart(context);
645-
#if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__USING_WASM_EXCEPTIONS__)
645+
#if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__WASM_EXCEPTIONS__)
646646
if (ip == uintptr_t(-1))
647647
{
648648
// no action
@@ -652,9 +652,9 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
652652
else if (ip == 0)
653653
call_terminate(native_exception, unwind_exception);
654654
// ip is 1-based index into call site table
655-
#else // !__USING_SJLJ_EXCEPTIONS__ && !__USING_WASM_EXCEPTIONS__
655+
#else // !__USING_SJLJ_EXCEPTIONS__ && !__WASM_EXCEPTIONS__
656656
uintptr_t ipOffset = ip - funcStart;
657-
#endif // !__USING_SJLJ_EXCEPTIONS__ && !__USING_WASM_EXCEPTIONS__
657+
#endif // !__USING_SJLJ_EXCEPTIONS__ && !__WASM_EXCEPTIONS__
658658
const uint8_t* classInfo = NULL;
659659
// Note: See JITDwarfEmitter::EmitExceptionTable(...) for corresponding
660660
// dwarf emission
@@ -676,7 +676,7 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
676676
// Walk call-site table looking for range that
677677
// includes current PC.
678678
uint8_t callSiteEncoding = *lsda++;
679-
#if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__USING_WASM_EXCEPTIONS__)
679+
#if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__WASM_EXCEPTIONS__)
680680
(void)callSiteEncoding; // Unused when using SjLj/Wasm exceptions
681681
#endif
682682
uint32_t callSiteTableLength = static_cast<uint32_t>(readULEB128(&lsda));
@@ -687,33 +687,33 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
687687
while (callSitePtr < callSiteTableEnd)
688688
{
689689
// There is one entry per call site.
690-
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__)
690+
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__WASM_EXCEPTIONS__)
691691
// The call sites are non-overlapping in [start, start+length)
692692
// The call sites are ordered in increasing value of start
693693
uintptr_t start = readEncodedPointer(&callSitePtr, callSiteEncoding);
694694
uintptr_t length = readEncodedPointer(&callSitePtr, callSiteEncoding);
695695
uintptr_t landingPad = readEncodedPointer(&callSitePtr, callSiteEncoding);
696696
uintptr_t actionEntry = readULEB128(&callSitePtr);
697697
if ((start <= ipOffset) && (ipOffset < (start + length)))
698-
#else // __USING_SJLJ_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
698+
#else // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
699699
// ip is 1-based index into this table
700700
uintptr_t landingPad = readULEB128(&callSitePtr);
701701
uintptr_t actionEntry = readULEB128(&callSitePtr);
702702
if (--ip == 0)
703-
#endif // __USING_SJLJ_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
703+
#endif // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
704704
{
705705
// Found the call site containing ip.
706-
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__)
706+
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__WASM_EXCEPTIONS__)
707707
if (landingPad == 0)
708708
{
709709
// No handler here
710710
results.reason = _URC_CONTINUE_UNWIND;
711711
return;
712712
}
713713
landingPad = (uintptr_t)lpStart + landingPad;
714-
#else // __USING_SJLJ_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
714+
#else // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
715715
++landingPad;
716-
#endif // __USING_SJLJ_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
716+
#endif // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
717717
results.landingPad = landingPad;
718718
if (actionEntry == 0)
719719
{
@@ -841,15 +841,15 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
841841
action += actionOffset;
842842
} // there is no break out of this loop, only return
843843
}
844-
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__)
844+
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__WASM_EXCEPTIONS__)
845845
else if (ipOffset < start)
846846
{
847847
// There is no call site for this ip
848848
// Something bad has happened. We should never get here.
849849
// Possible stack corruption.
850850
call_terminate(native_exception, unwind_exception);
851851
}
852-
#endif // !__USING_SJLJ_EXCEPTIONS__ && !__USING_WASM_EXCEPTIONS__
852+
#endif // !__USING_SJLJ_EXCEPTIONS__ && !__WASM_EXCEPTIONS__
853853
} // there might be some tricky cases which break out of this loop
854854

855855
// It is possible that no eh table entry specify how to handle
@@ -906,7 +906,7 @@ _UA_CLEANUP_PHASE
906906
*/
907907

908908
#if !defined(_LIBCXXABI_ARM_EHABI)
909-
#ifdef __USING_WASM_EXCEPTIONS__
909+
#ifdef __WASM_EXCEPTIONS__
910910
_Unwind_Reason_Code __gxx_personality_wasm0
911911
#elif defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
912912
static _Unwind_Reason_Code __gxx_personality_imp
@@ -975,7 +975,7 @@ __gxx_personality_v0
975975
exc->languageSpecificData = results.languageSpecificData;
976976
exc->catchTemp = reinterpret_cast<void*>(results.landingPad);
977977
exc->adjustedPtr = results.adjustedPtr;
978-
#ifdef __USING_WASM_EXCEPTIONS__
978+
#ifdef __WASM_EXCEPTIONS__
979979
// Wasm only uses a single phase (_UA_SEARCH_PHASE), so save the
980980
// results here.
981981
set_registers(unwind_exception, context, results);

libcxxabi/src/private_typeinfo.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,10 +1530,16 @@ __base_class_type_info::search_below_dst(__dynamic_cast_info* info,
15301530
not_public_path,
15311531
use_strcmp);
15321532
}
1533+
} // __cxxabiv1
1534+
15331535

15341536
// XXX EMSCRIPTEN
1537+
#ifndef __WASM_EXCEPTIONS__
1538+
1539+
#include "cxa_exception.h"
15351540

1536-
#ifndef __USING_WASM_EXCEPTIONS__
1541+
namespace __cxxabiv1
1542+
{
15371543

15381544
// These functions are used by the emscripten-style exception handling
15391545
// mechanism.
@@ -1555,11 +1561,33 @@ int __cxa_can_catch(__shim_type_info* catchType, __shim_type_info* excpType, voi
15551561
return ret;
15561562
}
15571563

1558-
int __cxa_is_pointer_type(__shim_type_info* type) {
1559-
return !!dynamic_cast<__pointer_type_info*>(type);
1564+
static
1565+
inline
1566+
__cxa_exception*
1567+
cxa_exception_from_thrown_object(void* thrown_object)
1568+
{
1569+
return static_cast<__cxa_exception*>(thrown_object) - 1;
1570+
}
1571+
1572+
void *__cxa_get_exception_ptr(void *thrown_object) throw() {
1573+
// Get pointer which is expected to be received by catch clause in C++ code.
1574+
// It may be adjusted when the pointer is casted to some of the exception
1575+
// object base classes (e.g. when virtual inheritance is used). When a pointer
1576+
// is thrown this method should return the thrown pointer itself.
1577+
// Work around a fastcomp bug, this code is still included for some reason in
1578+
// a build without exceptions support.
1579+
__cxa_exception* ex = cxa_exception_from_thrown_object(thrown_object);
1580+
bool is_pointer = !!dynamic_cast<__pointer_type_info*>(ex->exceptionType);
1581+
if (is_pointer)
1582+
return *(void**)thrown_object;
1583+
if (ex->adjustedPtr)
1584+
return ex->adjustedPtr;
1585+
return ex;
15601586
}
15611587

15621588
}
1563-
#endif // __USING_EMSCRIPTEN_EXCEPTIONS__
15641589

15651590
} // __cxxabiv1
1591+
1592+
#endif // !__WASM_EXCEPTIONS__
1593+

libunwind/src/Unwind-wasm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "config.h"
1616

17-
#ifdef __USING_WASM_EXCEPTIONS__
17+
#ifdef __WASM_EXCEPTIONS__
1818

1919
#include "unwind.h"
2020
#include <threads.h>
@@ -120,4 +120,4 @@ _Unwind_GetRegionStart(struct _Unwind_Context *context) {
120120
return 0;
121121
}
122122

123-
#endif // defined(__USING_WASM_EXCEPTIONS__)
123+
#endif // defined(__WASM_EXCEPTIONS__)

libunwind/src/libunwind.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <sanitizer/asan_interface.h>
2727
#endif
2828

29-
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__)
29+
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__WASM_EXCEPTIONS__)
3030
#include "AddressSpace.hpp"
3131
#include "UnwindCursor.hpp"
3232

@@ -348,7 +348,7 @@ void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
348348

349349
#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
350350
#endif // !defined(__USING_SJLJ_EXCEPTIONS__) &&
351-
// !defined(__USING_WASM_EXCEPTIONS__)
351+
// !defined(__WASM_EXCEPTIONS__)
352352

353353
#ifdef __APPLE__
354354

0 commit comments

Comments
 (0)