* @(#)profile.h 8.1 (Berkeley) 6/11/93
*/
-#define _MCOUNT_DECL static inline void _mcount
+/*
+ * This file is taken from Cygwin distribution. Please keep it in sync.
+ * The differences should be within __MINGW32__ guard.
+ */
+/* If compiler doesn't inline, at least avoid passing args on the stack. */
+#define _MCOUNT_CALL __attribute__ ((regparm (2)))
+#define _MCOUNT_DECL static __inline__ void _MCOUNT_CALL _mcount
+
+/* FIXME: This works, but it would be cleaner to convert mcount into an
+ assembler stub that calls an extern _mcount.
+ Older versions of GCC (pre-4.1) will still fail with regparm since the
+ compiler used %edx to store an unneeded counter variable. */
#define MCOUNT \
void \
mcount() \
{ \
- int selfpc, frompcindex; \
+ u_long selfpc, frompcindex; \
+ /* \
+ * Save registers, since this may be called from \
+ * the prologue of a regparm function. \
+ */ \
+ __asm __volatile__ ("pushl %eax\n\t" \
+ "pushl %ecx\n\t" \
+ "pushl %edx"); \
/* \
* find the return address for mcount, \
* and the return address for mcount's caller. \
* \
* selfpc = pc pushed by mcount call \
*/ \
- __asm __volatile ("movl 4(%%ebp),%0" : "=r" (selfpc)); \
+ /* __asm ("movl 4(%%ebp),%0" : "=r" (selfpc)); */ \
+ selfpc = (u_long) __builtin_return_address (0); \
/* \
* frompcindex = pc pushed by call into self. \
*/ \
- __asm __volatile ("movl (%%ebp),%0;movl 4(%0),%0" : "=r" (frompcindex));\
+ /* __asm ("movl (%%ebp),%0;movl 4(%0),%0" : "=r" (frompcindex)); */ \
+ frompcindex = (u_long) __builtin_return_address (1); \
_mcount(frompcindex, selfpc); \
+ /* \
+ * Restore registers. \
+ */ \
+ __asm __volatile__ ("popl %edx\n\t" \
+ "popl %ecx\n\t" \
+ "popl %eax"); \
}
-