Skip to content

Conversation

@yerzham
Copy link

@yerzham yerzham commented Nov 17, 2025

Most minimal changes to enable libunwind to build for wasm by excluding __wasm__ from the Windows-style __declspec path in config.h and by recognizing wasm in assembly.h to skip the unsupported-target error. This unblocks building an exceptions-enabled wasi-sdk sysroot (see WebAssembly/wasi-sdk#565) and builds on prior attempts including yamt’s gist, #79667, and #140365.

@yerzham yerzham requested a review from a team as a code owner November 17, 2025 21:50
@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Nov 17, 2025

@llvm/pr-subscribers-libunwind

Author: Yerzhan Zhamashev (yerzham)

Changes

Most minimal changes to enable libunwind to build for wasm by excluding __wasm__ from the Windows-style __declspec path in config.h and by recognizing wasm in assembly.h to skip the unsupported-target error. This unblocks building an exceptions-enabled wasi-sdk sysroot (see WebAssembly/wasi-sdk#565) and builds on prior attempts including yamt’s gist, #79667, and #140365.


Full diff: https://github.com/llvm/llvm-project/pull/168449.diff

2 Files Affected:

  • (modified) libunwind/src/assembly.h (+2)
  • (modified) libunwind/src/config.h (+8-7)
diff --git a/libunwind/src/assembly.h b/libunwind/src/assembly.h index 84c9d526f1d75..9c35b6050a2bf 100644 --- a/libunwind/src/assembly.h +++ b/libunwind/src/assembly.h @@ -254,6 +254,8 @@ aliasname: \ #define NO_EXEC_STACK_DIRECTIVE // clang-format on +#elif defined(__wasm__) + #else #error Unsupported target diff --git a/libunwind/src/config.h b/libunwind/src/config.h index f017403fa2234..73162995f9293 100644 --- a/libunwind/src/config.h +++ b/libunwind/src/config.h @@ -75,13 +75,14 @@ #define _LIBUNWIND_EXPORT #define _LIBUNWIND_HIDDEN #else - #if !defined(__ELF__) && !defined(__MACH__) && !defined(_AIX) - #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 
@zyedidia
Copy link
Contributor

Compared to yamt's gist why do we not have #define NO_EXEC_STACK_DIRECTIVE this time? When I tried to use this patch to build an exceptions-enabled version of wasi-sdk (with your additional patch) I encountered a build error related to NO_EXEC_STACK_DIRECTIVE:

llvm-project/libunwind/src/UnwindRegistersRestore.S:1258:1: error: invalid instruction NO_EXEC_STACK_DIRECTIVE ^ 

After fixing that I then ran into the following errors when linking libc++abi.so:

wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_exception.cpp.o: undefined symbol: _Unwind_RaiseException wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_exception.cpp.o: undefined symbol: _Unwind_DeleteException wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_exception.cpp.o: undefined symbol: _Unwind_RaiseException wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_exception.cpp.o: undefined symbol: _Unwind_RaiseException wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_personality.cpp.o: undefined symbol: _Unwind_SetGR wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_personality.cpp.o: undefined symbol: _Unwind_SetGR wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_personality.cpp.o: undefined symbol: _Unwind_SetIP wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_personality.cpp.o: undefined symbol: _Unwind_GetLanguageSpecificData wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_personality.cpp.o: undefined symbol: _Unwind_GetIP wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_personality.cpp.o: undefined symbol: _Unwind_GetRegionStart wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_personality.cpp.o: undefined symbol: _Unwind_SetGR wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_personality.cpp.o: undefined symbol: _Unwind_SetGR wasm-ld: error: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_personality.cpp.o: undefined symbol: _Unwind_SetIP 

Are there further changes needed to fix this?

@yerzham
Copy link
Author

yerzham commented Nov 18, 2025

I needed to clarify wasi-sdk had to use latest version of src/llvm-project, at least I tested since v21.1.5. Otherwise, usage of NO_EXEC_STACK_DIRECTIVE in UnwindRegistersRestore.S should be gated out since #92192 (then some modification at #162581). I do not think NO_EXEC_STACK_DIRECTIVE is ever used for wasm target after that, so it would be an unused declaration. As for the consequent errors, probably still related to outdated llvm source?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants