@@ -331,6 +331,24 @@ AS_VAR_IF([php_cv_have_global_register_vars], [yes],
331331] )
332332AC_MSG_CHECKING ( [ whether to enable global register variables support] )
333333AC_MSG_RESULT ( [ $ZEND_GCC_GLOBAL_REGS] )
334+
335+ dnl GCC doesn't propagate -ffixed-* from LTO objects. Reserve the VM registers
336+ dnl before LTO code gen to avoid "global register variable follows a function definition"
337+ AS_VAR_IF ( [ ZEND_GCC_GLOBAL_REGS] , [ yes] , [
338+ zend_lto=no
339+ for zend_flag in $CC $CFLAGS $LDFLAGS; do
340+ AS_CASE ( [ $zend_flag] , [ -flto|-flto=*] , [ zend_lto=yes] , [ -fno-lto] , [ zend_lto=no] )
341+ done
342+ AS_VAR_IF ( [ zend_lto] , [ yes] , [
343+ AS_CASE ( [ $host_cpu] ,
344+ [ x86_64*|amd64*] , [ AS_VAR_APPEND ( [ LDFLAGS] , [ " -ffixed-r14 -ffixed-r15"] ) ] ,
345+ [ x86*|amd*|i?86*|pentium] , [ AS_VAR_APPEND ( [ LDFLAGS] , [ " -ffixed-esi -ffixed-edi"] ) ] ,
346+ [ aarch64*|arm64*] , [ AS_VAR_APPEND ( [ LDFLAGS] , [ " -ffixed-x27 -ffixed-x28"] ) ] ,
347+ [ ppc64*|powerpc64*] , [ AS_VAR_APPEND ( [ LDFLAGS] , [ " -ffixed-r14 -ffixed-r15"] ) ] ,
348+ [ riscv64*] , [ AS_VAR_APPEND ( [ LDFLAGS] , [ " -ffixed-x18 -ffixed-x19"] ) ] ,
349+ [ AC_MSG_ERROR ( [ Cannot reserve VM registers for LTO, disable LTO or use --disable-gcc-global-regs] ) ] )
350+ ] )
351+ ] )
334352] )
335353
336354dnl
0 commit comments