Repository navigation
Segfault when using opcache and JIT #10626
Copy link
Copy link
Closed
Description
Description
Runnning https://github.com/vimeo/psalm with this php.ini causes a segfault (ref vimeo/psalm#9340):
zend_extension=opcache.so
opcache.optimization_level="0"
opcache.enable_cli=1
opcache.jit_buffer_size=512M
opcache.jit=1205
Command:
git clone https://github.com/vimeo/psalm
cd psalm
git checkout 5.7.0
composer i
php -n -c php.ini ./psalm --no-cache
gdb backtrace:
(gdb) backtrace
#0 0x00005555558c4a74 in zend_parse_arg (arg_num=4106310752, arg=0x7fffffffa0e0, va=0x55555642a70c, spec=0x7fffffffa278, flags=-23928) at /usr/src/debug/php/php-8.2.3/Zend/zend_API.c:989
#1 0x0000000000000000 in ?? ()
gdb zbacktrace:
(gdb) zbacktrace
[0x7ffff4c15400] DOMDocument->getElementsByTagNameNS("https://getpsalm.org/schema/config", unknown type 103) [internal function]
[0x7ffff4c151a0] Psalm\Config->processConfigDeprecations(object[0x7ffff4c151f0], object[0x7ffff4c15200], "<?xml version="1.0"?>\12<psalm\12 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instanc
e"\12 xmlns="https://getpsalm.org/schema/config"\12 name="Psalm for Psalm"\12 errorLevel="1"\12 throwExceptionOnError="0"\12 findUnusedCode="true"\12 ensureArrayStrin...", "/ho
me/daniil/repos/psalm/psalm.xml.dist") /home/daniil/repos/psalm/src/Psalm/Config.php:1003
[0x7ffff4c135d0] Psalm\Config->fromXmlAndPaths("/home/daniil/repos/psalm/", "<?xml version="1.0"?>\12<psalm\12 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\12 xmlns="https://getps
alm.org/schema/config"\12 name="Psalm for Psalm"\12 errorLevel="1"\12 throwExceptionOnError="0"\12 findUnusedCode="true"\12 ensureArrayStrin...", "/home/daniil/repos/psalm/", "/ho
me/daniil/repos/psalm/psalm.xml.dist") /home/daniil/repos/psalm/src/Psalm/Config.php:1033
[0x7ffff4c13500] Psalm\Config->loadFromXML("/home/daniil/repos/psalm/", "<?xml version="1.0"?>\12<psalm\12 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\12 xmlns="https://getpsalm.
org/schema/config"\12 name="Psalm for Psalm"\12 errorLevel="1"\12 throwExceptionOnError="0"\12 findUnusedCode="true"\12 ensureArrayStrin...", "/home/daniil/repos/psalm/", "/home/d
aniil/repos/psalm/psalm.xml.dist") /home/daniil/repos/psalm/src/Psalm/Config.php:823
[0x7ffff4c132b0] Psalm\Config->loadFromXMLFile("/home/daniil/repos/psalm/psalm.xml.dist", "/home/daniil/repos/psalm/") /home/daniil/repos/psalm/src/Psalm/Config.php:785
[0x7ffff4c131c0] Psalm\Config->getConfigForPath("/home/daniil/repos/psalm/", "/home/daniil/repos/psalm/") /home/daniil/repos/psalm/src/Psalm/Config.php:734
[0x7ffff4c12fa0] Psalm\Internal\CliUtils->initializeConfig(NULL, "/home/daniil/repos/psalm/", "console", object[0x7ffff4c13020], false)
/home/daniil/repos/psalm/src/Psalm/Internal/CliUtils.php:348
[0x7ffff4c12df0] Psalm\Internal\Cli\Psalm->loadConfig(NULL, "/home/daniil/repos/psalm/", "console", object[0x7ffff4c12e70], false, array(1)[0x7ffff4c12e90])
/home/daniil/repos/psalm/src/Psalm/Internal/Cli/Psalm.php:559
[0x7ffff4c12c30] Psalm\Internal\Cli\Psalm->initConfig("/home/daniil/repos/psalm/", array(1)[0x7ffff4c12c90], "vendor", object[0x7ffff4c12cb0], NULL, "console", false, array(1)[0x7ffff4c12cf0])
/home/daniil/repos/psalm/src/Psalm/Internal/Cli/Psalm.php:1020
[0x7ffff4c120a0] Psalm\Internal\Cli\Psalm->run(array(2)[0x7ffff4c120f0]) /home/daniil/repos/psalm/src/Psalm/Internal/Cli/Psalm.php:238
[0x7ffff4c12020] (main) /home/daniil/repos/psalm/psalm:9
PHP Version
PHP 8.2.3
Operating System
Arch linux
Reacted by Tarmo Leppänen
Activity
weirdan commentedon Feb 19, 2023
Note that
getElementsByTagNameNS()call happens in a loop over an array, however that array is empty (we don't have any deprecated elements at the moment), and execution should have never entered the loop body.ndossche commentedon Feb 19, 2023
arg_num is also a ridiculously high number, so looks like something got corrupted somewhere
weirdan commentedon Feb 19, 2023
Minimal reproducer:
Expected:
Actual:
dstogov commentedon Feb 20, 2023
@weirdan your test doesn't show any problems for me nor with php-8.2.3 neither with PHP-8.2.
Can you run the script under gdb and show backtrace. (PHP debug build is preferred).
This may be already fixed by commit 7d68f91, but it's included into php-8.2.3. Please check if you really use php 8.2.3 and the installed opcache is from the same PHP version.
dstogov commentedon Feb 20, 2023
Yeah. This is definitely fixed by 7d68f91. Reverting it starts crashing on both minimal test and psalm. There are no crashes with patch applied.
weirdan commentedon Feb 20, 2023
@dstogov this is still reproducible on 8.2.3:
I'll try to get debug symbols installed, but meanwhile, the culprit seems to be
-dopcache.optimization_level=0weirdan commentedon Feb 20, 2023
And the OPcache version (reported by
php -v) matches the php version:danog commentedon Feb 20, 2023
@weirdan It seems that the commit with the fix was only merged into master, and wasn't tagged yet
weirdan commentedon Feb 20, 2023
Backtrace with debug symbols added (from another machine):
weirdan commentedon Feb 20, 2023
and with
jit_debug=0x400:weirdan commentedon Feb 20, 2023
Having built
masterandPHP-8.2branches from git I can confirm that neither exhibit this bug. PHP 8.2.3 is still affected though.dstogov commentedon Feb 20, 2023
Right, the fix was not included into PHP-8.2.3. The last commit is from February 13, see https://github.com/php/php-src/commits/php-8.2.3 The fix was committed into PHP-8.2 on February 20. It's going to be included into 8.2.4.
As a temporary workaround you may use default value of opcache.optimization_level.
weirdan commentedon Feb 20, 2023
That's what we did.
dstogov commentedon Feb 20, 2023
In any case, thanks for your good report(s).
vasilvestre commentedon Feb 28, 2024
Is this possible that this issue also exists on 8.1 and hasn't been backported ?
ndossche commentedon Feb 28, 2024
The fix did make it into PHP 8.1.17.
Can you post more details (in a new issue) about your bug?
Also, please note that PHP 8.1 is not under bugfix support anymore, so it's worth checking if it reproduces under PHP 8.2 before making a report.
Thanks.