This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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] removing gprof sentinels


Hi,

The attached patch removes the <locore> and <hicore> sentinels from the gprof 
code. They were introduced back in 1994 to prevent the sym_lookup function 
from returning zero. sym_lookup takes a sorted list of Syms and a VMA and 
returns the corresponding symbol or zero if the VMA is out of range. The 
current code assumes that there is no code at address zero which isn't true 
for the SPU. I searched all occurrences of sym_lookup and added checks where 
necessary. No regressions.

Ken

gprof/ChangeLog:

2009-02-12  Ken Werner  <ken.werner@de.ibm.com>

        * corefile.c (core_create_function_syms): Remove "<locore>" and 
        "<hicore>" sentinels.
        * gprof.c: Likewise.
        * cg_print.c (cg_print_function_ordering): Likewise.
        * alpha.c (alpha_find_call): Add check for return value of sym_lookup.
        * mips.c (mips_find_call): Likewise.
        * sparc.c (sparc_find_call): Likewise.
        * tahoe.c (tahoe_find_call): Likewise.
        * vax.c (vax_find_call): Likewise.

gprof/ChangeLog:

2009-02-12  Ken Werner  <ken.werner@de.ibm.com>

        * corefile.c (core_create_function_syms): Remove "<locore>" and 
        "<hicore>" sentinels.
        * gprof.c: Likewise.
        * cg_print.c (cg_print_function_ordering): Likewise.
        * alpha.c (alpha_find_call): Add check for return value of sym_lookup.
        * mips.c (mips_find_call): Likewise.
        * sparc.c (sparc_find_call): Likewise.
        * tahoe.c (tahoe_find_call): Likewise.
        * vax.c (vax_find_call): Likewise.


Index: gprof/alpha.c
===================================================================
RCS file: /cvs/src/src/gprof/alpha.c,v
retrieving revision 1.10
diff -u -r1.10 alpha.c
--- gprof/alpha.c	10 Apr 2007 07:57:31 -0000	1.10
+++ gprof/alpha.c	18 Dec 2008 12:23:22 -0000
@@ -148,17 +148,20 @@
 	  if (hist_check_address (dest_pc))
 	    {
 	      child = sym_lookup (&symtab, dest_pc);
-	      DBG (CALLDEBUG,
-		   printf (" 0x%lx\t; name=%s, addr=0x%lx",
-			   (unsigned long) dest_pc, child->name,
-			   (unsigned long) child->addr));
-	      if (child->addr == dest_pc || child->addr == dest_pc - 8)
-		{
-		  DBG (CALLDEBUG, printf ("\n"));
-		  /* a hit:  */
-		  arc_add (parent, child, (unsigned long) 0);
-		  continue;
-		}
+              if (child)
+                {
+	          DBG (CALLDEBUG,
+		       printf (" 0x%lx\t; name=%s, addr=0x%lx",
+			       (unsigned long) dest_pc, child->name,
+			       (unsigned long) child->addr));
+	          if (child->addr == dest_pc || child->addr == dest_pc - 8)
+		    {
+		      DBG (CALLDEBUG, printf ("\n"));
+		      /* a hit:  */
+		      arc_add (parent, child, (unsigned long) 0);
+		      continue;
+		    }
+                }
 	    }
 	  /*
 	   * Something funny going on.
Index: gprof/cg_print.c
===================================================================
RCS file: /cvs/src/src/gprof/cg_print.c,v
retrieving revision 1.16
diff -u -r1.16 cg_print.c
--- gprof/cg_print.c	19 Jun 2008 16:30:29 -0000	1.16
+++ gprof/cg_print.c	18 Dec 2008 12:23:22 -0000
@@ -804,13 +804,8 @@
     {
       if (symtab.base[index].ncalls == 0)
 	{
-	  /* Filter out gprof generated names.  */
-	  if (strcmp (symtab.base[index].name, "<locore>")
-	      && strcmp (symtab.base[index].name, "<hicore>"))
-	    {
-	      unused_syms[unused++] = &symtab.base[index];
-	      symtab.base[index].has_been_placed = 1;
-	    }
+	  unused_syms[unused++] = &symtab.base[index];
+	  symtab.base[index].has_been_placed = 1;
 	}
       else
 	{
Index: gprof/corefile.c
===================================================================
RCS file: /cvs/src/src/gprof/corefile.c,v
retrieving revision 1.31
diff -u -r1.31 corefile.c
--- gprof/corefile.c	30 Jul 2008 04:34:57 -0000	1.31
+++ gprof/corefile.c	18 Dec 2008 12:23:22 -0000
@@ -480,8 +480,7 @@
       done (1);
     }
 
-  /* The "+ 2" is for the sentinels.  */
-  symtab.base = (Sym *) xmalloc ((symtab.len + 2) * sizeof (Sym));
+  symtab.base = (Sym *) xmalloc (symtab.len * sizeof (Sym));
 
   /* Pass 2 - create symbols.  */
   symtab.limit = symtab.base;
@@ -597,19 +596,6 @@
       ++symtab.limit;
     }
 
-  /* Create sentinels.  */
-  sym_init (symtab.limit);
-  symtab.limit->name = "<locore>";
-  symtab.limit->addr = 0;
-  symtab.limit->end_addr = min_vma - 1;
-  ++symtab.limit;
-
-  sym_init (symtab.limit);
-  symtab.limit->name = "<hicore>";
-  symtab.limit->addr = max_vma + 1;
-  symtab.limit->end_addr = ~(bfd_vma) 0;
-  ++symtab.limit;
-
   symtab.len = symtab.limit - symtab.base;
   symtab_finalize (&symtab);
 }
@@ -623,7 +609,7 @@
   char *prev_name, *prev_filename;
   unsigned int prev_name_len, prev_filename_len;
   bfd_vma vma, min_vma = ~(bfd_vma) 0, max_vma = 0;
-  Sym *prev, dummy, *sentinel, *sym;
+  Sym *prev, dummy, *sym;
   const char *filename;
   int prev_line_num;
   Sym_Table ltab;
@@ -744,7 +730,8 @@
       else
 	{
 	  sym = sym_lookup(&symtab, ltab.limit->addr);
-	  ltab.limit->is_static = sym->is_static;
+          if (sym)
+	    ltab.limit->is_static = sym->is_static;
 	}
 
       prev = ltab.limit;
@@ -756,21 +743,6 @@
       ++ltab.limit;
     }
 
-  /* Update sentinels.  */
-  sentinel = sym_lookup (&symtab, (bfd_vma) 0);
-
-  if (sentinel
-      && strcmp (sentinel->name, "<locore>") == 0
-      && min_vma <= sentinel->end_addr)
-    sentinel->end_addr = min_vma - 1;
-
-  sentinel = sym_lookup (&symtab, ~(bfd_vma) 0);
-
-  if (sentinel
-      && strcmp (sentinel->name, "<hicore>") == 0
-      && max_vma >= sentinel->addr)
-    sentinel->addr = max_vma + 1;
-
   /* Copy in function symbols.  */
   memcpy (ltab.limit, symtab.base, symtab.len * sizeof (Sym));
   ltab.limit += symtab.len;
Index: gprof/gprof.c
===================================================================
RCS file: /cvs/src/src/gprof/gprof.c,v
retrieving revision 1.32
diff -u -r1.32 gprof.c
--- gprof/gprof.c	19 Jun 2008 16:30:29 -0000	1.32
+++ gprof/gprof.c	18 Dec 2008 12:23:22 -0000
@@ -84,7 +84,6 @@
 {
   "_gprof_mcount", "mcount", "_mcount", "__mcount", "__mcount_internal",
   "__mcleanup",
-  "<locore>", "<hicore>",
   0
 };
 
Index: gprof/mips.c
===================================================================
RCS file: /cvs/src/src/gprof/mips.c,v
retrieving revision 1.8
diff -u -r1.8 mips.c
--- gprof/mips.c	10 Apr 2007 07:57:31 -0000	1.8
+++ gprof/mips.c	18 Dec 2008 12:23:22 -0000
@@ -74,16 +74,19 @@
 	  if (hist_check_address (dest_pc))
 	    {
 	      child = sym_lookup (&symtab, dest_pc);
-	      DBG (CALLDEBUG,
-		   printf (" 0x%lx\t; name=%s, addr=0x%lx",
-			   (unsigned long) dest_pc, child->name,
-			   (unsigned long) child->addr));
-	      if (child->addr == dest_pc)
+              if (child)
 		{
-		  DBG (CALLDEBUG, printf ("\n"));
-		  /* a hit:  */
-		  arc_add (parent, child, (unsigned long) 0);
-		  continue;
+	          DBG (CALLDEBUG,
+		       printf (" 0x%lx\t; name=%s, addr=0x%lx",
+			       (unsigned long) dest_pc, child->name,
+			       (unsigned long) child->addr));
+	          if (child->addr == dest_pc)
+		    {
+		      DBG (CALLDEBUG, printf ("\n"));
+		      /* a hit:  */
+		      arc_add (parent, child, (unsigned long) 0);
+		      continue;
+		    }
 		}
 	    }
 	  /* Something funny going on.  */
Index: gprof/sparc.c
===================================================================
RCS file: /cvs/src/src/gprof/sparc.c,v
retrieving revision 1.9
diff -u -r1.9 sparc.c
--- gprof/sparc.c	10 Apr 2007 07:57:31 -0000	1.9
+++ gprof/sparc.c	18 Dec 2008 12:23:22 -0000
@@ -68,15 +68,18 @@
 	  if (hist_check_address (dest_pc))
 	    {
 	      child = sym_lookup (&symtab, dest_pc);
-	      DBG (CALLDEBUG,
-		   printf ("\tdest_pc=0x%lx, (name=%s, addr=0x%lx)\n",
-			   (unsigned long) dest_pc, child->name,
-			   (unsigned long) child->addr));
-	      if (child->addr == dest_pc)
+	      if (child)
 		{
-		  /* a hit:  */
-		  arc_add (parent, child, (unsigned long) 0);
-		  continue;
+	          DBG (CALLDEBUG,
+		      printf ("\tdest_pc=0x%lx, (name=%s, addr=0x%lx)\n",
+			     (unsigned long) dest_pc, child->name,
+			     (unsigned long) child->addr));
+	          if (child->addr == dest_pc)
+		    {
+		      /* a hit:  */
+		      arc_add (parent, child, (unsigned long) 0);
+		      continue;
+		    }
 		}
 	    }
 	  /*
Index: gprof/tahoe.c
===================================================================
RCS file: /cvs/src/src/gprof/tahoe.c,v
retrieving revision 1.12
diff -u -r1.12 tahoe.c
--- gprof/tahoe.c	10 Apr 2007 07:57:31 -0000	1.12
+++ gprof/tahoe.c	18 Dec 2008 12:23:22 -0000
@@ -298,21 +298,24 @@
 	      if (hist_check_address (destpc))
 		{
 		  child = sym_lookup (&symtab, destpc);
-		  DBG (CALLDEBUG,
-		       printf ("[findcall]\tdestpc 0x%lx",
-			       (unsigned long) destpc);
-		       printf (" child->name %s", child->name);
-		       printf (" child->addr 0x%lx\n",
-			       (unsigned long) child->addr);
-		    );
-		  if (child->addr == destpc)
+                  if (child)
 		    {
-		      /*
-		       *    a hit
-		       */
-		      arc_add (parent, child, (unsigned long) 0);
-		      length += tahoe_operandlength (instructp + length);
-		      continue;
+		      DBG (CALLDEBUG,
+		           printf ("[findcall]\tdestpc 0x%lx",
+			           (unsigned long) destpc);
+		           printf (" child->name %s", child->name);
+		           printf (" child->addr 0x%lx\n",
+			           (unsigned long) child->addr);
+		        );
+		      if (child->addr == destpc)
+		        {
+		          /*
+		           *    a hit
+		           */
+		          arc_add (parent, child, (unsigned long) 0);
+		          length += tahoe_operandlength (instructp + length);
+		          continue;
+		        }
 		    }
 		  goto botched;
 		}
Index: gprof/vax.c
===================================================================
RCS file: /cvs/src/src/gprof/vax.c,v
retrieving revision 1.13
diff -u -r1.13 vax.c
--- gprof/vax.c	10 Apr 2007 07:57:31 -0000	1.13
+++ gprof/vax.c	18 Dec 2008 12:23:22 -0000
@@ -309,21 +309,24 @@
 	      if (hist_check_address (destpc))
 		{
 		  child = sym_lookup (&symtab, destpc);
-		  DBG (CALLDEBUG,
-		       printf ("[findcall]\tdestpc 0x%lx",
-			       (unsigned long) destpc);
-		       printf (" child->name %s", child->name);
-		       printf (" child->addr 0x%lx\n",
-			       (unsigned long) child->addr);
-		    );
-		  if (child->addr == destpc)
+		  if (child)
 		    {
-		      /*
-		       *    a hit
-		       */
-		      arc_add (parent, child, (unsigned long) 0);
-		      length += vax_operandlength (instructp + length);
-		      continue;
+		      DBG (CALLDEBUG,
+		           printf ("[findcall]\tdestpc 0x%lx",
+			           (unsigned long) destpc);
+		           printf (" child->name %s", child->name);
+		           printf (" child->addr 0x%lx\n",
+			           (unsigned long) child->addr);
+		        );
+		      if (child->addr == destpc)
+		        {
+		          /*
+		           *    a hit
+		           */
+		          arc_add (parent, child, (unsigned long) 0);
+		          length += vax_operandlength (instructp + length);
+		          continue;
+		        }
 		    }
 		  goto botched;
 		}

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