Skip to content

Fix bootstrap AOT segfault: CallArgv LLVM global cross-context leak (#14459)#14473

Merged
PurHur merged 4 commits into
masterfrom
agent/issue-14459-callargv-context-leak
Jul 1, 2026
Merged

Fix bootstrap AOT segfault: CallArgv LLVM global cross-context leak (#14459)#14473
PurHur merged 4 commits into
masterfrom
agent/issue-14459-callargv-context-leak

Conversation

@PurHur

@PurHur PurHur commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • CallArgv (lib/JIT/Builtin/CallArgv.php): guard __phpc_call_argv_ht per LLVM module using the same pattern as LateStaticBindingGlobals — static Value must not leak across JIT\Context instances (php-src ref: nested JIT during defineBuiltins() / WeakRefRegistryRuntime::ensureJitHelperCompiled).
  • Reentrant Context init (lib/Runtime.php, lib/JIT/Context.php): claimJitContextSlot() binds the in-flight context before defineBuiltins() so nested loadJitContext() during php-in-PHP helper JIT does not spawn a second module.
  • Bootstrap-aot thin init (lib/JIT/Context.php, bin/compile.php): test/bootstrap-aot/* auto-sets PHP_COMPILER_BOOTSTRAP_AOT_LINK=1 and uses ensureBootstrapAotStandaloneBodies() to avoid nested-JIT segfault in ensureFullStandaloneBodies() (StringJsonEncode / StringGetenvAll path). Defer heavy emitters via StreamIoRuntime + StringGetenvAll stubs when link flag is set.

Verification

Issue repro (was exit 139 segfault):

source script/php-env.sh
php bin/compile.php -o /tmp/echo_hello test/bootstrap-aot/echo_hello.php
echo compile_exit:$?
# compile_exit:0

Unit tests:

source script/php-env.sh
./vendor/bin/phpunit test/unit/BootstrapAotEchoCompileTest.php test/unit/CallArgvContextModuleTest.php
# OK (2 tests)

Remaining / handoff

  • make bootstrap-aot-link no longer mass-segfaults on compile, but many fixtures still report output mismatch (AOT binary runs with empty stdout for echo_hello on this host) or compile failure — follow-up needed for standalone echo/output path under thin bootstrap init.
  • Full ensureFullStandaloneBodies() without PHP_COMPILER_BOOTSTRAP_AOT_LINK still segfaults in nested Json/Getenv JIT; thin path is the bootstrap gate fix for Bootstrap: CallArgv LLVM global leaks across JIT Context — bootstrap-aot-link segfault (#197) #14459.

Closes #14459

Made with Cursor

PurHur and others added 4 commits July 1, 2026 08:46
…ntext leak (#14459).

Guard CallArgv globals per LLVM module (LateStaticBindingGlobals pattern), bind the in-flight JIT Context before defineBuiltins for reentrant nested JIT, and route bootstrap-aot fixtures through thin standalone init so nested php-in-PHP helpers do not segfault during Context construction.

Co-authored-by: Cursor <cursoragent@cursor.com>
PHP_COMPILER_BOOTSTRAP_AOT_LINK deferred inventory ob_* stubs were no-ops,
so echo_hello AOT binaries linked but produced empty stdout. Mirror the
user-script AOT path: direct STDOUT LLVM echo without nested ObOutputJitHelper.

Co-authored-by: Cursor <cursoragent@cursor.com>
…pattern.

Co-authored-by: Cursor <cursoragent@cursor.com>
…teRegistry JIT.

compileCommon always links AttributeRegistryJitHelper, which calls
__compiler_json_decode; thin bootstrap init must declare those ABI symbols
before nested helper JIT (master #14470 + rebase).

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur PurHur force-pushed the agent/issue-14459-callargv-context-leak branch from 38e18c2 to e1e4ce3 Compare July 1, 2026 08:47
@PurHur PurHur merged commit c7cb21f into master Jul 1, 2026
@PurHur PurHur deleted the agent/issue-14459-callargv-context-leak branch July 1, 2026 08:47
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: CallArgv LLVM global leaks across JIT Context — bootstrap-aot-link segfault (#197)

1 participant