https://gcc.gnu.org/g:8ceb5e4a6020d16a251c14efe5b7d2b3b88dfec9

commit r17-1566-g8ceb5e4a6020d16a251c14efe5b7d2b3b88dfec9
Author: Rainer Orth <[email protected]>
Date:   Mon Jun 15 14:18:59 2026 +0200

    libgcc: Fix _mcount on 32-bit Solaris/x86 [PR38239]
    
    Profiling on 32-bit Solaris/x86 has been broken since
    
    Save call-clobbered registers in _mcount on 32-bit Solaris/x86 (PR 
target/38239)
    https://gcc.gnu.org/pipermail/gcc-patches/2016-March/444175.html
    
    This was only recently noticed when setting up a Solaris/i386 binutils
    buildbot.
    
    Since internal_mcount is a regular function on Solaris, the selfpc and
    frompcindex args need to pushed to the stack.  Besides, the patch fixes
    a couple of warnings in gmon.c
    
    Bootstrapped withoug regressions on i386-pc-solaris2.11.  With this
    patch, the binutils gprof tests PASS.
    
    2026-06-12  Rainer Orth  <[email protected]>
    
            libgcc:
            PR target/38239
            * config/sol2/gmon.c [__i386__] (_mcount): Pass selfpc, frompc to
            internal_mcount.
            (internal_mcount): Remove already_setup.
            Remove obsolete comment.
            (moncontrol): Disable profil(2) deprecation warning.

Diff:
---
 libgcc/config/sol2/gmon.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libgcc/config/sol2/gmon.c b/libgcc/config/sol2/gmon.c
index 26c38ca99eb2..28964c44d51e 100644
--- a/libgcc/config/sol2/gmon.c
+++ b/libgcc/config/sol2/gmon.c
@@ -225,9 +225,12 @@ asm(".globl _mcount\n"
     "  pushl   %eax\n"
     "  pushl   %ecx\n"
     "  pushl   %edx\n"
-    "  movl    12(%esp), %edx\n"
-    "  movl    4(%ebp), %eax\n"
+    /* Get SELFPC (pushed by the call to this function) and
+       FROMPCINDEX (via the frame pointer).  */
+    "  pushl   4(%ebp)\n"
+    "  pushl   16(%esp)\n"
     "  call    internal_mcount\n"
+    "  addl    $8, %esp\n"
     "  popl    %edx\n"
     "  popl    %ecx\n"
     "  popl    %eax\n"
@@ -311,10 +314,6 @@ internal_mcount (char *selfpc, unsigned short *frompcindex)
   struct tostruct *top;
   struct tostruct *prevtop;
   long toindex;
-  static char already_setup;
-
-/* Only necessary without the Solaris CRTs or a proper gcrt1.o, otherwise
-   crtpg.o or gcrt1.o take care of that.
 
   /* Check that we are profiling and that we aren't recursively invoked.  */
   if (profiling) {
@@ -398,6 +397,9 @@ internal_mcount (char *selfpc, unsigned short *frompcindex)
   goto out;
 }
 
+/* Disable profil(2) deprecation warning.  */
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
 /* Control profiling.  Profiling is what mcount checks to see if all the
    data structures are ready.  */
 static void

Reply via email to