Skip to content

php-in-php: delete JitEnv emitLibcPutenvMirror — route libc environ sync through GetenvJitHelper PHP (#1492) #23414

Description

@PurHur

Category

php-in-php · runtime-shrink (#1492, peer #19215 / #21023)

Problem

ext/standard/JitEnv.php already calls NestedJIT GetenvJitHelper::putenv, but still emits ~50 LOC of inline libc LLVM (malloc/memcpy/strchr/setenv/free) via emitLibcPutenvMirror and a duplicate path in putenvFromCStringLiteral. That is a hand-written C ABI shortcut beside the PHP helper — same shape as closed rename/unlink defer migrations.

test/unit/PutenvRuntimeShrinkTest.php currently requires emitLibcPutenvMirror to remain; flip that guard when the PHP path owns process-environ mirroring.

php-src reference

PHP implementation target

  • ext/standard/GetenvJitHelper.php — ensure putenv() (or a thin companion) also mirrors into process environ for libc getenv readers (AOT: fix request_parse_body compile/link (#5965) #17316), without JIT-side LibcExtern emission
  • ext/standard/JitEnv.php — delete emitLibcPutenvMirror; simplify putenvFromCStringLiteral to helper-only
  • test/unit/PutenvRuntimeShrinkTest.php — assert no emitLibcPutenvMirror / LibcExtern::register in JitEnv.php

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
vendor/bin/phpunit test/unit/PutenvRuntimeShrinkTest.php
tmpdir=$(mktemp -d)
PHP_COMPILER_AOT_USER_SCRIPT=1 php bin/compile.php -o "$tmpdir/pe" -r "putenv(\"PHPC_PE=1\"); echo getenv(\"PHPC_PE\");"
"$tmpdir/pe"
make bootstrap-selfhost-vm-driver-execute-probe
'

Done when

  • emitLibcPutenvMirror deleted from JitEnv.php
  • putenvFromCStringLiteral has no inline malloc/setenv LLVM
  • AOT user-script putenvgetenv smoke prints 1
  • PutenvRuntimeShrinkTest green (guards absence of libc defer)
  • make bootstrap-selfhost-vm-driver-execute-probe green
  • PR body cites lines removed from JitEnv.php

Refs #1492, #17316, #19215, #21023, #20499, #20644, #10533

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevEx

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions