Skip to content

Commit 04d9c98

Browse files
committed
[libunwind] Fix 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
1 parent 3bece3d commit 04d9c98

File tree

4 files changed

+47
-38
lines changed

4 files changed

+47
-38
lines changed

libunwind/include/__libunwind_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
#endif
181181
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER \
182182
_LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
183+
#elif defined(__wasm__)
183184
# else
184185
# error "Unsupported architecture."
185186
# endif

libunwind/src/CMakeLists.txt

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
# Get sources
22

3-
set(LIBUNWIND_CXX_SOURCES
4-
libunwind.cpp
5-
Unwind-EHABI.cpp
6-
Unwind-seh.cpp
7-
)
3+
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "wasm32" OR
4+
${CMAKE_SYSTEM_PROCESSOR} STREQUAL "wasm64")
5+
set(LIBUNWIND_C_SOURCES
6+
Unwind-wasm.c
7+
)
8+
else()
9+
set(LIBUNWIND_CXX_SOURCES
10+
libunwind.cpp
11+
Unwind-EHABI.cpp
12+
Unwind-seh.cpp
13+
)
14+
15+
if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
16+
list(APPEND LIBUNWIND_CXX_SOURCES
17+
Unwind_AIXExtras.cpp
18+
)
19+
endif()
820

9-
if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
10-
list(APPEND LIBUNWIND_CXX_SOURCES
11-
Unwind_AIXExtras.cpp
12-
)
13-
endif()
21+
set(LIBUNWIND_C_SOURCES
22+
UnwindLevel1.c
23+
UnwindLevel1-gcc-ext.c
24+
Unwind-sjlj.c
25+
)
1426

15-
set(LIBUNWIND_C_SOURCES
16-
UnwindLevel1.c
17-
UnwindLevel1-gcc-ext.c
18-
Unwind-sjlj.c
19-
Unwind-wasm.c
20-
)
21-
set_source_files_properties(${LIBUNWIND_C_SOURCES}
22-
PROPERTIES
23-
COMPILE_FLAGS "-std=c99")
27+
set(LIBUNWIND_ASM_SOURCES
28+
UnwindRegistersRestore.S
29+
UnwindRegistersSave.S
30+
)
2431

25-
set(LIBUNWIND_ASM_SOURCES
26-
UnwindRegistersRestore.S
27-
UnwindRegistersSave.S
28-
)
32+
set_source_files_properties(${LIBUNWIND_C_SOURCES}
33+
PROPERTIES
34+
COMPILE_FLAGS "-std=c99")
35+
endif()
2936

3037
set(LIBUNWIND_HEADERS
3138
AddressSpace.hpp

libunwind/src/Unwind-wasm.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if __STDC_VERSION__ < 202311L
1314
#include <stdbool.h>
14-
15+
#endif
1516
#include "config.h"
16-
17-
#ifdef __USING_WASM_EXCEPTIONS__
18-
1917
#include "unwind.h"
20-
#include <threads.h>
2118

2219
_Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action actions,
2320
uint64_t exceptionClass,
@@ -35,7 +32,12 @@ struct _Unwind_LandingPadContext {
3532

3633
// Communication channel between compiler-generated user code and personality
3734
// function
38-
thread_local struct _Unwind_LandingPadContext __wasm_lpad_context;
35+
#if __STDC_VERSION__ >= 202311L
36+
thread_local
37+
#else
38+
_Thread_local
39+
#endif
40+
struct _Unwind_LandingPadContext __wasm_lpad_context;
3941

4042
/// Calls to this function is in landing pads in compiler-generated user code.
4143
/// In other EH schemes, stack unwinding is done by libunwind library, which
@@ -119,5 +121,3 @@ _LIBUNWIND_EXPORT uintptr_t
119121
_Unwind_GetRegionStart(struct _Unwind_Context *context) {
120122
return 0;
121123
}
122-
123-
#endif // defined(__USING_WASM_EXCEPTIONS__)

libunwind/src/config.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@
6666
#define _LIBUNWIND_EXPORT
6767
#define _LIBUNWIND_HIDDEN
6868
#else
69-
#if !defined(__ELF__) && !defined(__MACH__) && !defined(_AIX)
70-
#define _LIBUNWIND_EXPORT __declspec(dllexport)
71-
#define _LIBUNWIND_HIDDEN
72-
#else
73-
#define _LIBUNWIND_EXPORT __attribute__((visibility("default")))
74-
#define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden")))
75-
#endif
69+
#if !defined(__ELF__) && !defined(__MACH__) && !defined(_AIX) && \
70+
!defined(__wasm__)
71+
#define _LIBUNWIND_EXPORT __declspec(dllexport)
72+
#define _LIBUNWIND_HIDDEN
73+
#else
74+
#define _LIBUNWIND_EXPORT __attribute__((visibility("default")))
75+
#define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden")))
76+
#endif
7677
#endif
7778

7879
#define STR(a) #a

0 commit comments

Comments
 (0)