Skip to content

Regression: AOT DOMDocument::replaceChild() segfaults after build — VM/JIT match Zend (ext/dom/node.c) #27216

Closed

Description

@PurHur

Category

Regression · php-src-strict · AOT · pillar 4 (DOM live-node)

Problem

DOMDocument::replaceChild matches Zend on VM/JIT (1:b), but thin AOT builds then segfaults (exit 139) before useful stdout — live DOM mutation gap (2026-08-03, 6a5b2fc66).

Repro Zend / VM / JIT AOT
replace <a> with <b> under <root>; print childNodes->length:firstChild->nodeName 1:b segfault (139) after c:main_before_php

Peer open Dom AOT: #27108 (Dom\\Attr::rename / createFromString — WIP #27151 still segfaults on living nodes).

php-src reference

PHP implementation target

  • Living Dom node graph under thin AOT / NestedJIT — replaceChild must update child lists and firstChild like VM (ext/dom + lib/JIT Dom helpers)
  • No new runtime/*.c DOM mutation logic; keep PHP-in-PHP

Repro

./script/docker-exec.sh -- bash -lc '
cat > /tmp/aot_dom_replace.php <<'"'"'PHP'"'"'
<?php
$d = new DOMDocument();
$r = $d->appendChild($d->createElement("root"));
$a = $r->appendChild($d->createElement("a"));
$b = $d->createElement("b");
$r->replaceChild($b, $a);
echo $r->childNodes->length, ":", $r->firstChild->nodeName, "\n";
PHP
php /tmp/aot_dom_replace.php
php bin/vm.php /tmp/aot_dom_replace.php
php bin/jit.php /tmp/aot_dom_replace.php
PHP_COMPILER_HELPER_RUNTIME_O=0 ./phpc build -o /tmp/aot_dom_replace /tmp/aot_dom_replace.php && /tmp/aot_dom_replace
'

Done when

  • AOT prints 1:b matching Zend/VM/JIT
  • Prefer --repeat 10 (segfault / heap class)
  • Repro/compliance guard; php-src-strict only

Activity

  1. added
    bugSomething isn't working
    phase-4:stdlibPhase 4 – stdlib for web apps
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Aug 3, 2026
  2. PurHur commented on Aug 3, 2026

    @PurHur
    OwnerAuthor

    Verified locally before filing (6a5b2fc66): Zend/VM/JIT print 1:b; thin AOT builds then exit 139 (fatal signal … after c:main_before_php). Gate context for the run (also on #27204 — #10533 comments locked): user_release_ready: no (helper-runtime prelink stale + north-star5-fast 4f-m).

  3. PurHur commented on Aug 3, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler Ext — DOM & XML — starting this run

    Gate snapshot before claim:

  4. PurHur commented on Aug 3, 2026

    @PurHur
    OwnerAuthor

    Merged in #27247

    Verification: Zend/VM/JIT/AOT print 1:b; AOT repeat 10/10; AotTest dom_node_replacechild* OK (2); #27044 live length still green.

    Cause: thin-AOT createElement LLVM materialize has no DomRegistry; NestedJIT replaceChild bridge segfaulted. Fix syncs live child slots like append and seeds childNodes length when unset.

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 / JITbugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions