fix(jit): SHEN_JIT=off switch + arm64/beta warning for boot SIGSEGV (#43) - #44
Merged
Conversation
…GV (#43) On aarch64, an old (2.1.0-beta3-era) LuaJIT mis-compiles one of the ~1500 traces generated while loading the kernel; the bad trace branches into unmapped memory and SIGSEGVs during boot. Reproduced on aarch64 Linux (OrbStack): 50/50 boots crash on the genuine v2.1.0-beta3 tag with the JIT on, 0/30 with it off. The same boot is clean 0/60 under a current 2.1 rolling release — this is a LuaJIT backend bug already fixed upstream, so the primary fix is to upgrade LuaJIT. For hosts pinned to an old LuaJIT, add an in-library mitigation: - SHEN_JIT=off -> jit.off() at boot (the equivalent of `luajit -j off`). Distinct from the existing SHEN_JIT_OPT=off, which only resets jit.opt and leaves the JIT on (so it never prevented the crash). - shen.boot{jit=false} -> the programmatic equivalent for embedders. - A one-time stderr warning on the exact risky combo (arm64 + a beta-versioned LuaJIT, JIT left on) pointing at both remedies; silenced by SHEN_JIT=on/off and never fires on a rolling build. test/jit_spec.lua drives a fresh LuaJIT per case and asserts, via jit.status(), that the switch reaches the JIT-off state while boot still evaluates; it skips cleanly on PUC Lua. README documents the crash, the upgrade-first fix, and the fallback switch. Co-Authored-By: Claude Fable 5 <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
Addresses #43 — the intermittent boot-time SIGSEGV under LuaJIT on aarch64.
I reproduced it on real aarch64 Linux (OrbStack) and root-caused it: an old (2.1.0-beta3-era) LuaJIT mis-compiles one of the ~1500 traces generated while loading the kernel; the bad trace branches into unmapped memory and faults. It is a LuaJIT backend bug, already fixed upstream — the identical kernel boot is clean under a current 2.1 rolling release.
SHEN_JIT=offgdb shows the fault PC landing just outside LuaJIT's executable mcode region with a corrupt stack — a compiled trace jumping to a bad target, not anything in shen-lua's C surface or the interpreter.
Changes
SHEN_JIT=off→jit.off()at boot (equivalent toluajit -j off). Distinct from the pre-existingSHEN_JIT_OPT=off, which only resetjit.optand left the JIT on (so it never prevented the crash).shen.boot{jit=false}→ the programmatic equivalent for embedders.SHEN_JIT=on/offand never fires on a rolling build.test/jit_spec.luadrives a fresh LuaJIT per case and asserts viajit.status()that the switch reaches the JIT-off state while boot still evaluates; skips cleanly on PUC Lua.Verification
test/jit_spec.lua: 11/11.🤖 Generated with Claude Code