php-src icon indicating copy to clipboard operation
php-src copied to clipboard

Segfault with JIT and large match/switch statements

Open therealgaxbo opened this issue 4 years ago • 4 comments

Description

Running this code with the JIT enabled results in a segfault (sometimes I have to run it 2-3 times before it happens): https://gist.github.com/therealgaxbo/5e7b111c994bf932e3e7870ac258babe

$ php -v
PHP 8.0.15 (cli) (built: Jan 18 2022 12:16:19) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.15, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.15, Copyright (c), by Zend Technologies

$ php -n -dzend_extension=/usr/lib64/php/modules/opcache.so -dopcache.enable_cli=1 -dopcache.jit_buffer_size=64M match.php
Segmentation fault (core dumped)

The same result happens with 8.1.2.

This is as minimal as I've managed to make the repro. It seems extremely sensitive to the precise order that the two different match arms are accessed.

A similar segfault happens with an equivalent switch statement, although the exact number of arms may need increasing.

PHP Version

PHP 8.0.15, PHP 8.1.2

Operating System

Fedora 35

therealgaxbo avatar Feb 03 '22 17:02 therealgaxbo

Confirmed, seeing similar result with php debian:

php -dopcache.jit_buffer_size=64M match.php
[1]    655079 segmentation fault (core dumped)  php -dopcache.jit_buffer_size=64M match.php
PHP 8.1.2 (cli) (built: Jan 24 2022 10:42:51) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

kocoten1992 avatar Feb 03 '22 23:02 kocoten1992

This might be related to #7854?

olivernybroe avatar Feb 04 '22 08:02 olivernybroe

I thought the same, but had already ruled it out - cmb69 found the offending commit for that one (https://github.com/php/php-src/commit/1f19401ffa0edb2b69f5f1bd229776ee34cf693e) and don't think that's in PHP 8.0.15.

I checked and can only trigger #7854 on 8.1.2, whereas my snipped segfaults on 8.0.15 as well.

therealgaxbo avatar Feb 04 '22 10:02 therealgaxbo

Thank you !

This is now fixed in https://github.com/php/php-src/pull/8961

arnaud-lb avatar Jul 18 '22 10:07 arnaud-lb