feat(wasm): link libsetjmp, so setjmp needs no flag
All checks were successful
Flatpak / flatpak (push) Successful in 17m58s

-mllvm -wasm-enable-sjlj, in every wasm compile because setjmp.h does
not compile without it, turns setjmp and longjmp into calls to
__wasm_setjmp, __wasm_setjmp_test and __wasm_longjmp and a throw of
the __c_longjmp tag, all of which live in wasi-libc's libsetjmp. The
driver does not link it, so a program that used setjmp, or a C library
that handles its errors that way, failed to link with undefined
__wasm_setjmp until the project put -lsetjmp in its linkFlags.

Build() adds it to every wasm link, next to -lunwind. A static archive
contributes only the members something references, so a program
without setjmp gets nothing from it, and every sysroot that passes the
exception check ships it. WasmExceptions drops its own -lsetjmp, and
its C fixture now fails to link without this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jorijn van der Graaf 2026-10-31 06:29:52 +01:00
commit 70ff11d0a1
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
3 changed files with 10 additions and 7 deletions

View file

@ -1208,9 +1208,14 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
}
// Code built with -fwasm-exceptions calls into libunwind (the
// __cpp_exception tag, the landing-pad context, _Unwind_RaiseException),
// and the driver does not add it to the link the way it adds libc++.
// and -wasm-enable-sjlj turns setjmp and longjmp into calls into
// wasi-libc's libsetjmp (__wasm_setjmp, __wasm_longjmp, the __c_longjmp
// tag). The driver adds neither to the link the way it adds libc++. A
// static archive contributes only what something references, so a
// program without setjmp gets nothing from libsetjmp, and every sysroot
// that passes WasmBuildError ships both.
if (isWasm) {
linkExtras += " -lunwind";
linkExtras += " -lunwind -lsetjmp";
}
// Force a relink if the expected output is missing or older than any dep