Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Zend/Zend.m4
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,24 @@ 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*|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"])],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I m certain powerpc is correct, I was digging a bit about riscv64 and it looks correct too according to this doc, those registers are equivalent to s2/s3 confirmed with the gcc header (see REGISTER_NAMES/ADDITIONAL_REGISTER_NAMES).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I certainly hope they're correct, because otherwise php would crash, I copied them from

# if defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(i386)
😄

[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])])
])
])
])

dnl
Expand Down
2 changes: 2 additions & 0 deletions build/ltmain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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| \
Comment on lines +1692 to +1693

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid modifying ltmain.sh directly as it's a generated/3rd party file. The version on master is much more recent, so it's possible that these changes are not necessary on that branch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes are required there too, -ffixed is missing. (-fno-lto isn't required, I've only added it because -flto is in the line above, so passing "-flto -fno-lto" would create unexpected outcomes)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petk @NattyNarwhal do you have thoughts about the ltmain.sh changes?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next time libtool gets updated, it'll get clobbered. If this is a bug in libtool, we could carry it locally (and ship patches that could be applied), but you should probably seek to upstream it there.

@henderkes henderkes Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not sure how to submit a patch to libtool:
image

Should I file a bug report instead and hope someone tends to it?

-64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
-t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*)

Expand Down
Loading