php / php-src

The PHP Interpreter
https://www.php.net
Other
37.97k stars 7.73k forks source link

opcache: symbol not found in flat namespace (_zend_gdb_register_code) when JIT enabled on Mac OS X #9639

Open dunglas opened 1 year ago

dunglas commented 1 year ago

Description

When compiling PHP 8.2 on Mac OS X with the following configuration:

./configure --enable-embed=static --enable-zts --with-iconv=/opt/homebrew/opt/libiconv/ --enable-opcache

I get this error when loading the opcache.so extension:

Failed loading /usr/local/lib/php/extensions/no-debug-zts-20220829/opcache.so: dlopen(/usr/local/lib/php/extensions/no-debug-zts-20220829/opcache.so, 0x0009): symbol not found in flat namespace (_zend_gdb_register_code)

Disabling opcache JIT fixes the issue:

./configure --enable-embed=static --enable-zts --with-iconv=/opt/homebrew/opt/libiconv/ --enable-opcache --disable-opcache-jit

PHP Version

PHP 8.2-dev

Operating System

macOS 12.6

devnexen commented 1 year ago

I could not reproduce on native arm64 nor in rosetta mode with both gcc and clang, would it be possible to give a bit more context ? did you try for example instead of removing opcache jit, removing zts ?

iluuu1994 commented 1 year ago

This is odd, zend_gdb_register_code is not static and zend_gdb.c is compiled unconditionally.

devnexen commented 1 year ago

start to wonder if this is a somewhat similar issue found here (as embed sapi involved).

dunglas commented 1 year ago

did you try for example instead of removing opcache jit, removing zts ?

Good catch, removing --enable-zts fixes the issue too!

I've written a SAPI to embed PHP in a Go binary. I can provide you a (private) repo with a reproducer if needed!

devnexen commented 1 year ago

sure why not feel free to send an email if you prefer.

dunglas commented 1 year ago

I upgraded to the latest commit of the PHP-8.2 branch, recompiled with the exact same flags... and the issue is gone.

Thanks for your help everybody!

dunglas commented 1 year ago

This issue is back again (macOS only). I probably made a mistake while recompiling hiding the issue. I can still give access to a reproducer.

devnexen commented 1 year ago

did you acknowledge what was advised here ?

dunglas commented 1 year ago

@devnexen this looks related but I'm not sure if that's precisely the same issue. Unlike #9635, I'm not loading PHP as a plugin for another app. PHP is statically compiled in the main Go binary:

+-------+-------+
|Go App         |
+---------------+
|     PHP       |
+--+---------+--+
   |         |dlopen/dlsym
+--+---+ +---+--+
| PHP  | | PHP  |
| ext1 | | ext2 |
+------+ +------+

Basically, the main app loads directly opcache.so.

devnexen commented 1 year ago

This issue is back again (macOS only). I probably made a mistake while recompiling hiding the issue. I can still give access to a reproducer.

you can send an email however won t be able to have a proper look at it before this weekend at earliest, pretty busy atm. but if someone else wants a crack at it before me that s fine :-)

dunglas commented 1 year ago

Now that FrankenPHP is public, here is a quick reproducer (on Mac):

compile PHP

./buildconf
./configure \
    --enable-embed=static \
    --enable-zts \
    --enable-static \
    --enable-shared=no \
    --with-iconv=/opt/homebrew/opt/libiconv/ \
    --enable-debug
make -j$(nproc)
sudo make install

Be sure that opcache is loaded in php.ini

run Franken's test suite

# Go must be installed
git clone --recursive git@github.com:dunglas/frankenphp.git
cd frankenphp
go test -v

Result:

<b>Warning</b>:  Failed loading Zend extension 'opcache' (tried: /usr/local/lib/php/extensions/debug-zts-20220830/opcache (dlopen(/usr/local/lib/php/extensions/debug-zts-20220830/opcache, 0x0009): tried: '/usr/local/lib/php/extensions/debug-zts-20220830/opcache' (no such file)), /usr/local/lib/php/extensions/debug-zts-20220830/opcache.so (dlopen(/usr/local/lib/php/extensions/debug-zts-20220830/opcache.so, 0x0009): symbol not found in flat namespace (_zend_gdb_register_code))) in <b>Unknown</b> on line <b>0</b><br />