Skip to content

Commit b06cda0

Browse files
authored
perf: fix LTO build with gcc (hybrid VM) (#23602)
1 parent 7fe8b2a commit b06cda0

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎Zend/Zend.m4‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,24 @@ AS_VAR_IF([php_cv_have_global_register_vars], [yes],
331331
])
332332
AC_MSG_CHECKING([whether to enable global register variables support])
333333
AC_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

336354
dnl

‎build/ltmain.sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7705,6 +7705,7 @@ func_mode_link ()
77057705
# -tp=* Portland pgcc target processor selection
77067706
# --sysroot=* for sysroot support
77077707
# -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7708+
# -ffixed-*, -fno-lto GCC LTO register reservations and cancellation
77087709
# -specs=* GCC specs files
77097710
# -stdlib=* select c++ std lib with clang
77107711
# -fdiagnostics-color* simply affects output
@@ -7725,6 +7726,7 @@ func_mode_link ()
77257726
-64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
77267727
-t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
77277728
-O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-no-canonical-prefixes| \
7729+
-ffixed-*|-fno-lto| \
77287730
-stdlib=*|-rtlib=*|--unwindlib=*| \
77297731
-specs=*|-fsanitize=*|-fno-sanitize*|-shared-libsan|-static-libsan| \
77307732
-ffile-prefix-map=*|-fdebug-prefix-map=*|-fmacro-prefix-map=*|-fprofile-prefix-map=*| \

0 commit comments

Comments
 (0)