x86: Avoid vector/r16-r31 registers and memcpy/memset in mcount_internal

Since mcount_internal is called from mcount/__fentry__ which preserve
only RAX, RCX, RDX, RSI, RDI, R8 and R9, compile mcount.c with

-fno-tree-loop-distribute-patterns -mgeneral-regs-only -mno-apxf

to void vector/r16-r31 registers and memcpy/memset in mcount_internal.
This fixes BZ #33134.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Andreas K. Huettel <dilfridge@gentoo.org>
This commit is contained in:
H.J. Lu 2025-07-08 06:38:38 +08:00
parent f33bb12366
commit 7130c2ae97
3 changed files with 11 additions and 2 deletions

View File

@ -62,8 +62,9 @@ tests-static += tst-gmon-static-pie
endif
endif
# The mcount code won't work without a frame pointer.
CFLAGS-mcount.c := -fno-omit-frame-pointer
# The mcount code won't work without a frame pointer nor when memcpy or
# memset are called.
CFLAGS-mcount.c := -fno-omit-frame-pointer -fno-tree-loop-distribute-patterns
CFLAGS-tst-gmon.c := -fno-omit-frame-pointer -pg
tst-gmon-no-pie = yes

View File

@ -137,6 +137,10 @@ tst-tls23-mod.so-no-z-defs = yes
$(objpfx)tst-tls23-mod.so: $(libsupport)
endif
ifeq ($(subdir),gmon)
CFLAGS-mcount.c += -mgeneral-regs-only
endif
ifeq ($(subdir),math)
tests += \
tst-ldbl-nonnormal-printf \

View File

@ -19,6 +19,10 @@ sysdep_routines += _mcount
# recursive calls when ENTRY is used. Just copy the normal static
# object.
sysdep_noprof += _mcount
ifeq (yes,$(have-x86-apx))
CFLAGS-mcount.c += -mno-apxf
endif
endif
ifeq ($(subdir),string)