Skip to content

build: add -flto for wasm32 to fix setjmp/longjmp with Emscripten#218

Open
Rawan10101 wants to merge 1 commit into
natecraddock:mainfrom
Rawan10101:main
Open

build: add -flto for wasm32 to fix setjmp/longjmp with Emscripten#218
Rawan10101 wants to merge 1 commit into
natecraddock:mainfrom
Rawan10101:main

Conversation

@Rawan10101

Copy link
Copy Markdown

When building Lua for wasm32 with Emscripten, WebAssembly does not natively support traditional setjmp/longjmp semantics. Emscripten implements support by applying compiler and linker transformations that rewrite and instrument setjmp/longjmp usage. But when Lua is compiled by Zig as a separate static library outside Emscripten's normal compilation pipeline. Without -flto, Zig compiles Lua's source files into object code that Emscripten cannot fully analyze or rewrite during the final link step which prevents the required setjmp/longjmp transformations from being applied correctly.

Adding -flto for the wasm32 build causes Zig to preserve LLVM IR in the generated artifacts. When emcc performs the final link, it can see inside the Lua code and apply its setjmp/longjmp instrumentation passes across the entire program.

Note: This issue was discovered while building Neovim for WebAssembly as part of the active Neovim wasm project: neovim/neovim#39987

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant