This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

patch for MIPS profiling in mips.h


	I'd really appreciate it if someone would please take
this patch against gcc/config/mips/mips.h. I posted it three
weeks ago, Chris Demetriou kindly formatted it more formally for
me, but I got no replies. It has been in use within the NetBSD
community for over a year, and we're trying to feed the fix back.

	The current mcount code is broken. It generates "jal
_mcount", followed by a "subu sp,sp,8", where the subu is
intended to be in the branch delay slot. It isn't. "jal" is an
assembler macro which is expanded, thus pushing the following
instruction out of the delay slot in some cases involving PIC
code.

	The simplest fix is to swap the jal and subu, and follow
the jal with a nop. This will work regardless of whether the
assembler expands the jal. The change is really simple, and
clearly non-harmful.

	Thanks!
	-- Ethan



2000-05-09  Ethan Solomita  ethan@cs.columbia.edu

        * config/mips/mips.h (FUNCTION_PROFILER): jump after
        subtract, since jal is an assembler macro which doesn't
        handle branch delay slot properly.




===================================================================
Index: mips.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/mips/mips.h,v
retrieving revision 1.97
diff -c -r1.97 mips.h
*** mips.h      2000/04/19 15:39:16     1.97
--- mips.h      2000/05/09 21:01:07
***************
*** 2574,2586 ****
    fprintf (FILE, "\t.set\tnoat\n");                                   \
    fprintf (FILE, "\tmove\t%s,%s\t\t# save current return address\n",  \
           reg_names[GP_REG_FIRST + 1], reg_names[GP_REG_FIRST + 31]);  \
-   fprintf (FILE, "\tjal\t_mcount\n");                                 \
    fprintf (FILE,                                                      \
           "\t%s\t%s,%s,%d\t\t# _mcount pops 2 words from  stack\n",    \
           TARGET_64BIT ? "dsubu" : "subu",                             \
           reg_names[STACK_POINTER_REGNUM],                             \
           reg_names[STACK_POINTER_REGNUM],                             \
           Pmode == DImode ? 16 : 8);                                   \
    fprintf (FILE, "\t.set\treorder\n");                                        \
    fprintf (FILE, "\t.set\tat\n");                                     \
  }
--- 2574,2587 ----
    fprintf (FILE, "\t.set\tnoat\n");                                   \
    fprintf (FILE, "\tmove\t%s,%s\t\t# save current return address\n",  \
           reg_names[GP_REG_FIRST + 1], reg_names[GP_REG_FIRST + 31]);  \
    fprintf (FILE,                                                      \
           "\t%s\t%s,%s,%d\t\t# _mcount pops 2 words from  stack\n",    \
           TARGET_64BIT ? "dsubu" : "subu",                             \
           reg_names[STACK_POINTER_REGNUM],                             \
           reg_names[STACK_POINTER_REGNUM],                             \
           Pmode == DImode ? 16 : 8);                                   \
+   fprintf (FILE, "\tjal\t_mcount\n");                                 \
+   fprintf (FILE, "\tnop\n");                                          \
    fprintf (FILE, "\t.set\treorder\n");                                        \
    fprintf (FILE, "\t.set\tat\n");                                     \
  }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]