This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PPC64 gmon-start


The profiling code needs the range (lowest and highest address) of the
executable text. In gmon-start.c the address of _start to _monstartup
as lowpc. In the PPC64 ABI &_start returns the address of the function
descriptor in the .odp section which is beyond &etext (highpc). The
result is negative indexes and a segfault in _mcount().

The solution is to dereference the function descriptor and pass the
first double word (the functions entry point address) to _monstartup. We
cant use the ia64 scheme:

	#define ENTRY_POINT (((long int *) _start)[0])

because the ENTRY_POINT macro is also used in rtld.c where it needs to
be simply

	#define ENTRY_POINT _start

So we define a new macro:

	#define TEXT_START (((long int *) ENTRY_POINT)[0])

Which we can use gmon_start and allows ENTRY_POINT to be the normal
defintion for use in rtld.c.

In a previous patch from Alan Modra to gmon_start.c we added the follows
macros:

	#ifndef TEXT_START
	#ifdef ENTRY_POINT_DECL
	#define TEXT_START ENTRY_POINT
	#else
	#define TEXT_START &ENTRY_POINT
	#endif
	#endif

to insure that the TEST_START is set correctly for the generic case and
for arches that do not define TEXT_START in their entry.h. Unfortunately
the wrong patch was submitted and the result is:

	/* Start keeping profiling records.  */
	#ifdef ENTRY_POINT_DECL
	  __monstartup ((u_long) ENTRY_POINT, (u_long) &etext);
	#else
	  __monstartup ((u_long) TEXT_START, (u_long) &etext);
	#endif

which is incorrect. Since all three macros are defined for PPC64's
entry.h, ENTRY_POINT is used instead of TEXT_START. So profiling of
PPC64 binaries segfault. The correct code would always use TEXT_START.
The following patch corrects this error.

2002-11-20  Steven Munroe  <sjmunroe@us.ibm.com>

	* csu/gmon-start.c (__gmon_start__): Always use TEXT_START macro to
	obtain lowest address for profiling in __monstartup call.



-- 
Steven Munroe
sjmunroe@us.ibm.com
Linux on PowerPC-64 Development
GLIBC for PowerPC-64 Development
diff -rupPN libc23-cvstip-20021119/csu/gmon-start.c libc23/csu/gmon-start.c
--- libc23-cvstip-20021119/csu/gmon-start.c	Mon Oct 21 12:55:08 2002
+++ libc23/csu/gmon-start.c	Tue Nov 19 13:37:26 2002
@@ -71,11 +71,7 @@ __gmon_start__ (void)
 #endif
 
   /* Start keeping profiling records.  */
-#ifdef ENTRY_POINT_DECL
-  __monstartup ((u_long) ENTRY_POINT, (u_long) &etext);
-#else
   __monstartup ((u_long) TEXT_START, (u_long) &etext);
-#endif
 
   /* Call _mcleanup before exiting; it will write out gmon.out from the
      collected data.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]