Open jingjingxyk opened 1 month ago
Well, there might be reason why "OPcache can only be compiled as a shared extension" according to the documentation.
Anyhow, did that work with previous versions of PHP 8.2?
Test PHP version list
PHP_VERSION=8.2.21 PHP_VERSION=8.3.9 PHP_VERSION=8.1.29 PHP_VERSION=8.0.30
They have similar compilation errors
/usr/bin/ld: ext/opcache/jit/zend_jit.o: TLS transition from R_X86_64_TLSGD to R_X86_64_GOTTPOFF against `_tsrm_ls_cache' at 0x12fc3 in section `.text' failed
/usr/bin/ld: failed to set dynamic section sizes: bad value
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:259: sapi/cli/php] Error 1
Thank you! So this is actually a feature request (to be able to compile OPcache statically), but not a report about a regression.
If PHP does not enable ZTS, opcache extension static compilation can be successfully compiled
https://github.com/jingjingxyk/swoole-cli/actions/runs/10062434474/
The problem seems to be that ld
is trying to optimize the relocation here, but fails because we (purposefully) don't generate the exact code that ld
is expecting.
This does not affect glibc builds, as in this case we use a different relocation in tsrm_get_ls_cache_tcb_offset()
. I believe that it would be safe to do the same for other libcs only when php is being compiled as executable, which we don't know until linking.
Compile target : Statically compiled PHP enable Zend Thread Safe and opcache extension
environment :
OS: alpine OS-Version: 3.19 CPU ARCH : x86_64
The following code:
vi build-static-php.sh
vi opcache-static-compile-patch.sh
Compile PHP into Static Binary
Resulted in this output:
PHP Version
8.2.21
Operating System
alpine 3.18