From 1cff7a49e02d262e1fce6ff15e9544bd7f7eda68 Mon Sep 17 00:00:00 2001 From: henderkes Date: Sun, 6 Sep 2026 00:28:57 +0200 Subject: [PATCH 1/4] perf: fix LTO build with gcc (hybrid VM) --- Zend/Zend.m4 | 15 +++++++++++++++ build/ltmain.sh | 2 ++ 2 files changed, 17 insertions(+) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index 72bc116f7edb..e585944d3d0d 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -330,6 +330,21 @@ AS_VAR_IF([php_cv_have_global_register_vars], [yes], ]) AC_MSG_CHECKING([whether to enable global register variables support]) AC_MSG_RESULT([$ZEND_GCC_GLOBAL_REGS]) + +dnl GCC doesn't propagate -ffixed-* from LTO objects. Reserve the VM registers +dnl before LTO code gen to avoid "global register variable follows a function definition" +AS_VAR_IF([ZEND_GCC_GLOBAL_REGS], [yes], [ + zend_lto=no + for zend_flag in $CC $CFLAGS $LDFLAGS; do + AS_CASE([$zend_flag], [-flto|-flto=*], [zend_lto=yes], [-fno-lto], [zend_lto=no]) + done + AS_VAR_IF([zend_lto], [yes], [ + AS_CASE([$host_cpu], + [x86_64], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-r14 -ffixed-r15"])], + [aarch64*], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-x27 -ffixed-x28"])], + [AC_MSG_ERROR([Cannot reserve VM registers for LTO, disable lto or use --disable-gcc-global-regs])]) + ]) +]) ]) dnl diff --git a/build/ltmain.sh b/build/ltmain.sh index 3c00e7915707..7cfa084920fc 100755 --- a/build/ltmain.sh +++ b/build/ltmain.sh @@ -1689,6 +1689,8 @@ EOF # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC # -F/path gives path to uninstalled frameworks, gcc on darwin # @file GCC response files + # -ffixed-*, -fno-lto GCC LTO register reservations and cancellation + -ffixed-*|-fno-lto| \ -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*) From f0eff010e880a6ef5f1ef165423dfd01c100d3f3 Mon Sep 17 00:00:00 2001 From: Marc Date: Sun, 6 Sep 2026 09:16:39 +0200 Subject: [PATCH 2/4] add i386 registers --- Zend/Zend.m4 | 1 + 1 file changed, 1 insertion(+) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index e585944d3d0d..b66eb0a59334 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -340,6 +340,7 @@ AS_VAR_IF([ZEND_GCC_GLOBAL_REGS], [yes], [ done AS_VAR_IF([zend_lto], [yes], [ AS_CASE([$host_cpu], + [i386], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-esi -ffixed-edi"])], [x86_64], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-r14 -ffixed-r15"])], [aarch64*], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-x27 -ffixed-x28"])], [AC_MSG_ERROR([Cannot reserve VM registers for LTO, disable lto or use --disable-gcc-global-regs])]) From 689a52744d8a8b530c36c7bab771696ec57c2e79 Mon Sep 17 00:00:00 2001 From: henderkes Date: Sun, 6 Sep 2026 20:55:42 +0200 Subject: [PATCH 3/4] feedback: add extra host handling in global reg var checks --- Zend/Zend.m4 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index b66eb0a59334..4945ffa46977 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -340,9 +340,11 @@ AS_VAR_IF([ZEND_GCC_GLOBAL_REGS], [yes], [ done AS_VAR_IF([zend_lto], [yes], [ AS_CASE([$host_cpu], - [i386], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-esi -ffixed-edi"])], - [x86_64], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-r14 -ffixed-r15"])], - [aarch64*], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-x27 -ffixed-x28"])], + [x86_64*|amd64*], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-r14 -ffixed-r15"])], + [x86*|amd*|i?86*|pentium], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-esi -ffixed-edi"])], + [aarch64*|arm64*], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-x27 -ffixed-x28"])], + [ppc64*|powerpc64*], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-r14 -ffixed-r15"])], + [riscv64*], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-x18 -ffixed-x19"])], [AC_MSG_ERROR([Cannot reserve VM registers for LTO, disable lto or use --disable-gcc-global-regs])]) ]) ]) From 07d96e5bd747d23fe7bbc40158c23d7288c8eefc Mon Sep 17 00:00:00 2001 From: henderkes Date: Sun, 6 Sep 2026 21:05:06 +0200 Subject: [PATCH 4/4] capitalise lto both times --- Zend/Zend.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index 4945ffa46977..fd8eee17f23f 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -345,7 +345,7 @@ AS_VAR_IF([ZEND_GCC_GLOBAL_REGS], [yes], [ [aarch64*|arm64*], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-x27 -ffixed-x28"])], [ppc64*|powerpc64*], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-r14 -ffixed-r15"])], [riscv64*], [AS_VAR_APPEND([LDFLAGS], [" -ffixed-x18 -ffixed-x19"])], - [AC_MSG_ERROR([Cannot reserve VM registers for LTO, disable lto or use --disable-gcc-global-regs])]) + [AC_MSG_ERROR([Cannot reserve VM registers for LTO, disable LTO or use --disable-gcc-global-regs])]) ]) ]) ])