Skip to content

AOT: fix localeCompare in hardened builds, and generators where loop polls do not fault - #1076

Merged
dylan-conway merged 2 commits into
mainfrom
claude/aot-hardened-locale-compare-and-loop-polls
Nov 18, 2026
Merged

dylan-conway merged 2 commits into
mainfrom
claude/aot-hardened-locale-compare-and-loop-polls

Conversation

@dylan-conway

@dylan-conway dylan-conway commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Fixes two crashes of ahead-of-time compiled programs.

localeCompare segfaults in hardened builds (x64 and arm64). The pointer to the known collation weights is set once the default collator exists, but it lay in the part of the instance that is made read-only at start. It now has a writable part of its own. The pointer to the table itself stays read-only.

"generator check failed" where loop polls do not fault (hardened arm64, FreeBSD). The straight emitter had no form for such a poll. So a generator with a loop had no body to go on in when a return that was replaced during a for of kept it. The poll is now a comparison and a call, as in walked code.

  • Slow bodies with simple loops are now written straight on these targets too, as on all others. Speed was not measured.
  • The abort remains on every target where a resume frame cannot be built for another reason.

What was run

Without LTO, arm64 under qemu with pointer authentication:

  • The three new tests fail before and pass after on hardened arm64. The localeCompare test does so on hardened x64 too.
  • Of 735 programs from Bun's test/aot/parallel on hardened arm64, 21 crashed before (13 and 8). None does now, and no other result changed.
  • Nothing was run on FreeBSD.

Generated by Claude Code

The pointer to the known weights changes once the default collator is made,
but it lay in a part of the instance that a hardened build makes read-only.
It now has a writable part of its own.
Without one, a generator with a loop had no body to go on in after its
consumer's loop had left it, and the program ended with "generator check
failed".
@dylan-conway
dylan-conway merged commit 0befb64 into main Nov 18, 2026
81 checks passed

@claude claude Bot 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.

I reviewed this PR and did not find any bugs. Because it changes the hardened Instance layout and adds a new loop-poll form to straight code (exercised only where polls do not fault), a human look from someone who knows the AOT emitters would still be worthwhile.

What was reviewed:

  • Every reader and writer of knownLevel1Weights (B3 loads in AOTStringEmitterComparisons.cpp, the stub offset in AOTStubsStrings.cpp, the init in AOTInstance.cpp, the write in operationAOTStringLocaleCompare) is repointed to the new mutable defaultCollator part; ducetLevel1Weights stays in the written-once collation part, and the 8-byte addition only shrinks unusedBelowWordsWrittenOnce.
  • The new non-faulting straight poll mirrors the walked emitCompareAndCall: same sign test on trapAwareSoftStackLimit (inverted), PollSlow's throws/terminates effects give the call a throw site through StraightEmitter::callOperation, and listing PollSlow in the mayFailToAllocate false-list matches the walked path's preserving stub (which also does not poll before returning) rather than skipping anything PollSlow would not do itself.
  • The straight path does not set pollLeavesOwedError; that matches the pre-existing faulting straight form, which never used the owed-error poll offset either, since straight code does not consult sweep marks.
  • Not done here: running the three new .ir answer tests or the hardened x64/arm64 lanes; the author's qemu results are the only evidence for the non-faulting path.
Extended reasoning...

The change is confined to Source/JavaScriptCore/aot under ENABLE(AOT): it moves one pointer out of the written-once Instance region into a new mutable part, repoints its four users, makes the straight emitter always claim LoopHint with a compare-and-call form for non-faulting polls, shares a new branchIfStopRequest helper, and adds three answer tests. It touches no injection, auth or data-exposure surface, but it does alter the memory-protection layout of hardened builds and the termination/poll path of compiled loops. The code is internally consistent with the walked-code poll and with how PollSlow handles owed errors, and no findings were reported with a dry_streak exit. Deferring rather than approving because it is JIT codegen and instance-layout work in a compiler, the new path runs only on hardened arm64 and FreeBSD, and /Source/JavaScriptCore is covered by a CODEOWNERS entry.

@github-actions

Copy link
Copy Markdown

Preview build of 2740b75: autobuild-preview-pr-1076-2740b753

dylan-conway added a commit to oven-sh/bun that referenced this pull request Nov 18, 2026
### What does this PR do?

Moves `WEBKIT_VERSION` from `a8d825d8a049` to `0befb64c5f30`, the head
of oven-sh/WebKit `main`. The release for that commit is published, with
every asset name of the previous one.

oven-sh/WebKit changes picked up:

- Build lto-hardened-aot-no-webassembly for Linux arm64
(oven-sh/WebKit#1073)
- [JSC] IsoCellSet::addSlow fences before storing a new bit set
(oven-sh/WebKit#1075)
- AOT: fix localeCompare in hardened builds, and generators where loop
polls do not fault (oven-sh/WebKit#1076)

### How did you verify your code works?

A debug build on Linux x64, with WebKit compiled from that commit,
reports it in `process.versions.webkit`. It passes
`webkit-prebuilt-url.test.ts`, `internal-module-blob.test.ts`,
`bun-jsc.test.ts`, `test/js/bun/gc/` and 20 programs of
`test/aot/parallel` that use `localeCompare` or loop over generators.

The prebuilt libraries and hardened builds were not run locally. CI is
their check. No test is added.

---
_Generated by [Claude Code](https://claude.ai/code)_

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant