From 842db592751e121068a3676817c54dd5b229dc56 Mon Sep 17 00:00:00 2001 From: Danny Smith Date: Thu, 16 Jun 2005 12:14:21 +0000 Subject: [PATCH] * profile/profile.h (_MCOUNT_CALL): Define as regparm(2) (_MCOUNT_DECL): Use it. (MCOUNT): Save and restore eax, ecx, edx registers. * profile/mcount.c (_mcount): ANSI-fy. --- winsup/mingw/ChangeLog | 7 +++++++ winsup/mingw/profile/mcount.c | 5 ++--- winsup/mingw/profile/profile.h | 28 +++++++++++++++++++++++----- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/winsup/mingw/ChangeLog b/winsup/mingw/ChangeLog index 9aeb29278..a2e6eefb9 100644 --- a/winsup/mingw/ChangeLog +++ b/winsup/mingw/ChangeLog @@ -1,3 +1,10 @@ +2005-06-16 Danny Smith + + * profile/profile.h (_MCOUNT_CALL): Define as regparm(2) + (_MCOUNT_DECL): Use it. + (MCOUNT): Save and restore eax, ecx, edx registers. + * profile/mcount.c (_mcount): ANSI-fy. + 2005-06-16 Danny Smith * include/_mingw.h (__MINGW_GNUC_PREREQ): Define. Use to diff --git a/winsup/mingw/profile/mcount.c b/winsup/mingw/profile/mcount.c index 296f8c891..9f1736d3b 100644 --- a/winsup/mingw/profile/mcount.c +++ b/winsup/mingw/profile/mcount.c @@ -61,9 +61,8 @@ static char rcsid[] = "$OpenBSD: mcount.c,v 1.6 1997/07/23 21:11:27 kstailey Exp * both frompcindex and frompc. Any reasonable, modern compiler will * perform this optimization. */ -//_MCOUNT_DECL __P((u_long frompc, u_long selfpc)); -_MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */ - register u_long frompc, selfpc; +/* _mcount; may be static, inline, etc */ +_MCOUNT_DECL (u_long frompc, u_long selfpc) { register u_short *frompcindex; register struct tostruct *top, *prevtop; diff --git a/winsup/mingw/profile/profile.h b/winsup/mingw/profile/profile.h index 6c198d742..d1de0f98e 100644 --- a/winsup/mingw/profile/profile.h +++ b/winsup/mingw/profile/profile.h @@ -39,27 +39,45 @@ * 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 -#define _MCOUNT_DECL static inline void _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() \ { \ - u_long 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 ("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"); \ } - -- 2.43.5