This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] fix profiling


Long story short: some asm()s have missing volatile modifiers.

The mcount() profiling hook is implemented with a short wrapper around
the actual mcount function.  The wrapper's purpose is to get the pc of
the caller as well as the return value of the caller's frame, and pass
those on as arguments to the actual mcount function.  Because it's a
local static function the compiler inlines all this into one function. 
The problem is these asm()s aren't marked volatile and so the compiler
freely rearranges them and interleaves them with the prologue of the
inlined function.  Thus mcount gets some bogus value for the pc and
ignores the data because it's not in the valid range of .text.

Since this code is lifted from the BSDs I did check that this change was
made there as well, e.g.
<http://www.openbsd.org/cgi-bin/cvsweb/src/sys/arch/i386/include/profile.h?rev=1.10&content-type=text/x-cvsweb-markup>.

Unfortuantely there seems to also be some bitrot in the gprof side, as
the codepath to read BSD style gmon.out files is also broken.  I've
posted a separate patch to the binutils list.  With both these fixes,
gprof again works with Cygwin.

Brian
2008-08-04  Brian Dessent  <brian@dessent.net>

	* config/i386/profile.h (mcount): Mark asms volatile.

Index: config/i386/profile.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/config/i386/profile.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 profile.h
--- config/i386/profile.h	17 Feb 2000 19:38:31 -0000	1.1.1.1
+++ config/i386/profile.h	5 Aug 2008 05:02:25 -0000
@@ -48,11 +48,11 @@ mcount()								\
 	 *								\
 	 * selfpc = pc pushed by mcount call				\
 	 */								\
-	__asm("movl 4(%%ebp),%0" : "=r" (selfpc));			\
+	__asm __volatile ("movl 4(%%ebp),%0" : "=r" (selfpc));		\
 	/*								\
 	 * frompcindex = pc pushed by call into self.			\
 	 */								\
-	__asm("movl (%%ebp),%0;movl 4(%0),%0" : "=r" (frompcindex));	\
+	__asm __volatile ("movl (%%ebp),%0;movl 4(%0),%0" : "=r" (frompcindex));\
 	_mcount(frompcindex, selfpc);					\
 }
 

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