fix: gate -lopfs.js behind pthreads to fix OPFS crash#360
Merged
adsharma merged 1 commit intoLadybugDB:mainfrom Apr 3, 2026
Merged
fix: gate -lopfs.js behind pthreads to fix OPFS crash#360adsharma merged 1 commit intoLadybugDB:mainfrom
adsharma merged 1 commit intoLadybugDB:mainfrom
Conversation
-lopfs.js internally uses _emscripten_proxy_finish, which is only defined when pthreads are enabled. Linking it without -pthread causes wasmfsOPFSProxyFinish to compile as a no-op, so at runtime the OPFS backend reads childType=0 and hits UNREACHABLE at opfs_backend.cpp:292. Move -lopfs.js and the OPFS exported functions inside the NOT __SINGLE_THREADED__ guard so they are only linked when -pthread is also present. The single-threaded browser build still gets WasmFS (in-memory) but no longer links the broken OPFS backend. Ref: LadybugDB#305 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes the OPFS
UNREACHABLEcrash atopfs_backend.cpp:292by ensuring-lopfs.jsis only linked when pthreads are enabled.-lopfs.jsand OPFS exported functions (_wasmfs_create_opfs_backend,_wasmfs_create_directory) inside theNOT __SINGLE_THREADED__guardRoot cause
-lopfs.jsis linked unconditionally in the browser WasmFS build (theelse()branch), but-pthreadis only added whenNOT __SINGLE_THREADED__. The Emscripten OPFS JS backend internally calls_emscripten_proxy_finish, which is only defined with pthreads. Without it,wasmfsOPFSProxyFinishcompiles as a no-op, so at runtime the OPFS backend readschildType=0and hits:What changes
CMakeLists.txt— In theBUILD_WASM/ browser-WasmFS branch:-lopfs.jslinked unconditionally-lopfs.jsonly linked whenNOT __SINGLE_THREADED__allocateUTF8always exportedallocateUTF8only exported when OPFS is availableThe companion JS-side fixes (WasmFS C API usage, runtime detection, OPFS tests) are already merged in ladybug-wasm — see commits
6305367andc495097.Test plan
SINGLE_THREADED=false): verify OPFS mounts and persists dataSINGLE_THREADED=true): verify build succeeds,mountOpfs()returns a clear error instead of crashingWASM_NODEFS=true): verify no regression (unaffected code path)BUILD_TESTS=true): verify no regression (NODERAWFS path)Ref: #305