Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* profiling bug on alpha-linux
@ 1996-04-05  6:08 Richard Henderson
  1996-04-05 10:20 ` Linus Torvalds
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 1996-04-05  6:08 UTC (permalink / raw)


Leaf functions on alpha-linux improperly overwrite the
return address register ($26) when profiling is on.

Case in point, the null function `foo(){ }' compiles,
with -O -p, to

------------------
        .ent foo
foo:
        ldgp $29,0($27)
foo..ng:
        .frame $30,0,$26,0
        .prologue 1
.data
        .align 3
$P32:
        .quad 0
.text
        lda $27,_mcount
        jsr $26,($27),_mcount
        ldgp $29,0($26)
        ret $31,($26),1
        .end foo
------------------

Note that foo's return address is not saved before the call
to _mcount kills it.  The fix, of course, is to always save
the return address register when profiling is on.

r~

-----
Fri Apr  5 01:03:02 1996  Richard Henderson  <rth@tamu.edu>

        * alpha.c (alpha_sa_size): Do not elide saving $ra when
        profiling is on.  The call to _mcount is going to kill it.
        (output_prolog): Continued.
        (output_epilog): Continued.

Index: alpha.c
===================================================================
RCS file: /home/richard/Repository/cygnus/gcc/config/alpha/alpha.c,v
retrieving revision 1.1.1.1.2.1
retrieving revision 1.1.1.1.2.2
diff -u -r1.1.1.1.2.1 -r1.1.1.1.2.2
--- alpha.c     1996/03/26 02:39:40     1.1.1.1.2.1
+++ alpha.c     1996/04/05 05:49:45     1.1.1.1.2.2
@@ -1335,7 +1335,7 @@ alpha_sa_size ()
 
   /* If some registers were saved but not reg 26, reg 26 must also
      be saved, so leave space for it.  */
-  if (size != 0 && ! regs_ever_live[26])
+  if ((size != 0 || profile_flag) && ! regs_ever_live[26])
     size++;
 
   /* Our size must be even (multiple of 16 bytes).  */
@@ -1599,7 +1599,7 @@ output_prolog (file, size)
           frame_size, current_function_pretend_args_size);
     
   /* Save register 26 if any other register needs to be saved.  */
-  if (sa_size != 0)
+  if (sa_size != 0 || profile_flag)
     {
       reg_mask |= 1 << 26;
       fprintf (file, "\tstq $26,%d($30)\n", reg_offset);
@@ -1684,7 +1684,7 @@ output_epilog (file, size)
 
       /* Restore all the registers, starting with the return address
         register.  */
-      if (sa_size != 0)
+      if (sa_size != 0 || profile_flag)
        {
          fprintf (file, "\tldq $26,%d($30)\n", reg_offset);
          reg_offset += 8;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: profiling bug on alpha-linux
@ 1996-04-05  6:12 David Mosberger
  0 siblings, 0 replies; 3+ messages in thread
From: David Mosberger @ 1996-04-05  6:12 UTC (permalink / raw)


No, it's really the profiling code that's broken.  I fixed it in a way that
is compatible with the calling convention of OSF/1.    The mcount that comes with
the (old) Linux libc is also completely broken.  I'll send you the fixes as
soon as I can (ping me if you don't hear from me by
Sunday evening).

	--advid

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: profiling bug on alpha-linux
  1996-04-05  6:08 profiling bug on alpha-linux Richard Henderson
@ 1996-04-05 10:20 ` Linus Torvalds
  0 siblings, 0 replies; 3+ messages in thread
From: Linus Torvalds @ 1996-04-05 10:20 UTC (permalink / raw)


On Fri, 5 Apr 1996, Richard Henderson wrote:
> 
> Leaf functions on alpha-linux improperly overwrite the
> return address register ($26) when profiling is on.

Umm.. Wouldn't it be better to use another register for the return 
address when calling _mcount? You could use one of the normal scratch 
registers for it, and then you wouldn't need to save anything.

Of course, that would also mean that the "_mcount" function couldn't be 
written in C (or at least not compiled with gcc), but I'd assume that you 
wouldn't want to do that anyway?

> Case in point, the null function `foo(){ }' compiles,
> with -O -p, to
> 
> ------------------
>         .ent foo
> foo:
>         ldgp $29,0($27)
> foo..ng:
>         .frame $30,0,$26,0
>         .prologue 1
> .data
>         .align 3
> $P32:
>         .quad 0
> .text
>         lda $27,_mcount
>         jsr $26,($27),_mcount
>         ldgp $29,0($26)
>         ret $31,($26),1
>         .end foo
> ------------------
> 
> Note that foo's return address is not saved before the call
> to _mcount kills it.  The fix, of course, is to always save
> the return address register when profiling is on.

What I'd suggest would result in something like

	lda $27,_mcount
	jsr $XX,($27),_mcount
	ldgp $29,0($XX)

where XX is some scratch register (and _mcount returns using a 
sequence of "ret $31,($XX),1"). Kind of like the alternate call sequence 
used by the integer division stuff..

Of course, your fix looks fine too, and I guess this isn't really 
performance-critical anyway.

		Linus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-04-05 10:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-04-05  6:08 profiling bug on alpha-linux Richard Henderson
1996-04-05 10:20 ` Linus Torvalds
  -- strict thread matches above, loose matches on Subject: below --
1996-04-05  6:12 David Mosberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox