Skip to content

Commit f6ff87d

Browse files
authored
[libunwind][WebAssembly] Make libunwind compilable (#92192)
This tries to make Wasm compilable in LLVM tree with CMake for non-Emscripten platform. This - Adds `-D__USING_WASM_EXCEPTIONS__` when you compile with `-fwasm-exceptions` (like other EH options) in Clang - Exclude `UnwindLevel1.c`, `UnwindRegistersSave.S`, and `UnwindRegistersRestore.S` when compiling with Wasm - Changed some `__USING_WASM_EXCEPTIONS__` to `__wasm__`; they should be applied when compiling with Wasm w/o exceptions. - Define some unused macros to make it compile Fixes #72771.
1 parent 0012b1e commit f6ff87d

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

libunwind/include/__libunwind_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@
180180
#endif
181181
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER \
182182
_LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
183+
#elif defined(__wasm__)
184+
// Unused
185+
#define _LIBUNWIND_CONTEXT_SIZE 0
186+
#define _LIBUNWIND_CURSOR_SIZE 0
183187
# else
184188
# error "Unsupported architecture."
185189
# endif

libunwind/src/UnwindLevel1.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
#include "libunwind_ext.h"
3232
#include "unwind.h"
3333

34-
#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)
34+
#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
35+
!defined(__wasm__)
3536

3637
#ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND
3738

libunwind/src/UnwindRegistersRestore.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
.text
2121
#endif
2222

23-
#if !defined(__USING_SJLJ_EXCEPTIONS__)
23+
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
2424

2525
#if defined(__i386__)
2626
DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)
@@ -1232,7 +1232,7 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind19Registers_loongarch6jumptoEv)
12321232

12331233
#endif
12341234

1235-
#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) */
1235+
#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) */
12361236

12371237
NO_EXEC_STACK_DIRECTIVE
12381238

libunwind/src/UnwindRegistersSave.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
.text
2121
#endif
2222

23-
#if !defined(__USING_SJLJ_EXCEPTIONS__)
23+
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
2424

2525
#if defined(__i386__)
2626

@@ -1177,6 +1177,6 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
11771177

11781178
WEAK_ALIAS(__unw_getcontext, unw_getcontext)
11791179

1180-
#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) */
1180+
#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) */
11811181

11821182
NO_EXEC_STACK_DIRECTIVE

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__)
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__)
352352

353353
#ifdef __APPLE__
354354

0 commit comments

Comments
 (0)