Skip to content

Sign macOS binaries with allow-jit - #63

Open
mokagio wants to merge 1 commit into
mainfrom
mokagio/macos-allow-jit-entitlement
Open

mokagio wants to merge 1 commit into
mainfrom
mokagio/macos-allow-jit-entitlement

Conversation

@mokagio

@mokagio mokagio commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Why

The macOS binaries are signed with the hardened runtime but no entitlements, and under those conditions Bun silently runs with its JIT off.

Nothing fails: the binary starts, notarizes, and passes smoke tests, so the signing checks never caught it.

This came up while setting up CLI signing for another Bun project.

Measured on the shipped 0.6.4 binaries, with a CPU-bound JavaScript loop:

Binary Time JIT
arm64, shipped ~1,690 ms off
arm64, this PR's build ~144 ms on
x64 under Rosetta, shipped ~1,500 ms off
x64 under Rosetta, this PR's build ~220 ms on

Impact

Startup doesn't change: --version, --help and chats --help take about 200 ms with or without the entitlement. So only CPU-heavy JavaScript gets faster, and most commands, which wait on I/O, may not change noticeably. I didn't time commands that talk to a server.

Tradeoff

allow-jit is the only entitlement added. Bun needs it to run its JIT, and the other hardened runtime protections stay on, including library validation and the block on unsigned executable memory. The cost is that a memory-corruption bug would have an easier route to running code. It seems a small added risk for a CLI that runs its own bundled code.

How to test

Build 17 built from source, then signed and notarized both architectures. From its downloaded release archives, both binaries have the entitlement, spctl reports Notarized Developer ID, and the JIT is on.

verify_code_signing fails on the shipped 0.6.4 binary, on one with the entitlement set to false, and on an ad-hoc signature.

packages/cli/scripts/sign-macos-binaries.ts got the same flag, but neither Buildkite nor my local runs exercise it.

To reproduce on a built or released binary:

bundle exec fastlane verify_code_signing binary:<path>
BUN_BE_BUN=1 <path> <script>   # `numberOfDFGCompiles` from `bun:jsc` returns 1000000 with the JIT off

Under the hardened runtime without this entitlement, Bun starts and passes smoke tests but runs with its JIT off.
On the shipped 0.6.4 arm64 binary, a CPU loop took about 1690 ms, against about 140 ms for the same bytes with the entitlement.
Startup is unaffected: `--version` and `--help` take about 200 ms either way.

`verify_code_signing` asserts the entitlement because nothing else would notice it going missing.

---

Generated with the help of Claude Code (Opus 5.5), https://code.claude.com
@mokagio mokagio self-assigned this Nov 3, 2026
@mokagio
mokagio marked this pull request as ready for review November 3, 2026 05:58
Copilot AI balanced review requested due to automatic review settings November 3, 2026 05:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the macOS signing change that enables Bun’s JIT.

No open issues 🎉

What changed in this PR

Enables Bun’s JIT in signed macOS CLI binaries by adding the allow-jit entitlement while retaining the hardened runtime’s other protections.

Changes:

  • Adds a shared entitlement file to both macOS signing paths.
  • Extends Fastlane verification to require the entitlement to be explicitly enabled.
  • Adds a patch changeset describing the CPU-heavy JavaScript performance improvement.
File Description
packages/​cli/​scripts/​sign-macos-binaries.ts Passes the shared entitlement file to codesign.
packages/​cli/​macos.entitlements Enables only com.apple.security.cs.allow-jit.
fastlane/​Fastfile Applies the entitlement during signing and verifies its value.
.changeset/​macos-allow-jit-entitlement.md Documents the signing fix in a patch release note.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants