[Bug build/33121] FAIL: gmon/tst-gmon-gprof with GCC 16 and --enable-stack-protector=all

hjl.tools at gmail dot com sourceware-bugzilla@sourceware.org
Wed Jul 2 05:36:46 GMT 2025


https://sourceware.org/bugzilla/show_bug.cgi?id=33121

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|MOVED                       |---
                 CC|                            |cuilili8868 at gmail dot com,
                   |                            |fweimer at redhat dot com

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
Separate shrink wrapping doesn't work well with gmon since when separate shrink
wrapping is enabled, NOTE_INSN_PROLOGUE_END may not represent the entry bb. One
solution is to place the mcount call before the prologue with:

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 60ca9360ab3..b5bf77dc00a 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -493,7 +493,7 @@ ix86_using_red_zone (void)
 static bool
 ix86_profile_before_prologue (void)
 {
-  return flag_fentry != 0;
+  return (TARGET_64BIT && SHRINK_WRAPPING_ENABLED) || flag_fentry != 0;
 }

 /* Update register usage after having seen the compiler flags.  */

With this, GCC 16 will generate:

f1:
.LFB0:
        .cfi_startproc
1:      call    mcount
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp

which doesn't work with sysdeps/x86_64/_mcount.S:

        /* Setup parameter for __mcount_internal.  */
        /* selfpc is the return address on the stack.  */
        movq    56(%rsp),%rsi
        /* Get frompc via the frame pointer.  */
        movq    8(%rbp),%rdi
        call C_SYMBOL_NAME(__mcount_internal)

which expects that the mount call is made after "push %rbp; mov %rsp,%rbp".

Disable separate shrink wrapping with -pg may skew the profiling data, making
PGO less effective.  This glibc change

diff --git a/sysdeps/x86_64/_mcount.S b/sysdeps/x86_64/_mcount.S
index 85500a2646..ed9cf9e12c 100644
--- a/sysdeps/x86_64/_mcount.S
+++ b/sysdeps/x86_64/_mcount.S
@@ -45,8 +45,16 @@ ENTRY(_mcount)
   /* Setup parameter for __mcount_internal.  */
   /* selfpc is the return address on the stack.  */
   movq  56(%rsp),%rsi
+  /* If mount is called just before "push %rbp; mov %rsp,%rbp",
+     get the frompc via the stack pointer.  */
+  cmpl  $0xe5894855,(%rsi)
+  jne   1f
+  movq  (56+8)(%rsp),%rdi
+  jmp   2f
+1:
   /* Get frompc via the frame pointer.  */
   movq  8(%rbp),%rdi
+2:
   call C_SYMBOL_NAME(__mcount_internal)
   /* Pop the saved registers.  Please note that `mcount' has no
      return value.  */

should make glibc compatible for both the mcount call made before and after
"push %rbp; mov %rsp,%rbp".

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list