Skip to content

AOT: str_pad() segfaults — three-argument literal call is enough #23911

Closed

Description

@PurHur

Summary

str_pad() segfaults in an AOT binary. A single call with all literal arguments is enough; no
computed arguments, no variables, no other code required.

VM is unaffected.

Reproducer

<?php echo str_pad('p', 5, '-'), "\n";
zend: p----
aot : phpc: fatal signal (segfault) after c:main_before_php

Argument form is irrelevant

program AOT
str_pad('p', 5, '-') — all literals segfault
$x=5; str_pad('p', $x, '-') — variable length segfault
$x=3; str_pad('p', $x+2, '-') — computed length segfault

So this is not the computed-argument / packed-argv path that #23871 was about. str_pad itself is
broken.

substr() is fine, for contrast

Same file shape, same argument forms, no crash:

<?php echo substr('abcdefgh', 1, 4), "\n";          // ok — bcde
<?php $x=3; echo substr('abcdefgh', $x-2, $x+1), "\n";  // ok — bcde

That narrows it to str_pad's own lowering rather than string builtins generally.

Note on the marker

The crash reports after c:main_before_php, i.e. it does not reach user code output. Worth checking
whether the fault is at the call site or in str_pad's emitted body/registration.

Blast radius

Accounts for two standing AOT differential failures:

  • c11_strcmp.php — str_pad('p',$x+2,'-') then substr(...)
  • e15_str_fns.php — str_pad($s,$n+13,".") then substr(...) then str_replace(...)

Both were previously recorded only as "segfault" at case level; this pins the function.

Environment: php-compiler:22.04-dev, PHP 8.2.32, LLVM 9, php bin/compile.php -o <bin> <file>,
master 055356698. Reproducers in build/micro/strfn/.

Activity

  1. PurHur commented on Jul 27, 2026

    @PurHur
    OwnerAuthor

    Companion: str_replace() returning Array under AOT is #23912. e15_str_fns.php hits both, so it needs both before it passes; c11_strcmp.php needs only this one.

  2. added
    bugSomething isn't working
    phase-3:aotPhase 3 – AOT deployment
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 27, 2026
  3. PurHur commented on Jul 27, 2026

    @PurHur
    OwnerAuthor

    claim: Lane B implementer — starting this run

  4. PurHur commented on Jul 27, 2026

    @PurHur
    OwnerAuthor

    merged: #23931

    Fix: inline pad loop in StrPadJitHelper (stop NestedJIT VmString::strPad null — peer #23204); StringStrPad NestedJitCompileScope guard.

    Verified:

    • php bin/compile.php -o … test/repro/issue23911_str_pad_aot.php && … → p---- ×3, exit 0 (was segfault after c:main_before_php)
    • vendor/bin/phpunit --filter StrPadRuntimeShrinkTest OK
    • AOT fixtures str_pad / str_pad_literal_segfault / str_pad_named_params OK
    • c11_strcmp.php AOT → p---- / bcde
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-3:aotPhase 3 – AOT deployment

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions