Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation Fault during OPCache Preload in PHP 8.1+ #9968

Closed
michdingpayc opened this issue Nov 17, 2022 · 2 comments
Closed

Segmentation Fault during OPCache Preload in PHP 8.1+ #9968

michdingpayc opened this issue Nov 17, 2022 · 2 comments

Comments

@michdingpayc
Copy link

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)

  1. Changing base docker image from php:8.1.1-fpm-alpine3.15 to php:8.1.12-fpm-alpine3.15 and php:8.2-rc-fpm-alpine3.15.
  2. Different settings for opcache.jit directive: disable, 0, 0000, 0205, 1205.
  3. Setting opcache.jit_buffer_size directive to 0.

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

@michdingpayc michdingpayc changed the title Segmentation Fault during OPCache Preload in PHP 8.1/PHP8.2 Segmentation Fault during OPCache Preload in PHP 8.1+ Nov 17, 2022
@michdingpayc
Copy link
Author

Here is a relevant detail I believe wasn't clear in my original posting.

After a composer install, Root2_Empty_Empty is not listed in the vendor/composer/autoload_classmap.php file. This is by design. I would expect the following warning:

Can't preload unlinked class Root1_Constant_Referencer: Unknown parent Root2_Empty_Empty in /var/www/html/lib/packages/Root1/src/Constant/Referencer.php on line 3

Indeed this warning shows (with no segmentation fault) when the reference to Root1_Constant_Definer::CONSTANT is removed from the problematic file. However, instead we see a segmentation fault. Interestingly, the file containing Root1_Constant_Definer is listed in the vendor/composer/autoload_classmap.php file and should be preloaded.

It seems to be related to BOTH an unknown parent class AND an external constant reference.

@arnaud-lb
Copy link
Member

Thank you for the high quality bug report!

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

No branches or pull requests

4 participants
@arnaud-lb @cmb69 @michdingpayc and others