At present, PHP cannot be built using LTO (Link Time Optimization). LTO is a compiler feature that can improve performance by optimizing at link time. Chromium is also using this feature.
https://gcc.gnu.org/onlinedocs/gccint/LTO-Overview.html The reason for the LTO failure appears to be the Zend Engine's use of GCC's global register variables. Conversely, it is otherwise compatible with LTO. (except: opcache). I modified toolchain too to enable and validate LTOs outside of Zend Engine and OPcache: https://github.com/zeriyoshi/php-src/commit/b25c237837fec2f82d268d8dbd45ec886baf474f I tested the following compilation options: ``` gcc: (Debian 10.2.1-6) 10.2.1 20210110 CFLAGS="-fstack-protector-strong -fpic -fpie -O3 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" CXXFLAGS="${CFLAGS}" LDFLAGS="-Wl,-O1 -pie" $ ./sapi/cli/php ./Zend/bench.php simple 0.010 simplecall 0.005 simpleucall 0.010 simpleudcall 0.013 mandel 0.052 mandel2 0.049 ackermann(7) 0.012 ary(50000) 0.003 ary2(50000) 0.002 ary3(2000) 0.020 fibo(30) 0.035 hash1(50000) 0.004 hash2(500) 0.004 heapsort(20000) 0.012 matrix(20) 0.012 nestedloop(12) 0.010 sieve(30) 0.006 strcat(200000) 0.002 ------------------------ Total 0.261 ``` vs ``` gcc: (Debian 10.2.1-6) 10.2.1 20210110 CFLAGS="-fstack-protector-strong -fpic -fpie -O3 -flto -fuse-linker-plugin -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" CXXFLAGS="${CFLAGS}" LDFLAGS="-Wl,-O1 -pie -flto -fuse-linker-plugin" $ ./sapi/cli/php ./Zend/bench.php simple 0.006 simplecall 0.003 simpleucall 0.010 simpleudcall 0.014 mandel 0.050 mandel2 0.049 ackermann(7) 0.012 ary(50000) 0.003 ary2(50000) 0.002 ary3(2000) 0.020 fibo(30) 0.035 hash1(50000) 0.004 hash2(500) 0.004 heapsort(20000) 0.012 matrix(20) 0.011 nestedloop(12) 0.010 sieve(30) 0.007 strcat(200000) 0.002 ------------------------ Total 0.255 ``` In fact, it does not seem to work very well. However, it may be effective when large numbers of extensions are built into PHP. Is anyone interested in supporting this?