Skip to content

Defer nested-JIT standalone init for bootstrap AOT compile (#14472)#14480

Merged
PurHur merged 2 commits into
masterfrom
agent/issue-14472-string-json-encode-insert-restore-lane-b
Jul 1, 2026
Merged

Defer nested-JIT standalone init for bootstrap AOT compile (#14472)#14480
PurHur merged 2 commits into
masterfrom
agent/issue-14472-string-json-encode-insert-restore-lane-b

Conversation

@PurHur

@PurHur PurHur commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add StreamIoRuntime::beginStandaloneInitPhase() so ensureFullStandaloneBodies() defers nested php-in-PHP JIT (JsonEncode, Getenv, CliArgv, stream/json stubs) during standalone spine init — fixes exit 139 in loadJitContext() / StringJsonEncode::ensureJitHelperCompiled.
  • CliArgv spine init uses thin ensureUserScriptMainStubs during defer; skip StringGetenvAll nested JIT; lazy-link soundex/metaphone/parse_str during defer.
  • Link ObOutputRuntime, ValueEchoRuntime, StringRandomBytes in full standalone bodies; skip VM env-probe gate for bootstrap-aot/ entries.
  • StringJsonEncode::implement: NestedJitCompileScope guard + insert-block restore for future full ensureLinked lowering.

Root cause (#14472)

Nested jit->compile(JsonEncodeJitHelper) during ensureFullStandaloneBodies segfaulted LLVM 9 after #14470 unblocked CliArgv. Same class as #13245 inventory defer — spine init only needs linkable ABI stubs until user code calls ensureLinked.

Verification

source script/php-env.sh

# Issue repro — compile succeeds (was exit 139)
php bin/compile.php -o /tmp/echo_hello test/bootstrap-aot/echo_hello.php
# exit 0; /tmp/echo_hello created

# loadJitContext standalone init
php -r 'require "vendor/autoload.php"; $r = new PHPCompiler\Runtime(PHPCompiler\Runtime::MODE_AOT); $r->loadJitContext(); echo "ok\n";'
# ok

php vendor/bin/phpunit --filter 'BootstrapAotJitCompileTest::testEchoHelloBootstrapAotCompileDoesNotSegfault|BootstrapAotJitCompileTest::testLoadJitContextStandaloneInitCompletes|CliArgvRuntimeShrinkTest'
# OK (5 tests)

make bootstrap-selfhost-link
# bootstrap-selfhost-link: OK build/selfhost

Handoff

  • Runtime execute: compiled echo_hello binary still segfaults at c:main_before_php when run — compile/link gate is green; follow-up needed for AOT main() runtime path.
  • json_encode AOT: ensureLinked still needs stub→full upgrade when user code calls json_encode (e.g. test/bootstrap-aot/stdlib_json.php).

Closes #14472

Made with Cursor

#14472).

Standalone spine init now stubs heavy JsonEncode/Getenv/CliArgv helpers instead of
running nested php-in-PHP JIT during loadJitContext, which LLVM 9 was segfaulting on.
Adds regression tests for echo_hello compile and loadJitContext completion.

Co-authored-by: Cursor <cursoragent@cursor.com>
…l/JsonEncode conflicts).

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur PurHur merged commit bdd5ec3 into master Jul 1, 2026
@PurHur PurHur deleted the agent/issue-14472-string-json-encode-insert-restore-lane-b branch July 1, 2026 08:59
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.

Bootstrap: StringJsonEncode::ensureStandaloneBodies segfault blocks bootstrap-aot-link (post-#14470)

1 participant