Subject: profiling main()
To: None <tech-toolchain@NetBSD.org>
From: Rui Paulo <rpaulo@fnop.net>
List: tech-toolchain
Date: 10/12/2005 22:27:03
--4f28nU6agdXSinmL
Content-Type: multipart/mixed; boundary="UnaWdueM1EBWVRzC"
Content-Disposition: inline


--UnaWdueM1EBWVRzC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,
The attached patch makes it possible to profile main() in userland
applications for ELF files. The "bug" was noticed by Bruce Evans in
http://lists.freebsd.org/pipermail/cvs-src/2005-October/053619.html.

Please comment.

		-- Rui Paulo

--UnaWdueM1EBWVRzC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="crt0-main.diff"
Content-Transfer-Encoding: quoted-printable

Index: alpha/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/alpha/crt0.c,v
retrieving revision 1.24
diff -u -p -r1.24 crt0.c
--- alpha/crt0.c	26 Jul 2003 19:24:25 -0000	1.24
+++ alpha/crt0.c	12 Oct 2005 21:26:28 -0000
@@ -72,6 +72,10 @@ __start(sp, cleanup, obj, ps_strings)
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif
=20
 	atexit(_fini);
Index: arm_elf/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/arm_elf/crt0.c,v
retrieving revision 1.6
diff -u -p -r1.6 crt0.c
--- arm_elf/crt0.c	1 Jan 2002 01:31:06 -0000	1.6
+++ arm_elf/crt0.c	12 Oct 2005 21:26:28 -0000
@@ -100,6 +100,10 @@ ___start(int argc, char **argv, char **e
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif	/* MCRT0 */
=20
 	atexit(_fini);
Index: common_elf/common.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/common_elf/common.c,v
retrieving revision 1.16
diff -u -p -r1.16 common.c
--- common_elf/common.c	26 Aug 2004 21:01:12 -0000	1.16
+++ common_elf/common.c	12 Oct 2005 21:26:28 -0000
@@ -52,14 +52,6 @@ _strrchr(char *p, int ch)
 	/* NOTREACHED */
 }
=20
-#ifdef MCRT0
-asm ("  .text");
-#ifdef EPROL_EXPORT
-EPROL_EXPORT;
-#endif
-asm ("_eprol:");
-#endif
-
 #ifdef DYNAMIC
=20
 void
Index: hppa/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/hppa/crt0.c,v
retrieving revision 1.7
diff -u -p -r1.7 crt0.c
--- hppa/crt0.c	26 Aug 2004 21:07:14 -0000	1.7
+++ hppa/crt0.c	12 Oct 2005 21:26:29 -0000
@@ -117,6 +117,10 @@ ___start(struct ps_strings *ps_strings,
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif
=20
 	/*
Index: i386_elf/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/i386_elf/crt0.c,v
retrieving revision 1.13
diff -u -p -r1.13 crt0.c
--- i386_elf/crt0.c	26 Jul 2003 19:24:27 -0000	1.13
+++ i386_elf/crt0.c	12 Oct 2005 21:26:29 -0000
@@ -86,6 +86,10 @@ ___start(argc, argv, envp, cleanup, obj,
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif
=20
 	atexit(_fini);
Index: m68k_elf/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/m68k_elf/crt0.c,v
retrieving revision 1.11
diff -u -p -r1.11 crt0.c
--- m68k_elf/crt0.c	26 Aug 2004 21:09:52 -0000	1.11
+++ m68k_elf/crt0.c	12 Oct 2005 21:26:29 -0000
@@ -82,6 +82,10 @@ __start(int argc, char **argv, char **en
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif
=20
 	atexit(_fini);
Index: mips/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/mips/crt0.c,v
retrieving revision 1.17
diff -u -p -r1.17 crt0.c
--- mips/crt0.c	26 Aug 2004 21:13:01 -0000	1.17
+++ mips/crt0.c	12 Oct 2005 21:26:29 -0000
@@ -144,6 +144,10 @@ __start(u_long sp,
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif
=20
 	atexit(_fini);
Index: powerpc/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/powerpc/crt0.c,v
retrieving revision 1.25
diff -u -p -r1.25 crt0.c
--- powerpc/crt0.c	26 Aug 2004 21:15:05 -0000	1.25
+++ powerpc/crt0.c	12 Oct 2005 21:26:30 -0000
@@ -91,6 +91,10 @@ _start(int argc, char **argv, char **env
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif
=20
 	atexit(_fini);
Index: sh3_elf/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/sh3_elf/crt0.c,v
retrieving revision 1.10
diff -u -p -r1.10 crt0.c
--- sh3_elf/crt0.c	26 Aug 2004 21:16:41 -0000	1.10
+++ sh3_elf/crt0.c	12 Oct 2005 21:26:30 -0000
@@ -76,6 +76,10 @@ ___start(int argc, char **argv, char **e
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif
=20
 	atexit(_fini);
Index: sh5/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/sh5/crt0.c,v
retrieving revision 1.4
diff -u -p -r1.4 crt0.c
--- sh5/crt0.c	1 Apr 2003 10:20:38 -0000	1.4
+++ sh5/crt0.c	12 Oct 2005 21:26:30 -0000
@@ -95,6 +95,10 @@ __start(int argc, char **argv, char **en
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif
=20
 	atexit(_fini);
Index: sparc64/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/sparc64/crt0.c,v
retrieving revision 1.23
diff -u -p -r1.23 crt0.c
--- sparc64/crt0.c	26 Aug 2004 21:21:33 -0000	1.23
+++ sparc64/crt0.c	12 Oct 2005 21:26:30 -0000
@@ -101,6 +101,10 @@ ___start(char **sp,
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif
=20
 	atexit(_fini);
Index: sparc_elf/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/sparc_elf/crt0.c,v
retrieving revision 1.12
diff -u -p -r1.12 crt0.c
--- sparc_elf/crt0.c	26 Aug 2004 21:18:36 -0000	1.12
+++ sparc_elf/crt0.c	12 Oct 2005 21:26:30 -0000
@@ -86,6 +86,10 @@ ___start(int argc, char **argv, char **e
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif
=20
 	atexit(_fini);
Index: vax_elf/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/vax_elf/crt0.c,v
retrieving revision 1.10
diff -u -p -r1.10 crt0.c
--- vax_elf/crt0.c	26 Aug 2004 21:24:09 -0000	1.10
+++ vax_elf/crt0.c	12 Oct 2005 21:26:30 -0000
@@ -83,6 +83,10 @@ ___start(int argc, char **argv, char **e
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif
=20
 	atexit(_fini);
Index: x86_64/crt0.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/csu/x86_64/crt0.c,v
retrieving revision 1.4
diff -u -p -r1.4 crt0.c
--- x86_64/crt0.c	26 Aug 2004 21:23:06 -0000	1.4
+++ x86_64/crt0.c	12 Oct 2005 21:26:30 -0000
@@ -85,6 +85,10 @@ ___start(int argc, char **argv, char **e
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&_eprol, (u_long)&_etext);
+#ifdef EPROL_EXPORT
+EPROL_EXPORT;
+#endif =20
+__asm("_eprol:");
 #endif
=20
 	atexit(_fini);

--UnaWdueM1EBWVRzC--

--4f28nU6agdXSinmL
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (NetBSD)

iD8DBQFDTX+nZPqyxs9FH4QRAsyTAJ4l0SFkCSdRM2RVtdVRe2t/Z2U15gCdHBpB
vi3JjqBoadZkiL9rYzAFtac=
=4Ghl
-----END PGP SIGNATURE-----

--4f28nU6agdXSinmL--