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.
Ok for trunk?
Rainer
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
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.
# HG changeset patch
# Parent 9108917225830aef7b0d8fba91f26fafdd0efbd0
libgcc: Fix _mcount on 32-bit Solaris/x86
diff --git a/libgcc/config/sol2/gmon.c b/libgcc/config/sol2/gmon.c
--- 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
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
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