From assar@sics.se  Sat Jan  9 20:15:27 1999
Received: from assaris2.pdc.kth.se (assaris2.pdc.kth.se [130.237.221.57])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id UAA24984
          for <FreeBSD-gnats-submit@freebsd.org>; Sat, 9 Jan 1999 20:15:26 -0800 (PST)
          (envelope-from assar@sics.se)
Received: (from assar@localhost) by assaris2.pdc.kth.se (8.9.1/8.7.3) id FAA65913; Sun, 10 Jan 1999 05:16:37 +0100 (CET)
Message-Id: <199901100416.FAA65913@assaris2.pdc.kth.se>
Date: Sun, 10 Jan 1999 05:16:37 +0100 (CET)
From: assar@sics.se
To: FreeBSD-gnats-submit@freebsd.org
Subject: profiling does not work on elf kernels
X-Send-Pr-Version: 3.2

>Number:         9413
>Category:       kern
>Synopsis:       profiling does not work with elf kernels
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bde
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jan  9 20:20:00 PST 1999
>Closed-Date:    Tue Feb 1 20:15:10 PST 2000
>Last-Modified:  Tue Feb  1 20:19:47 PST 2000
>Originator:     Assar Westerlund
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
none
>Environment:

>Description:

When configuring a kernel with profiling (`config -p'), it fails to
build due to duplicate and unresolved symbols.

In the aout-world it looks like this (where if_ex.o is a random object file):

mcount.o
00000000 T _mcount
prof_machdep.o
00000000 T __mcount
         U _mcount
00000010 T mcount
if_ex.o
         U mcount

But in the elf world there's some confusion as to what the different
functions should be called.

mcount.o
00000000 T mcount
prof_machdep.o
0000002c t Lmcount_exit
00000000 T __mcount
         U _mcount
00000010 T mcount
if_ex.o
         U .mcount

>How-To-Repeat:

config -p GENERIC
cd ../../GENERIC
make depend all

>Fix:

Index: i386/i386/exception.s
===================================================================
RCS file: /src/fbsd-repository/src/sys/i386/i386/exception.s,v
retrieving revision 1.55
diff -u -w -r1.55 exception.s
--- exception.s	1998/08/10 19:41:07	1.55
+++ exception.s	1999/01/10 04:09:57
@@ -204,7 +204,7 @@
 	movl	%ax,%es
 	FAKE_MCOUNT(12*4(%esp))
 calltrap:
-	FAKE_MCOUNT(_btrap)		/* init "from" _btrap -> calltrap */
+	FAKE_MCOUNT(CNAME(btrap))	/* init "from" _btrap -> calltrap */
 	MPLOCKED incl _cnt+V_TRAP
 	ALIGN_LOCK
 	ECPL_LOCK
Index: i386/isa/ipl.s
===================================================================
RCS file: /src/fbsd-repository/src/sys/i386/isa/ipl.s,v
retrieving revision 1.24
diff -u -w -r1.24 ipl.s
--- ipl.s	1998/08/11 17:01:32	1.24
+++ ipl.s	1999/01/10 04:11:15
@@ -111,7 +111,7 @@
 #ifdef SMP
 	TEST_CIL
 #endif
-	FAKE_MCOUNT(_bintr)		/* init "from" _bintr -> _doreti */
+	FAKE_MCOUNT(CNAME(bintr))	/* init "from" _bintr -> _doreti */
 	addl	$4,%esp			/* discard unit number */
 	popl	%eax			/* cpl or cml to restore */
 doreti_next:
Index: i386/isa/prof_machdep.c
===================================================================
RCS file: /src/fbsd-repository/src/sys/i386/isa/prof_machdep.c,v
retrieving revision 1.11
diff -u -w -r1.11 prof_machdep.c
--- prof_machdep.c	1998/12/14 18:21:34	1.11
+++ prof_machdep.c	1999/01/10 04:12:59
@@ -48,6 +48,8 @@
 #endif
 #include <i386/isa/timerreg.h>
 
+#include <machine/asmacros.h>
+
 #ifdef GUPROF
 #define	CPUTIME_CLOCK_UNINITIALIZED	0
 #define	CPUTIME_CLOCK_I8254		1
@@ -77,7 +79,7 @@
 	#							\n\
 	# Check that we are profiling.  Do it early for speed.	\n\
 	#							\n\
-	cmpl	$GMON_PROF_OFF,__gmonparam+GM_STATE		\n\
+	cmpl	$GMON_PROF_OFF," __XSTRING(CNAME(_gmonparam)) "+GM_STATE		\n\
  	je	Lmcount_exit					\n\
  	#							\n\
  	# __mcount is the same as mcount except the caller 	\n\
@@ -88,9 +90,9 @@
  	jmp	Lgot_frompc					\n\
  								\n\
  	.align	4,0x90						\n\
- 	.globl	mcount						\n\
-mcount:								\n\
-	cmpl	$GMON_PROF_OFF,__gmonparam+GM_STATE		\n\
+ 	.globl	" __XSTRING(HIDENAME(mcount)) "			\n\
+" __XSTRING(HIDENAME(mcount)) ":				\n\
+	cmpl	$GMON_PROF_OFF," __XSTRING(CNAME(_gmonparam)) "+GM_STATE		\n\
 	je	Lmcount_exit					\n\
 	#							\n\
 	# The caller's stack frame has already been built, so	\n\
@@ -109,7 +111,7 @@
 	pushl	%eax						\n\
 	pushl	%edx						\n\
 	cli							\n\
-	call	_mcount						\n\
+	call	" __XSTRING(CNAME(mcount)) "			\n\
 	addl	$8,%esp						\n\
 	popfl							\n\
 Lmcount_exit:							\n\
>Release-Note:
>Audit-Trail:

From: Darrell Anderson <anderson@cs.duke.edu>
To: freebsd-gnats-submit@freebsd.org, assar@sics.se
Cc:  
Subject: Re: kern/9413: profiling does not work with elf kernels
Date: Mon, 08 Mar 1999 18:57:15 -0500

 I've experience this problem and successfully used the fix.
 
 -Darrell
 --
 Department of Computer Science, Duke University, Durham, NC 27708-0129
 Darrell Anderson, anderson@cs.duke.edu, http://www.cs.duke.edu/~anderson
 
Responsible-Changed-From-To: freebsd-bugs->bde 
Responsible-Changed-By: obrien 
Responsible-Changed-When: Sat Jan 22 08:18:15 PST 2000 
Responsible-Changed-Why:  
I believe BDE is the author of our kernel profiling. 
Responsible-Changed-From-To: bde->obrien 
Responsible-Changed-By: obrien 
Responsible-Changed-When: Sun Jan 23 19:20:39 PST 2000 
Responsible-Changed-Why:  
I thought his PR dealt with current, and was not a MFC PR. 
State-Changed-From-To: open->closed 
State-Changed-By: bde 
State-Changed-When: Tue Feb 1 20:15:10 PST 2000 
State-Changed-Why:  
Fixed last May in -current. 
Fixes merged from -current to RELENG_3 today. 


Responsible-Changed-From-To: obrien->bde 
Responsible-Changed-By: bde 
Responsible-Changed-When: Tue Feb 1 20:15:10 PST 2000 
Responsible-Changed-Why:  
I have more round tuits for RELENG_3 while -current is frozone. 
>Unformatted:
