From owner-freebsd-current@FreeBSD.ORG Thu Nov 29 20:24:52 2007 Return-Path: Delivered-To: freebsd-current@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 797D616A41A for ; Thu, 29 Nov 2007 20:24:52 +0000 (UTC) (envelope-from luoqi@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 6A9A213C4D9; Thu, 29 Nov 2007 20:24:52 +0000 (UTC) (envelope-from luoqi@FreeBSD.org) Received: from freefall.freebsd.org (luoqi@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id lATKOqDA000770; Thu, 29 Nov 2007 20:24:52 GMT (envelope-from luoqi@freefall.freebsd.org) Received: (from luoqi@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id lATKOq5R000769; Thu, 29 Nov 2007 20:24:52 GMT (envelope-from luoqi) Date: Thu, 29 Nov 2007 20:24:52 GMT From: Luoqi Chen Message-Id: <200711292024.lATKOq5R000769@freefall.freebsd.org> To: freebsd-current@FreeBSD.org, youshi10@u.washington.edu Cc: Subject: RE: gprof's broken in 7-CURRENT X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Nov 2007 20:24:52 -0000 > And to think that I mentioned this problem 5-6 months ago with gcc 4.2.x > and now it finally gets publicity... Did I just hear someone volunteered to be a guinea pig? Garrett, would you like to try out my fix? It's actually quite simple, Index: profile.h =================================================================== RCS file: /home/ncvs/src/sys/i386/include/profile.h,v retrieving revision 1.42 diff -u -r1.42 profile.h --- profile.h 28 Oct 2006 11:03:03 -0000 1.42 +++ profile.h 29 Nov 2007 20:07:15 -0000 @@ -115,7 +115,17 @@ void \ mcount() \ { \ - uintfptr_t selfpc, frompc; \ + uintfptr_t selfpc, frompc, ecx; \ + /* \ + * In gcc 4.2, ecx could be used in the caller as arg pointer \ + * if stack realignment option is set (-mstackrealign) or \ + * if the caller has the force_align_arg_pointer atrribute \ + * (stack realignment is ALWAYS on for main). Preserve ecx \ + * here. Use volatile to prevent this statement from being \ + * rescheduled with the next two, just in case the compiler \ + * decides to use ecx for either selfpc or frompc. \ + */ \ + __asm __volatile("movl %%ecx,%0" : "=m" (ecx)); \ /* \ * Find the return address for mcount, \ * and the return address for mcount's caller. \ @@ -132,6 +142,7 @@ __asm("movl (%%ebp),%0" : "=r" (frompc)); \ frompc = ((uintfptr_t *)frompc)[1]; \ _mcount(frompc, selfpc); \ + __asm __volatile("movl %0,%%ecx" : : "m" (ecx)); \ } #else /* !__GNUCLIKE_ASM */ #define MCOUNT This file is in the kernel tree, but the change only affects libc build. If you don't want to redo a world build, you may copy the patched profile.h to /usr/include/machine and "make all install" inside /usr/src/lib/libc. Then re-link -pg compiled code and try it out. Thanks -lq