Subject: profiling breakage
To: None <port-alpha@netbsd.org>
From: Matthias Drochner <M.Drochner@fz-juelich.de>
List: port-alpha
Date: 01/25/2005 20:00:51
This is a multipart MIME message.

--==_Exmh_76368599746740
Content-Type: text/plain; charset=us-ascii


Hi -
just had a look why some programs crash if compiled for
profiling (-gp) on alpha.
There are 2 problems:
-The GP calculation as done by means of the LDGP macro (defined
 in asm.h) gets confused because that macro assumes that it is the
 first thing in the function. With profiling, this doesn't hold.
-The MCOUNT macro (also in asm.h) expands to code which clobbers
 "pv".

There is also one thing which looks strange for me, but this might
be due to lack of understanding on my side: the _mcount function
is always called through GP, but without setting GP before.
It might be just the fact that noone has tested a program too
large for a single GP. (or is there some compiler magic making
sure that the _mcount entry is always at a fixed position?)

One idea to fix this is to put the LDGP call into at least
the NESTED entry, before the MCOUNT. And remove all explicite
LDGP calls in assembler code. I had some success with the
appended patch. (actually  it makes a profiled swapcontext()
work which is the only function in libc which declares itself
NESTED)
Since this would change the semantics of the NESTED macro
I'm asking here whether there are conventions or standards
which would possibly be violated.

If it turned out that the _mcount call w/o setting GP before
is not really a problem, we could also just adjust "pv"
within the MCOUNT macro, so user code would get the illusion
to start after the MCOUNT.

comments?

best regards
Matthias



--==_Exmh_76368599746740
Content-Type: text/plain ; name="alpha-gprof.txt"; charset=us-ascii
Content-Description: alpha-gprof.txt
Content-Disposition: attachment; filename="alpha-gprof.txt"

--- asm.h.~1.27.~	Thu Dec  4 19:53:32 2003
+++ asm.h	Tue Jan 25 18:55:05 2005
@@ -230,7 +230,8 @@
 #else
 #define MCOUNT							\
 	.set noat;						\
-	jsr	at_reg,_mcount;					\
+	lda at_reg,_mcount;					\
+	jsr at_reg,(at_reg),_mcount;				\
 	.set at
 #endif
 /*
@@ -342,6 +343,7 @@ _name_:
 _name_:;							\
 	.frame	sp,_framesize_,_pc_reg_;			\
 	.livereg _i_mask_,_f_mask_;				\
+	LDGP(pv);						\
 	MCOUNT
 /* should have been
 	.proc	_name_,_n_args_;				\

--==_Exmh_76368599746740--