Skip to content

AOT: gc_collect_cycles() segfaults with 2,000 cyclic objects (Zend collects 1,998) — and 200k objects also trigger a false "Undefined variable $a" warning (lib/JIT/Builtin/GcCollectCyclesRuntime.php, ext/standard/GcCollectCyclesRegistryJitHelper.php) #36245

Description

@PurHur

Category

Regression: · runtime crash · child of #36188

Problem

Verified on master 4eed6a2785 in the pinned image (build/audit/v_gc1.php):

<?php class N { public $o; }
for ($r = 0; $r < 2; $r++) {
  for ($i = 0; $i < 1000; $i++) { $a = new N; $b = new N; $a->o = $b; $b->o = $a; }
  echo gc_collect_cycles(), "\n";
}
Zend AOT
output 1998 / 2000 Segmentation fault (rc 139), no output

With 100,000 pairs per round (build/audit/p_gc.php) the binary additionally prints PHP Warning: Undefined variable $a in … on line 1 before crashing — $a is assigned on every iteration, so the warning is the module-global undefined-variable flag (#36190) misfiring on a {main} loop variable. The 65,536-object hard cap in GcCollectCyclesRuntime::MAX_OBJECTS (#36195) is a separate defect; 2,000 objects are far below it, so this crash is in the mark/sweep itself (phpc_gc_collect_cycles_impl) or in the property-count/phpc_gc_prop_counts bookkeeping for objects whose only property is another object.

gc_collect_cycles() is called by frameworks, test runners and long-running workers; any AOT binary doing so with live cycles dies.

php-src reference

  • Zend/zend_gc.c zend_gc_collect_cycles — mark roots grey, scan, collect white; refcounts of the objects being freed are decremented through zend_objects_store_del, never read after free.

PHP implementation target

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/compile.php -o build/gc1 build/audit/v_gc1.php && ./build/gc1; echo rc=$?; php build/audit/v_gc1.php'

Done when

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

    IMPORTANTCritical patharea:compilerCompiler / CFG / JITbugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-3:aotPhase 3 – AOT deployment

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions