build: add -flto for wasm32 to fix setjmp/longjmp with Emscripten#218
Open
Rawan10101 wants to merge 1 commit into
Open
build: add -flto for wasm32 to fix setjmp/longjmp with Emscripten#218Rawan10101 wants to merge 1 commit into
Rawan10101 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When building Lua for wasm32 with Emscripten, WebAssembly does not natively support traditional
setjmp/longjmpsemantics. Emscripten implements support by applying compiler and linker transformations that rewrite and instrumentsetjmp/longjmpusage. 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 requiredsetjmp/longjmptransformations from being applied correctly.Adding
-fltofor 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 itssetjmp/longjmpinstrumentation 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