[libc-commits] [libcxx] [libunwind] [lldb] [clang] [llvm] [libc] [libunwind] Fix build for wasm (PR #79667)
via libc-commits
libc-commits at lists.llvm.org
Fri Jan 26 15:58:51 PST 2024
https://github.com/trcrsired updated https://github.com/llvm/llvm-project/pull/79667
>From 39bc0171e7c07e367446dd1abdc56fd918013a9d Mon Sep 17 00:00:00 2001
From: trcrsired <uwgghhbcad at gmail.com>
Date: Fri, 26 Jan 2024 18:44:41 -0500
Subject: [PATCH 1/2] [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
---
libunwind/include/__libunwind_config.h | 1 +
libunwind/src/CMakeLists.txt | 53 +++++++++++++++-----------
libunwind/src/Unwind-wasm.c | 16 ++++----
libunwind/src/config.h | 2 +-
4 files changed, 40 insertions(+), 32 deletions(-)
diff --git a/libunwind/include/__libunwind_config.h b/libunwind/include/__libunwind_config.h
index 8db336b2d727ce7..75e00a75b7e04bf 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,6 +180,7 @@
#endif
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER \
_LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+# elif defined(__wasm__)
# else
# error "Unsupported architecture."
# endif
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 9c6f5d908b09454..cce76eea007f434 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -1,31 +1,38 @@
# Get sources
-set(LIBUNWIND_CXX_SOURCES
- libunwind.cpp
- Unwind-EHABI.cpp
- Unwind-seh.cpp
- )
+if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "wasm32" OR
+ ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "wasm64")
+ set(LIBUNWIND_C_SOURCES
+ Unwind-wasm.c
+ )
+else()
+ set(LIBUNWIND_CXX_SOURCES
+ libunwind.cpp
+ Unwind-EHABI.cpp
+ Unwind-seh.cpp
+ )
+
+ if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+ list(APPEND LIBUNWIND_CXX_SOURCES
+ Unwind_AIXExtras.cpp
+ )
+ endif()
-if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
- list(APPEND LIBUNWIND_CXX_SOURCES
- Unwind_AIXExtras.cpp
- )
-endif()
+ set(LIBUNWIND_C_SOURCES
+ UnwindLevel1.c
+ UnwindLevel1-gcc-ext.c
+ Unwind-sjlj.c
+ )
-set(LIBUNWIND_C_SOURCES
- UnwindLevel1.c
- UnwindLevel1-gcc-ext.c
- Unwind-sjlj.c
- Unwind-wasm.c
- )
-set_source_files_properties(${LIBUNWIND_C_SOURCES}
- PROPERTIES
- COMPILE_FLAGS "-std=c99")
+ set(LIBUNWIND_ASM_SOURCES
+ UnwindRegistersRestore.S
+ UnwindRegistersSave.S
+ )
-set(LIBUNWIND_ASM_SOURCES
- UnwindRegistersRestore.S
- UnwindRegistersSave.S
- )
+ set_source_files_properties(${LIBUNWIND_C_SOURCES}
+ PROPERTIES
+ COMPILE_FLAGS "-std=c99")
+endif()
set(LIBUNWIND_HEADERS
AddressSpace.hpp
diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index f7f39d38b59c181..87be87e9fd92a86 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -10,14 +10,11 @@
//
//===----------------------------------------------------------------------===//
+#if __STDC_VERSION__ < 202311L
#include <stdbool.h>
-
+#endif
#include "config.h"
-
-#ifdef __USING_WASM_EXCEPTIONS__
-
#include "unwind.h"
-#include <threads.h>
_Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action actions,
uint64_t exceptionClass,
@@ -35,7 +32,12 @@ struct _Unwind_LandingPadContext {
// Communication channel between compiler-generated user code and personality
// function
-thread_local struct _Unwind_LandingPadContext __wasm_lpad_context;
+#if __STDC_VERSION__ >= 202311L
+thread_local
+#else
+_Thread_local
+#endif
+ struct _Unwind_LandingPadContext __wasm_lpad_context;
/// Calls to this function is in landing pads in compiler-generated user code.
/// In other EH schemes, stack unwinding is done by libunwind library, which
@@ -119,5 +121,3 @@ _LIBUNWIND_EXPORT uintptr_t
_Unwind_GetRegionStart(struct _Unwind_Context *context) {
return 0;
}
-
-#endif // defined(__USING_WASM_EXCEPTIONS__)
diff --git a/libunwind/src/config.h b/libunwind/src/config.h
index deb5a4d4d73d467..4cc32392aa72aff 100644
--- a/libunwind/src/config.h
+++ b/libunwind/src/config.h
@@ -66,7 +66,7 @@
#define _LIBUNWIND_EXPORT
#define _LIBUNWIND_HIDDEN
#else
- #if !defined(__ELF__) && !defined(__MACH__) && !defined(_AIX)
+ #if !defined(__ELF__) && !defined(__MACH__) && !defined(_AIX) && !defined(__wasm__)
#define _LIBUNWIND_EXPORT __declspec(dllexport)
#define _LIBUNWIND_HIDDEN
#else
>From 2a2d662dc1d831bc40133c7596eba44e058df1a8 Mon Sep 17 00:00:00 2001
From: trcrsired <uwgghhbcad at gmail.com>
Date: Fri, 26 Jan 2024 18:58:28 -0500
Subject: [PATCH 2/2] [libunwind] Apply formatting patch proposed by github
bot
---
libunwind/include/__libunwind_config.h | 2 +-
libunwind/src/config.h | 15 ++++++++-------
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/libunwind/include/__libunwind_config.h b/libunwind/include/__libunwind_config.h
index 75e00a75b7e04bf..1cda20d72255005 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,7 +180,7 @@
#endif
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER \
_LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
-# elif defined(__wasm__)
+#elif defined(__wasm__)
# else
# error "Unsupported architecture."
# endif
diff --git a/libunwind/src/config.h b/libunwind/src/config.h
index 4cc32392aa72aff..2a57df41acca9f7 100644
--- a/libunwind/src/config.h
+++ b/libunwind/src/config.h
@@ -66,13 +66,14 @@
#define _LIBUNWIND_EXPORT
#define _LIBUNWIND_HIDDEN
#else
- #if !defined(__ELF__) && !defined(__MACH__) && !defined(_AIX) && !defined(__wasm__)
- #define _LIBUNWIND_EXPORT __declspec(dllexport)
- #define _LIBUNWIND_HIDDEN
- #else
- #define _LIBUNWIND_EXPORT __attribute__((visibility("default")))
- #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden")))
- #endif
+#if !defined(__ELF__) && !defined(__MACH__) && !defined(_AIX) && \
+ !defined(__wasm__)
+#define _LIBUNWIND_EXPORT __declspec(dllexport)
+#define _LIBUNWIND_HIDDEN
+#else
+#define _LIBUNWIND_EXPORT __attribute__((visibility("default")))
+#define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden")))
+#endif
#endif
#define STR(a) #a
More information about the libc-commits
mailing list