Repository navigation
Closed
Description
Description
Dear PHP Maintainers,
The following code, a barebones reproduction is available at https://github.com/michdingpayc/preload-segfault-minimum-reproduction
The problematic preloaded file:
class Root1_Constant_Referencer extends Root2_Empty_Empty
// Removing the extends clause will cause preloading to succeed
// Changing the extends clause to Root1_Constant_Empty will cause preloading to succeed
// Changing the extends clause to a non-existent class will continue causing preloading to segfault
{
protected $propertyReferencingAnExternalConstant = Root1_Constant_Definer::CONSTANT;
// Removing this line will cause preloading to succeed
// Changing this to a hardcoded value will cause preloading to succeed
}preload.php:
echo "Preload started." . PHP_EOL;
$files = require __DIR__ . '/vendor/composer/autoload_classmap.php';
foreach ($files as $file) {
@opcache_compile_file($file);
}
echo "Finished preloading" . PHP_EOL;Resulted in this output:
$ docker-compose up
Recreating preload-segfault-minimum-reproduction_webpreloader_1 ...
Recreating preload-segfault-minimum-reproduction_webpreloader_1 ... done
Attaching to preload-segfault-minimum-reproduction_webpreloader_1
webpreloader_1 | Preload started.
webpreloader_1 | Finished preloading
preload-segfault-minimum-reproduction_webpreloader_1 exited with code 139
But I expected this output instead:
(No segmentation Fault. The following output occurs if you comment out the opcache_compile_file call in preload.php)
$ docker-compose up
Starting preload-segfault-minimum-reproduction_webpreloader_1 ...
Starting preload-segfault-minimum-reproduction_webpreloader_1 ... done
Attaching to preload-segfault-minimum-reproduction_webpreloader_1
webpreloader_1 | Preload started.
webpreloader_1 | Finished preloading
webpreloader_1 | Thu Nov 17 18:15:38 2022 (1): Message Cached script '$PRELOAD$'
webpreloader_1 | Thu Nov 17 18:15:38 2022 (1): Message Cached script '/var/www/html/lib/preload.php'
webpreloader_1 | Thu Nov 17 18:15:38 2022 (1): Message Cached script '/var/www/html/lib/vendor/composer/autoload_classmap.php'
Recommendations attempted: (in all cases the result is the same)
- Changing base docker image from
php:8.1.1-fpm-alpine3.15tophp:8.1.12-fpm-alpine3.15andphp:8.2-rc-fpm-alpine3.15. - Different settings for
opcache.jitdirective:disable,0,0000,0205,1205. - Setting
opcache.jit_buffer_sizedirective to0.
Similar to #7817 though narrower in scope.
Running the docker-compose command in the linked repository will consistently reproduce the issue. This is a blocker for our PHP 8.1 migration. Will you please assist?
PHP Version
PHP 8.1.1 8.1.12 8.2
Operating System
Docker php:8.1.1-fpm-alpine3.15
Reacted by Arnaud Le Blanc, Michael Voříšek and Andrey
Activity
[-]Segmentation Fault during OPCache Preload in PHP 8.1/PHP8.2[/-][+]Segmentation Fault during OPCache Preload in PHP 8.1+[/+]michdingpayc commentedon Nov 18, 2022
Here is a relevant detail I believe wasn't clear in my original posting.
After a composer install,
Root2_Empty_Emptyis not listed in thevendor/composer/autoload_classmap.phpfile. This is by design. I would expect the following warning:Indeed this warning shows (with no segmentation fault) when the reference to
Root1_Constant_Definer::CONSTANTis removed from the problematic file. However, instead we see a segmentation fault. Interestingly, the file containingRoot1_Constant_Defineris listed in thevendor/composer/autoload_classmap.phpfile and should be preloaded.It seems to be related to BOTH an unknown parent class AND an external constant reference.
Do not resolve constants on non-linked class during preloading (#9975)
arnaud-lb commentedon Nov 25, 2022
Thank you for the high quality bug report!