Repository navigation
feat(catalyst): ship V8 with its JIT tiers on Mac Catalyst - #10
Open
edusperoni wants to merge 1 commit into
Open
edusperoni wants to merge 1 commit into
edusperoni wants to merge 1 commit into
Conversation
Catalyst was built as lite mode despite the build script saying otherwise: gni/v8.gni turns v8_enable_lite_mode on for every target_platform "iphoneos" build, and Catalyst is only a target_environment of that platform, so the archives shipped without Sparkplug, Maglev or TurboFan. Set it off explicitly for both Catalyst variants. A JIT build alone faults on Apple silicon: Catalyst compiles as iOS, so V8 uses its iOS JIT-memory model and writes MAP_JIT pages without macOS's per-thread W^X toggle (SIGBUS on the first code write, even with the allow-jit entitlement). v8_catalyst_jit_write_protect.patch gives Catalyst the macOS model: pthread_jit_write_protect_np around code writes (resolved with dlsym, since the SDK marks it unavailable on Catalyst) and the macOS code-range pre-commit. It is applied for iOS fetches and is a no-op outside Catalyst. Verified on an arm64 macabi probe linking the archives: hot JS runs ~35x faster than --jitless and --trace-opt reports optimized functions under ad-hoc signing, hardened runtime + allow-jit, and hardened runtime + allow-unsigned-executable-memory. Without either entitlement the JIT cannot map memory, so the runtime must pass --jitless there.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
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.
What
build-ios.sh: Catalyst variants now passv8_enable_lite_mode=false, so they ship Sparkplug, Maglev and TurboFan.patches/v8_catalyst_jit_write_protect.patch, applied byfetch.shfor iOS fetches, so V8's JIT works inside a Catalyst process.tests/apple-args.pyasserts the Catalyst arg; the README documents the patch and the arg.Why
Catalyst has been lite mode all along. The comment in
build-ios.shsays Catalyst is "deliberately not lite", butgni/v8.gniturnsv8_enable_lite_modeon for everytarget_platform="iphoneos"build, and Catalyst is only atarget_environmentof that platform. The shipped-7Catalystlibv8_compiler.ais ~1.5 KB,--trace-optreports nothing, and hot JS runs at--jitlessspeed.A JIT build alone crashes on Apple silicon. Catalyst compiles as iOS (
TARGET_OS_IPHONE), so V8 picks its iOS JIT-memory model, which assumesMAP_JITpages are writable and executable at once. A Catalyst process runs on macOS, whereMAP_JITpages are per-thread W^X, so the first JIT code write raises SIGBUS, even withcom.apple.security.cs.allow-jit. The patch gives Catalyst the macOS model:V8_HAS_PTHREAD_JIT_WRITE_PROTECTfor Catalyst arm64, soRwxMemoryWriteScopetogglespthread_jit_write_protect_np. The SDK marks that function unavailable on Catalyst, so it's resolved once withdlsym; libpthread on macOS exports it.Everything is gated on a new internal
V8_OS_MACCATALYST(set insrc/base/build_config.h, not in a public header), so device, simulator, tvOS and Android builds compile the same code as before.Verification
Local arm64 Catalyst build of 14.9.207.39 with the existing patches plus this one, linked into a small macabi probe that runs a hot loop and a regex:
--jitless--trace-optallow-jitallow-unsigned-executable-memoryWithout either entitlement the process can't map JIT memory, and V8 doesn't fall back on its own, so the iOS runtime passes
--jitlessin that case (companion runtime PR). Without the patch, all three JIT rows SIGBUS.python3 tests/apple-args.pypasses. x64-catalyst picks up the same arg; Intel Macs have no per-thread W^X, so the patch is a no-op there. I couldn't run that slice locally.Size
Stripped arm64 Catalyst
NativeScript.framework: 13.27 MB → 22.89 MB (+9.6 MB), about +2.7 MB zipped. This affects the Catalyst slice only.Release
The runtime consumes this through a tagged release (
v8-*), so it needs a tag after merge, e.g.v8-14.9.207.39-8.