Repository navigation
Conversation
|
Status of this pull request
|
|
Preview build of a99e703: |
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.
9568a5c to
a99e703
Compare
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
🟣 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.
|
No actionable comments were generated in the recent review.
|
| 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:
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: 
3 · 
1
-
Failed checks: 1 warningCheck name Status Explanation Resolution Description check 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 checks: 3 passedFull 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.
Comment @coderabbitai help to get the list of available commands.
|
Closing: #997 covers this.
|
Problem
SIGSEGVat address 0 inWTF::findAtomBeforeAddingbelowJSC::AOT::nameOfBuiltin.nameOfBuiltin()(aot/runtime/AOTStackTrace.cpp:91) makes anIdentifierfor the name.Heap::pruneDeadReferences()sets the thread's atom table to null there.Symbol.match, not[Symbol.match].Fix
nameOfBuiltin()takes no VM. The name comes from the host's row or from the newBuiltinTable::functionNameOf(), which reads only the table.AOTBuiltinCells.cppandAOTNativeCallValidation.cppuse it too.%PrivateGlobals%arm, which read the first realm, is removed. Bun names its threerequirefunctions in rows: aot: name the functions thatrequirecalls in the table of built-ins bun#47293 lands first.stack-tracestests,builtin-table/function-names-follow-keys,testaot all(7924 passed, 0 failed).Background
Math.maxitself, and the stack trace lists a frame for it.ErrorInstance(Heap.cpp:1016forbids the lookup), or change only the last line (arequire()frame still crashes).Downsides
StringImpl(none before).StackFrame::appendToruns 497 instructions for amaxframe (736 before), 654 for[Symbol.match](553 before).jsctext: +704 bytes (lto-aotlane, x64).requireCommonJS, notanonymous.Notes
Landing order
mainfirst (aot: name the functions thatrequirecalls 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.requirecalls in the table of built-ins bun#47293 printsrequireCommonJSwhere it holdsanonymous.How to see it
The test program of
AOTStackTraceTests.cpphas three new functions:larger(Math.max(value, 2)),matches(pattern[Symbol.match](value)with aRegExpparameter) andclassed(a conversion marked as a step of%PrivateGlobals%.toClass, which no front end makes). A script hands each an object whosevalueOf/toStringis a new function. That function throws an error, or callsError.captureStackTraceon one. The script keeps the errors, drops the functions and callsfullGC().mainstack-traces/built-in-under-symbolSymbol.match[Symbol.match]stack-traces/collection-writes-out-called-built-insjscdies ofSIGSEGVstack-traces/collection-writes-out-stack-of-dead-realmjscdies ofSIGSEGVThe 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-aotlane, with a script that throws belowMath.maxand below[Symbol.match], drops the functions that threw and callsfullGC(). 20 runs with the default options and 20 with--useConcurrentGC=false:main(8c6c963)With the same lane binaries of this commit:
testaot native stack-traces11 passed,testaot all7924 passed, 0 failed, 42 todo, 33 left out.builtin-table/function-names-follow-keyscallsfunctionNameOf()for every name of the table while the thread has no atom table. Then it compares each answer with the key ofidentifierOf(): the text, or[description]for a symbol.Tools/Scripts/aot/check-unified-sources.py: 0 problems.Costs
jscof thelto-aotlane of each commit (x64).gdbsteps through every call ofJSC::StackFrame::appendTowhile two stacks are written out, from the entry to the return.appendTomain(8c6c963)maxframe[Symbol.match]frameStringImplthat points at the characters of the table. The name under a symbol is built withmakeString().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()isNEVER_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
main.AOTBuiltinTableValidation.cppis removed: no test could reach it.node:vmcontext reaches the crash in Bun, and that the dead-realm test is a state of the shell.nameOfBuiltin()and the comment of the dead-realm test speak of the frames of built-ins only.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) andAOTProgramIdentifiers.cpp(1).nameOfBuiltin()reached the first file throughfindInRealm(), and that call is removed.What the end of a collection runs in
aot/:AOTStackTrace.cpp, andfunctionName()ofAOTFunctionTables.cpp).AOTStackTrace.cppnow makes noIdentifier, andfunctionName()reads only the names that the VM already holds.CacheRegistry::finalize(), which calls theremoveDeadEntries()of each cache andPropertyCaches::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 ownError.captureStackTracekeeps. In canary 1.4.4-canary.1 a function of anode:vmcontext still has that function. Abun build --compile --aotexecutable in which such a function captures a stack belowMath.max, or belowrequire(), exits withSegmentation fault at address 0x0at the next collection that finds a frame dead (3 of 3 runs each,bun runexits with 0). oven-sh/bun#42605 would give every realm Bun'sError.captureStackTrace. Thejscshell has no hook at all: Bun'stest/aot/collector-stressfound 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
static displayNameis named throughfunctionName()(aot/object/AOTFunctionTables.cpp:577), which can fill the statics of the class at the end of a collection. The process aborts there onmainand on this commit. It is another defect with another fix.describeCodeAddresses()(aot/runtime/AOTStackTrace.cpp) names an inline frame of a called built-in withwrittenFunctionName(), which has no such function. WithnameOfBuiltin()free of the VM it can ask it.get size.displayNameis 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 thatrequirecalls in the table of built-ins bun#47293 holds the three names.