Skip to content

Stdlib AOT: link file_get_contents() for user-script standalone (#9308) - #16710

Merged
PurHur merged 2 commits into
masterfrom
agent/stdlib-file-get-contents-aot-link
Jul 6, 2026
Merged

PurHur merged 2 commits into
masterfrom
agent/stdlib-file-get-contents-aot-link

Conversation

@PurHur

@PurHur PurHur commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

php-src reference

  • ext/standard/streamsfuncs.c — php_stream_copy_to_mem

Verification

source script/php-env.sh
unset PHP_COMPILER_AOT_USER_SCRIPT

php bin/compile.php -o /tmp/fgc_aot - <<'PHP'
<?php
$path = 'test/compliance/cases/stdlib/readfile_fixture/data.txt';
echo file_get_contents($path);
PHP
/tmp/fgc_aot
# hello readfile

vendor/bin/phpunit test/compliance/JITTest.php --filter file_get_contents
# OK (9 tests)

vendor/bin/phpunit test/unit/FileGetContentsRuntimeShrinkTest.php
# OK (3 tests)

Known gaps (not merge-ready)

  • vendor/bin/phpunit test/aot/AotTest.php --filter file_get_contents — links but PHPUnit proc_open run aborts (munmap_chunk(): invalid pointer); direct php bin/compile.php path is green
  • file_get_contents_offset AOT fixture — compile SIGSEGV; needs __compiler_file_put_contents + offset slice
  • readfile AOT — still returns 0; needs StringReadfileLibc parity

Closes #9308 when AOT fixtures above are green.

Made with Cursor

PurHur and others added 2 commits July 6, 2026 02:00
…one (#9308)

User-script AOT defers Type/String_.php helper emit (#13571), leaving
__compiler_file_get_contents as an unresolved stub at link time. Register
StringFileGetContents/StringReadfile in ensureMinimalUserStandaloneBodies,
save/restore LLVM insertion during bridge emit, and restore the thin libc
open/read bridge for minimal standalone AOT where nested PHP JIT is unavailable.

php-src: ext/standard/streamsfuncs.c — php_stream_copy_to_mem
Co-authored-by: Cursor <cursoragent@cursor.com>
Use __mm__free for chunk buffer teardown and pin REQUEST_METHOD= empty
so AotTest does not inject GET (which tripped munmap on web refresh).

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur force-pushed the agent/stdlib-file-get-contents-aot-link branch from f63d662 to 95db2ca Compare July 6, 2026 02:00
@PurHur

PurHur commented Jul 6, 2026

Copy link
Copy Markdown
Owner Author

Additional verification (2026-07-06)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/aot/AotTest.php --filter "testCases with data set \"file_get_contents\""'
# OK (1 test, 5 assertions)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/unit/FileGetContentsRuntimeShrinkTest.php'
# OK (3 tests, 9 assertions)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/compliance/JITTest.php --filter file_get_contents'
# OK (9 tests, 9 assertions)

Follow-up commit: __mm__free for libc chunk buffer + REQUEST_METHOD= in AOT PHPT (prevents AotTest default GET env from tripping munmap on web superglobal refresh).

Known remaining gap: file_get_contents_offset AOT fixture still compile-SIGSEGV (needs file_put_contents standalone link).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stdlib: file_get_contents() offset/length args return false — must read slice (ext/standard/file.c)

1 participant