Subject: 'prof' is broken for large programs (#67)
Index:	usr.bin/prof/prof.c 2.11BSD

Description:
	'prof' can not handle either overlaid programs or those programs
	which have more than 32kb of symbol table information present.

Repeat-By:
	Attempt to 'prof' the output from a profiling run of 
	C-Kermit 5A(179) [not something for the faint of heart!].
	Note that 'prof' simply exits without printing anything
	at all.

Fix:
	Apply the following patch to prof.c, recompile and install
	'prof'.  Happy Profiling (it works now).

	There were several problems with 'prof'.  

	1) an 'int' was used to hold the size of the symbol table.  If
	   the symbol table was > 32kb the test against being greater
	   than 0 would fail immediately.  Changing the variable to
	   u_short probably would have fixed things, but somehow
	   doing a "if u_short > 0" didn't feel right - so a 'long'
	   was used.

	2) The size of the overlays was not being added into the
	   offset which was used to seek to the symbol table.  This
	   caused 'prof' to not find any symbols.  Ick.

	3) The comparison routine called by 'qsort' to sort the
	   number of calls was not comparing 'long' quantities
	   correctly.  The number of calls to a function is a "long"
	   not an "int".  The comparison was fixed to return the
	   qsort expected return value.
-----------------------------------------------------------------------
*** /usr/src/usr.bin/prof/prof.c.old	Fri May  8 10:15:05 1987
--- /usr/src/usr.bin/prof/prof.c	Thu Jun 25 22:11:14 1992
***************
*** 246,252 ****
   */
  getsymtab()
  {
! 	register int i;
  #ifdef BSD2_10
  	long symoff;
  #endif
--- 246,252 ----
   */
  getsymtab()
  {
! 	long i;
  #ifdef BSD2_10
  	long symoff;
  #endif
***************
*** 266,271 ****
--- 266,273 ----
  	if (!(xbuf.a_flag & 01))
  		symoff *= 2;
  	symoff += sizeof(xbuf);
+ 	if (xbuf.a_magic == A_MAGIC5 || xbuf.a_magic == A_MAGIC6)
+ 		symoff += sizeof(struct ovlhdr);
  	fseek(nfile, symoff, 0);
  #else !BSD2_10
  	fseek(nfile, N_SYMOFF(xbuf), 0);
***************
*** 587,593 ****
  	float d;
  
  	if (nflg && p2->ncall != p1->ncall)
! 		return (p2->ncall - p1->ncall);
  	d = p2->time - p1->time;
  	if (d > 0.0)
  		return(1);
--- 589,601 ----
  	float d;
  
  	if (nflg && p2->ncall != p1->ncall)
! 		{
! 		if (p2->ncall < p1->ncall)
! 			return(-1);
! 		else if (p2->ncall > p1->ncall)
! 			return(1);
! 		return(0);
! 		}
  	d = p2->time - p1->time;
  	if (d > 0.0)
  		return(1);
