--- glibc-2.2.5/gmon/sys/gmon.h.orig Wed Jun 26 20:17:40 2002 +++ glibc-2.2.5/gmon/sys/gmon.h Sun Jun 30 23:40:09 2002 @@ -96,17 +96,43 @@ #define HASHFRACTION 2 /* - * percent of text space to allocate for tostructs with a minimum. + * Percent of text space to allocate for tostructs. + * This is a heuristic; we will fail with a warning when profiling programs + * with a very large number of very small functions, but that's + * normally OK. + * 2 is probably still a good value for normal programs. + * Profiling a test case with 64000 small functions will work if + * you raise this value to 3 and link statically (which bloats the + * text size, thus raising the number of arcs expected by the heuristic). + */ +#define ARCDENSITY 3 + +/* + * Always allocate at least this many tostructs. This + * hides the inadequacy of the ARCDENSITY heuristic, at least + * for small programs. */ -#define ARCDENSITY 2 #define MINARCS 50 -#define MAXARCS ((1 << (8 * sizeof(HISTCOUNTER))) - 2) + +/* + * The type used to represent indices into gmonparam.tos[]. + */ +#define ARCINDEX u_long + +/* + * Maximum number of arcs we want to allow. + * Used to be max representable value of ARCINDEX minus 2, but now + * that ARCINDEX is a long, that's too large; we don't really want + * to allow a 48 gigabyte table. + * The old value of 1<<16 wasn't high enough in practice for large C++ + * programs; will 1<<20 be adequate for long? FIXME + */ +#define MAXARCS (1 << 20) struct tostruct { - u_long selfpc; - long count; - u_short link; - u_short pad; + u_long selfpc; + long count; + ARCINDEX link; }; /* @@ -132,7 +158,7 @@ long int state; u_short *kcount; u_long kcountsize; - u_short *froms; + ARCINDEX *froms; u_long fromssize; struct tostruct *tos; u_long tossize; --- glibc-2.2.5/gmon/gmon.c.orig Wed Jun 26 20:44:13 2002 +++ glibc-2.2.5/gmon/gmon.c Sun Jun 30 23:43:12 2002 @@ -141,9 +141,9 @@ } p->tos = (struct tostruct *)cp; cp += p->tossize; - p->kcount = (u_short *)cp; + p->kcount = (HISTCOUNTER *)cp; cp += p->kcountsize; - p->froms = (u_short *)cp; + p->froms = (ARCINDEX *)cp; p->tos[0].link = 0; @@ -212,7 +212,8 @@ u_char tag = GMON_TAG_CG_ARC; struct gmon_cg_arc_record raw_arc[NARCS_PER_WRITEV] __attribute__ ((aligned (__alignof__ (char*)))); - int from_index, to_index, from_len; + ARCINDEX from_index, to_index; + int from_len; u_long frompc; struct iovec iov[2 * NARCS_PER_WRITEV]; int nfilled; --- glibc-2.2.5/gmon/mcount.c.orig Wed Jun 26 20:44:18 2002 +++ glibc-2.2.5/gmon/mcount.c Sun Jun 30 23:35:37 2002 @@ -31,6 +31,7 @@ static char sccsid[] = "@(#)mcount.c 8.1 (Berkeley) 6/4/93"; #endif +#include #include #include @@ -40,6 +41,8 @@ #include +#define ERR(s) __write (STDERR_FILENO, s, sizeof (s) - 1) + /* * mcount is called on entry to each function compiled with the profiling * switch set. _mcount(), which is declared in a machine-dependent way @@ -57,10 +60,10 @@ */ _MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */ { - register u_short *frompcindex; + register ARCINDEX *frompcindex; register struct tostruct *top, *prevtop; register struct gmonparam *p; - register long toindex; + register ARCINDEX toindex; int i; p = &_gmonparam; @@ -167,6 +170,7 @@ p->state = GMON_PROF_ON; return; overflow: + ERR("mcount: profiling table overflow\n"); p->state = GMON_PROF_ERROR; return; }