https://gcc.gnu.org/g:a1396b605a77c7f2d2112f2989f8984ca1afa286
commit r17-5426-ga1396b605a77c7f2d2112f2989f8984ca1afa286 Author: Stefan Schulze Frielinghaus <[email protected]> Date: Wed Oct 21 09:29:04 2026 +0200 s390: Fix duplicated __fentry__ call During the removal of -m31, the else branch for TARGET_64BIT in function s390_function_profiler() was rewritten incorrectly, i.e., previously we had if (flag_fentry) { ... } else if (TARGET_64BIT) { if (flag_nop_mcount) ... else { ... } } else { ... } and with r17-2272 if (flag_fentry) { ... } if (flag_nop_mcount) ... else { ... } Therefore, the function emits for -mfentry one call to __fentry__ and then falls through into the sequence which is meant for -mno-fentry. Fixed by making the -mnop-mcount/default handling an else branch of the flag_fentry case. gcc/ChangeLog: * config/s390/s390.cc (s390_function_profiler): Make the -mnop-mcount/default handling an else branch of the flag_fentry case. gcc/testsuite/ChangeLog: * gcc.target/s390/mfentry-m64.c: Test for exactly one call. Diff: --- gcc/config/s390/s390.cc | 3 +-- gcc/testsuite/gcc.target/s390/mfentry-m64.c | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc index ba576680229a..61ca55161f9a 100644 --- a/gcc/config/s390/s390.cc +++ b/gcc/config/s390/s390.cc @@ -14109,8 +14109,7 @@ s390_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED) else output_asm_insn ("brasl\t0,%2%K2", op); } - - if (flag_nop_mcount) + else if (flag_nop_mcount) output_asm_nops ("-mnop-mcount", /* stg */ 3 + /* brasl */ 3 + /* lg */ 3); else diff --git a/gcc/testsuite/gcc.target/s390/mfentry-m64.c b/gcc/testsuite/gcc.target/s390/mfentry-m64.c index aa3fc81248f2..d5020050469c 100644 --- a/gcc/testsuite/gcc.target/s390/mfentry-m64.c +++ b/gcc/testsuite/gcc.target/s390/mfentry-m64.c @@ -6,3 +6,12 @@ profileme (void) { /* { dg-final { scan-assembler "brasl\t0,__fentry__" } } */ } + +/* During the removal of -m31, the else branch for TARGET_64BIT in function + s390_function_profiler() was rewritten incorrectly, causing to emit two + __fentry__ calls. Verify that with -mfentry exactly one call to __fentry__ + is emitted and that -mno-nop-mcount doesn't lead to a sequence which saves + %r14 and a call. */ +/* { dg-final { scan-assembler-times "__fentry__" 1 } } */ +/* { dg-final { scan-assembler-times "brasl\t" 1 } } */ +/* { dg-final { scan-assembler-not "stg\t%r14,8\\(%r15\\)" } } */
