Skip to content

[JSC] AOT: name the frame of a called built-in from static data - #939

Closed
robobun wants to merge 1 commit into
mainfrom
robobun/8def6551/aot-builtin-name-without-atom
Closed

robobun wants to merge 1 commit into
mainfrom
robobun/8def6551/aot-builtin-name-without-atom

Conversation

@robobun

@robobun robobun commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • A collection that writes out an error stack kills the process when it lists a built-in that compiled code called: SIGSEGV at address 0 in WTF::findAtomBeforeAdding below JSC::AOT::nameOfBuiltin.
  • nameOfBuiltin() (aot/runtime/AOTStackTrace.cpp:91) makes an Identifier for the name. Heap::pruneDeadReferences() sets the thread's atom table to null there.
  • A built-in under a symbol is listed as Symbol.match, not [Symbol.match].

Fix

  • nameOfBuiltin() takes no VM. The name comes from the host's row or from the new BuiltinTable::functionNameOf(), which reads only the table. AOTBuiltinCells.cpp and AOTNativeCallValidation.cpp use it too.
  • The %PrivateGlobals% arm, which read the first realm, is removed. Bun names its three require functions in rows: aot: name the functions that require calls in the table of built-ins bun#47293 lands first.
  • Verified: three new stack-traces tests, builtin-table/function-names-follow-keys, testaot all (7924 passed, 0 failed).
  • Self-reviewed: 7 concerns raised, 7 addressed (Notes).

Background

  • A called built-in: compiled code runs a step of Math.max itself, and the stack trace lists a frame for it.
  • An atom table holds a VM's unique strings. The thread that ends a collection has none.
  • A host row binds a table entry to native code and can name its frame.
  • Considered: install the atom table in ErrorInstance (Heap.cpp:1016 forbids the lookup), or change only the last line (a require() frame still crashes).

Downsides

  • A built-in frame allocates and frees one StringImpl (none before). StackFrame::appendTo runs 497 instructions for a max frame (736 before), 654 for [Symbol.match] (553 before).
  • Other frames cost the same. jsc text: +704 bytes (lto-aot lane, x64).
  • A Bun with this commit and without its rows lists requireCommonJS, not anonymous.
Notes

Landing order

  1. The three rows go onto Bun's main first (aot: name the functions that require calls in the table of built-ins bun#47293). They work on the engine that Bun has today: nameOfBuiltin() reads the name of a row before anything else.
  2. Then this commit.
  3. Then a Bun that pins it: the next pin of [JSC] AOT: handlers at the end of the stack, text constants in flow, samples in native code #934, or Upgrade to upstream WebKit e8f704815e94 #923 with Upgrade WebKit to e8f704815e94 bun#47112. Each needs the rows before its pin holds this commit. Without them, the test of aot: name the functions that require calls in the table of built-ins bun#47293 prints requireCommonJS where it holds anonymous.

How to see it

The test program of AOTStackTraceTests.cpp has three new functions: larger (Math.max(value, 2)), matches (pattern[Symbol.match](value) with a RegExp parameter) and classed (a conversion marked as a step of %PrivateGlobals%.toClass, which no front end makes). A script hands each an object whose valueOf/toString is a new function. That function throws an error, or calls Error.captureStackTrace on one. The script keeps the errors, drops the functions and calls fullGC().

main this commit
stack-traces/built-in-under-symbol prints Symbol.match [Symbol.match]
stack-traces/collection-writes-out-called-built-ins jsc dies of SIGSEGV passes
stack-traces/collection-writes-out-stack-of-dead-realm jsc dies of SIGSEGV passes

The first column is a build of this branch with the six engine files of main (at fe1e12e, before the rebase).

The binaries of the bun-webkit-linux-amd64-lto-aot lane, with a script that throws below Math.max and below [Symbol.match], drops the functions that threw and calls fullGC(). 20 runs with the default options and 20 with --useConcurrentGC=false:

exit code
main (8c6c963) 139 in 40 of 40 runs
this commit (a99e703) 0 in 40 of 40 runs

With the same lane binaries of this commit: testaot native stack-traces 11 passed, testaot all 7924 passed, 0 failed, 42 todo, 33 left out.

builtin-table/function-names-follow-keys calls functionNameOf() for every name of the table while the thread has no atom table. Then it compares each answer with the key of identifierOf(): the text, or [description] for a symbol.

Tools/Scripts/aot/check-unified-sources.py: 0 problems.

Costs

jsc of the lto-aot lane of each commit (x64). gdb steps through every call of JSC::StackFrame::appendTo while two stacks are written out, from the entry to the return.

one call of appendTo main (8c6c963) this commit (a99e703)
max frame 736 instructions, no allocation 497 instructions, 1 allocation, 1 free
[Symbol.match] frame 553 instructions, no allocation 654 instructions, 1 allocation, 1 free
the six other frames 813, 2848, 1903, 815, 2004, 805 813, 2848, 1903, 815, 2004, 805
  • The text name is a StringImpl that points at the characters of the table. The name under a symbol is built with makeString().
  • size jsc: text 54,004,060 to 54,004,764 bytes, data 616,444 both, bss 69,268 to 68,564. The sum is 54,689,772 for both.
  • nameOfBuiltin() is 288 bytes (518 before). functionNameOf() is 1,152 bytes.
  • nameOfBuiltin() is NEVER_INLINE. Without it (9568a5c) the link-time optimizer put it into its three callers, and those were no longer put in line themselves. A frame of compiled code then cost 25 instructions more (2848 to 2873, 2004 to 2029).

From the self-review

  1. The branch is rebased on main.
  2. "Landing order" says which Bun takes this commit first, and what it needs.
  3. A check of the row names in AOTBuiltinTableValidation.cpp is removed: no test could reach it.
  4. The text says that a frame under a symbol did not crash, since when a node:vm context reaches the crash in Bun, and that the dead-realm test is a state of the shell.
  5. The comment on nameOfBuiltin() and the comment of the dead-realm test speak of the frames of built-ins only.
  6. "Not in this change" lists the related defects.
  7. "Costs" has numbers for a text name and for a name under a symbol. The review proposed static text for the 15 well-known symbols. Both designs allocate one string for the frame, so the names stay built from the table.

The other callers of identifierOf()

BuiltinTable::identifierOf() has 31 other call sites, in 7 files: AOTBuiltinTableRealm.cpp (9), AOTBuiltinTableValidation.cpp (8), AOTBuiltinCells.cpp (6), AOTNativeCallValidation.cpp (3), AOTBuiltinLocationWatch.cpp (2), AOTTypedArrayOperations.cpp (1) and AOTProgramIdentifiers.cpp (1). nameOfBuiltin() reached the first file through findInRealm(), and that call is removed.

What the end of a collection runs in aot/:

  • the writing of a stack (AOTStackTrace.cpp, and functionName() of AOTFunctionTables.cpp). AOTStackTrace.cpp now makes no Identifier, and functionName() reads only the names that the VM already holds.
  • CacheRegistry::finalize(), which calls the removeDeadEntries() of each cache and PropertyCaches::didFinishCollection().
  • CollectionValidator::didFinishCollection().

The last two items are 17 functions. None of them calls identifierOf(), findInRealm() or another function of the 7 files.

Where Bun reaches it

Bun formats most stacks through its VM::onComputeErrorInfo() hook, which installs the atom table of the VM first (oven-sh/bun#17087). So the lookup works there. ErrorInstance::reconcileWeakReferencesAtGCEnd() asks no hook for the frames that the engine's own Error.captureStackTrace keeps. In canary 1.4.4-canary.1 a function of a node:vm context still has that function. A bun build --compile --aot executable in which such a function captures a stack below Math.max, or below require(), exits with Segmentation fault at address 0x0 at the next collection that finds a frame dead (3 of 3 runs each, bun run exits with 0). oven-sh/bun#42605 would give every realm Bun's Error.captureStackTrace. The jsc shell has no hook at all: Bun's test/aot/collector-stress found the crash there (oven-sh/bun#47112, build 134164).

The dead-realm test is a state that only a shell makes, which runs one image in several realms.

Not in this change

  • A frame of a class with a literal static displayName is named through functionName() (aot/object/AOTFunctionTables.cpp:577), which can fill the statics of the class at the end of a collection. The process aborts there on main and on this commit. It is another defect with another fix.
  • describeCodeAddresses() (aot/runtime/AOTStackTrace.cpp) names an inline frame of a called built-in with writtenFunctionName(), which has no such function. With nameOfBuiltin() free of the VM it can ask it.
  • A frame of a getter or a setter is listed under the name of the property. The function object is named get size.
  • A built-in that a program gives an own displayName is still listed under its first name.
  • BuiltinTable::mismatches() does not compare the name of a row with the function object. The test of aot: name the functions that require calls in the table of built-ins bun#47293 holds the three names.

@robobun

robobun commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status of this pull request

  • Reproduced on main with the jsc and testaot of the bun-webkit-linux-amd64-lto-aot lane. A compiled function runs Math.max(value, 2), and value.valueOf throws an error. The script keeps the error, drops the valueOf function and calls fullGC(). jsc exits with 139 in every run, with WTF::findAtomBeforeAdding below JSC::AOT::nameOfBuiltin on the stack.
  • With the lane binaries of this pull request (a99e703) the same script exits with 0 in 40 of 40 runs.
  • The companion change for Bun is aot: name the functions that require calls in the table of built-ins bun#47293. It lands first.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Preview build of a99e703: autobuild-preview-pr-939-a99e7036

A collection writes out the stack of an error at its end, where the
thread has no atom table. nameOfBuiltin() made an Identifier there to
read its characters, and the process died of SIGSEGV at address 0 in
WTF::findAtomBeforeAdding. Two kinds of frames died: a built-in under a
text name (`max`), and a function that the host keeps under a private
name, for which nameOfBuiltin() also read the global object of the
first realm.

nameOfBuiltin() now takes no VM. The name is the one in the row of the
host, or BuiltinTable::functionNameOf(), which reads only the characters
of the table. The arm for %PrivateGlobals% is removed: a host names
such a function in its row. nameOfBuiltin() stays out of line, so that
the three functions that call it stay small for a frame of compiled
code.

functionNameOf() also spells a name under a symbol as the function
object is named: `[Symbol.match]` under a well-known symbol, `[key]`
under a registered one. Such a frame did not crash. It was listed as
`Symbol.match`. The stand-in function of a missing host and the index
of native call validation take their names from functionNameOf() too.
@robobun
robobun force-pushed the robobun/8def6551/aot-builtin-name-without-atom branch from 9568a5c to a99e703 Compare October 29, 2026 05:29
@robobun
robobun marked this pull request as ready for review October 29, 2026 08:22

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Beyond the inline finding, I also checked two things that looked like behavior changes and ruled them out: the builtinsByFunctionName key for registered-symbol names moving from [Symbol.key] to [key] in AOTNativeCallValidation.cpp matches how JSC names a function keyed by a registered symbol (the old key could not have matched a native executable's .name), and functionNameOf branches on the same three name runs in the same order as identifierOf, so a nameless entry behaves as it did before.

Extended reasoning...

The change adds BuiltinTable::functionNameOf, which builds a built-in's function name from the table's static literals without an Identifier or VM, and routes nameOfBuiltin in AOTStackTrace.cpp, makeFunctionOfMissingHost and builtinsByFunctionName through it; it touches no security-sensitive surface. The new test statics are unique across aot/ and the IR entries named in the stack-trace tests exist in the stand-in host table. A confirmed inline finding about non-built-in frames still reaching functionName at GC end remains, which the PR itself lists as out of scope, so a human should weigh that.

if (isOfCalledBuiltin())
return nameOfBuiltin(vm, builtinOfFunctionInFrames(m_function));
return nameOfBuiltin(builtinOfFunctionInFrames(m_function));
return Image::current()->isObfuscated() ? emptyString() : functionName(vm, *this, NameForm::InFrames, callee ? asObject(callee) : nullptr, calleeLiesInFrame);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟣 pre-existing, not blocking: Processes still die at GC end when a dead error stack holds a compiled non-built-in frame, even though this change is sold as making collection-time stack writing safe. nameInFrames at Source/JavaScriptCore/aot/runtime/AOTStackTrace.cpp:129 only routes built-in frames through the new atom-free nameOfBuiltin; every other compiled frame still goes through functionName (aot/object/AOTFunctionTables.cpp:577), which can fill class statics and touch the realm on the collector thread. Fix: make the GC-end path safe for all frame kinds, for example by naming non-built-in frames from static data too or by deferring the name until a thread with an atom table runs. The new tests only cover built-in frames, so this population stays unprotected.
A small fix can ride a push you are already making; otherwise a short reply is enough.

Why this was flagged

A program whose error outlives a compiled function of a class with a literal static displayName and then has that function or realm collected reaches ErrorInstance::reconcileWeakReferencesAtGCEnd, which calls FunctionDescription::nameInFrames at Source/JavaScriptCore/aot/runtime/AOTStackTrace.cpp:127-131. Only the isOfCalledBuiltin branch at line 129 uses the new realm-free nameOfBuiltin; the else branch at line 131 still calls functionName, which aborts the process on main and on this commit. The population is every Bun --aot executable or jsc shell run where a thrown error from compiled code is kept past a collection, the same trigger the new tests exercise but with a class frame instead of a built-in. The base behaves the same, but the change widens the claim without covering this sibling frame kind; a remedy is to make the non-built-in branch at line 131 safe on the collector thread or to cover it with a test that fails.

Verification: Pre-existing. An ErrorInstance whose stack holds a compiled frame of a class with a static displayName is materialized at GC end via calculatedDisplayName (AOTStackTrace.cpp:132-137). Only the isOfCalledBuiltin() arm was changed; the else arm still calls functionName(vm, ...) (AOTFunctionTables.cpp:578), which fills statics on the collector thread at GC end. The base branch fails by the same route; merging makes nothing worse.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: fe43be19-304b-40c7-bcb4-61e151d2d495
Commits

Reviewing files that changed from the base of the PR and between 8c6c963 and a99e703.

Files selected for processing: 7
  • Source/JavaScriptCore/aot/builtins/AOTBuiltinTable.cpp
  • Source/JavaScriptCore/aot/builtins/AOTBuiltinTable.h
  • Source/JavaScriptCore/aot/runtime/AOTBuiltinCells.cpp
  • Source/JavaScriptCore/aot/runtime/AOTNativeCallValidation.cpp
  • Source/JavaScriptCore/aot/runtime/AOTStackTrace.cpp
  • Source/JavaScriptCore/aot/tests/AOTBuiltinTableTests.cpp
  • Source/JavaScriptCore/aot/tests/AOTStackTraceTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

Changes

Builtin function names now come from BuiltinTable::functionNameOf. Missing-host functions, native-call validation, and stack-trace naming use this method. Stack-trace naming no longer searches private globals in an instance realm. Tests cover symbol names and retained error stacks after collection.

Builtin naming and stack traces

Layer / File(s) Summary
Shared builtin function names
Source/JavaScriptCore/aot/builtins/AOTBuiltinTable.*, Source/JavaScriptCore/aot/runtime/AOTBuiltinCells.cpp, Source/JavaScriptCore/aot/runtime/AOTNativeCallValidation.cpp, Source/JavaScriptCore/aot/tests/AOTBuiltinTableTests.cpp
BuiltinTable::functionNameOf returns ordinary names unchanged, brackets registered-symbol names, and formats other symbol names as [Symbol.name]. Missing-host functions and native-call validation use the method. Tests check returned names, including push and Symbol.iterator.
Stack-trace builtin names
Source/JavaScriptCore/aot/runtime/AOTStackTrace.cpp, Source/JavaScriptCore/aot/tests/AOTStackTraceTests.cpp
Stack-trace lookups use a VM-independent helper that prefers a native function name and otherwise uses the builtin table name. Tests cover symbol-match calls and retained error stacks after collection.

Priority: Normal

Merge Risk: Minimal · up to a99e7

The built-in naming change is mergeable after normal checks and the stated companion Bun change lands first.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description follows the WebKit template's intent and gives the context a reviewer needs. It states the problem (a SIGSEGV at address 0 in WTF::findAtomBeforeAdding below JSC::AOT::nameOfBuiltin wh… Add a WebKit Bugzilla link (https://bugs.webkit.org/show_bug.cgi?id=#####) in the template's title format and mention the bug in the PR, as the template requires. Replace the Problem/Fix/Background layout with the template's header: bug tit…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: naming frames for called built-ins from static data.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description follows the WebKit template's intent and gives the context a reviewer needs. It states the problem (a SIGSEGV at address 0 in WTF::findAtomBeforeAdding below JSC::AOT::nameOfBuiltin when a collection writes out a stack that lists a called built-in) and the fix (nameOfBuiltin takes no VM and uses the new BuiltinTable::functionNameOf). It names the files touched, lists validation (three new stack-traces tests, builtin-table/function-names-follow-keys, testaot all with 7924 passed and 0 failed), and reports before/after numbers. It also gives landing order and known gaps. Its structure differs from the template: it has Problem, Fix, Background, and Downsides sections, not the template's bug-link, Reviewed by, explanation, and per-file changelog layout. The description does not include a bug tracker link (the template requires one, and the fix is described as needing an oven-sh/bun PR to land first). It also has no 'Reviewed by' line and no per-function changelog entries (e.g. '* path/changed.ext: (function):'). Those are required by the template. The core content is strong, but the missing bug link and changelog-style entries are real gaps for a WebKit change.

Resolution

Add a WebKit Bugzilla link (https://bugs.webkit.org/show_bug.cgi?id=#####) in the template's title format and mention the bug in the PR, as the template requires. Replace the Problem/Fix/Background layout with the template's header: bug title, bug link, 'Reviewed by' line (set to the reviewer, or leave a placeholder until review), and an explanation of the fix. Add a changelog-style file list in the template's format, for example '* Source/JavaScriptCore/aot/runtime/AOTStackTrace.cpp:' with the affected function names such as '(JSC::AOT::nameOfBuiltin)' and '(JSC::AOT::FunctionDescription::name)', and the same for AOTBuiltinTable.h/.cpp, AOTBuiltinCells.cpp, AOTNativeCallValidation.cpp, and the test files. Keep the landing-order and performance notes, but move them below the template fields.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@robobun

robobun commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: #997 covers this.

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