Skip to content

php-in-php: VmFsGlob/VmFsUnlink — delete host ext/ffi glob(3)/unlink(2) shims (bootstrap self-host) #7314

@PurHur

Description

@PurHur

Category

php-in-php | bootstrap

Problem

glob() and unlink() VM paths call host ext/ffi via ext/standard/VmFsGlob.php and VmFsUnlink.php. When FFI is unavailable (AOT self-host bundle, hardened bootstrap image), glob() falls back to a PHP iterator and unlink() returns false without error — breaking deploy scripts and compiler hygiene that delete temp artifacts.

Bootstrap M2–M5 must not depend on Zend ext/ffi for core filesystem builtins.

php-src reference

Repro

A — unlink without FFI

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
PHP_COMPILER_DISABLE_FFI=1 php bin/vm.php -r "
\$f = tempnam(sys_get_temp_dir(), \"t\");
var_export(file_exists(\$f));
var_export(unlink(\$f));
var_export(file_exists(\$f));
"'

If env gate missing today, simulate by temporarily forcing VmFsUnlink::ffi() null in a unit probe — document actual exit in PR.

B — glob parity

<?php
var_export(glob(__DIR__ . '/*.php', GLOB_NOSORT));
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php repro.php
php repro.php
'

Scope (this repo)

Module Path Notes
VM ext/standard/VmFsGlob.php, VmFsUnlink.php Replace FFI::cdef with compiled PHP lowering or thin AOT __compiler_unlink / __phpc_glob_vec already linked from phpc_stream.c / stream helpers
JIT/AOT lib/JIT/Builtin/ glob/unlink lowerers Mirror VM semantics
Registration ext/standard/glob_.php, unlink builtin
Tests test/compliance/cases/stdlib/glob_ffi_bootstrap.phpt, unlink_bootstrap.phpt

Goal: delete or shrink FFI blocks in VmFsGlob.php / VmFsUnlink.php; any retained C is syscall trampoline only (document lines removed).

Done when

  • unlink($path) succeeds on existing file in bootstrap image without host ext/ffi
  • glob() returns same file list as Zend for GLOB_NOSORT smoke on ext/standard/*.php
  • PR notes lines removed from FFI helpers (or C symbols deleted)
  • make bootstrap-selfhost-link / php script/bootstrap-inventory.php --check unaffected

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter "glob_|unlink"'
make bootstrap-selfhost-helloworld

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions