Skip to content

php-in-php: VmHrtime/VmDns — delete host ext/ffi clock_gettime/getaddrinfo shims (bootstrap) #7315

@PurHur

Description

@PurHur

Category

php-in-php | bootstrap

Problem

hrtime() and DNS hostname builtins (gethostbyname(), gethostbynamel(), …) use host ext/ffi in ext/standard/VmHrtime.php and VmDns.php. Self-host / AOT bundles that omit Zend FFI cannot provide monotonic timing or libc resolver calls — breaking perf probes (hrtime) and any compile-time / runtime path that resolves hostnames.

JIT already exposes __compiler_hrtime_* in lib/JIT/Builtin/StringHrtime.php; VM should share the same native path without instantiating FFI::cdef in PHP.

php-src reference

Repro

A — hrtime

<?php
var_export(is_array(hrtime()));
var_export(hrtime(true) > 0);
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php repro.php
php repro.php
'

B — DNS

<?php
var_export(gethostbyname('localhost'));
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'

Bootstrap gap: grep extension_loaded('ffi') in VmHrtime.php / VmDns.php — when false, behavior is degraded or absent; document in PR.

Scope (this repo)

Module Path
VM ext/standard/VmHrtime.php, VmDns.php — route through existing JIT/native symbols or new thin __compiler_* in linked runtime
JIT/AOT lib/JIT/Builtin/StringHrtime.php (reuse)
Builtins ext/standard/hrtime.php, DNS wrappers in Module.php
Tests test/compliance/cases/stdlib/hrtime_native.phpt, gethostbyname_native.phpt

PHP-in-PHP first: port resolver logic to ext/standard/ PHP where possible; keep C as syscall trampoline only.

Done when

  • Repro A passes on VM without host ext/ffi (monotonic array + positive int ns)
  • gethostbyname('localhost') returns 127.0.0.1 or ::1 without FFI
  • PR body lists lines removed from VmHrtime.php / VmDns.php FFI blocks
  • ./script/ci-fast.sh --filter hrtime green

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter hrtime'
make bootstrap-selfhost-link

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