PATCH: PR ld/1396: prohibited cross reference to a local symbol

H. J. Lu hjl@lucon.org
Tue Oct 4 19:52:00 GMT 2005


On Mon, Oct 03, 2005 at 03:45:11PM +0100, Etienne Lorrain wrote:
> > On Sun, Oct 02, 2005 at 07:21:18AM -0700, H. J. Lu wrote:
> > > When we process prohibited cross reference, we need to match the
> > > symbol type with the type of the symbol the relocation is against.
> >
> > Here is an updated patch to check global and local symbols explicitly.
> 
>   Thanks, it works for me - vmlinux now links without problems.
> 
>   The bug report can be closed.
> http://sourceware.org/bugzilla/show_bug.cgi?id=1396
> 

The patch is incorrect. Here is the right one.


H.J.
----
2005-10-04  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/1396
	* ldcref.c (check_refs): Accept asymbol *.
	(check_local_sym_xref): Pass sym to check_refs.
	(check_nocrossref): Pass NULL to check_refs.
	(check_refs_info): Add asymbol *.
	(check_refs): Add asymbol * to check_refs_info.
	(check_reloc_refs): Match relocations with proper symbols.

	* ldmisc.c (vfinfo): Don't add extra ":\n".

--- ld/ldcref.c.local	2005-05-16 11:04:39.000000000 -0700
+++ ld/ldcref.c	2005-10-04 12:30:00.000000000 -0700
@@ -71,7 +71,7 @@ struct cref_hash_table {
 static void output_one_cref (FILE *, struct cref_hash_entry *);
 static void check_local_sym_xref (lang_input_statement_type *);
 static bfd_boolean check_nocrossref (struct cref_hash_entry *, void *);
-static void check_refs (const char *, asection *, bfd *,
+static void check_refs (const char *, asymbol *, asection *, bfd *,
 			struct lang_nocrossrefs *);
 static void check_reloc_refs (bfd *, asection *, void *);
 
@@ -387,7 +387,7 @@ check_local_sym_xref (lang_input_stateme
 	  for (ncrs = nocrossref_list; ncrs != NULL; ncrs = ncrs->next)
 	    for (ncr = ncrs->list; ncr != NULL; ncr = ncr->next)
 	      if (strcmp (ncr->name, outsecname) == 0)
-		check_refs (symname, sym->section, abfd, ncrs);
+		check_refs (symname, sym, sym->section, abfd, ncrs);
 	}
     }
 
@@ -429,7 +429,8 @@ check_nocrossref (struct cref_hash_entry
     for (ncr = ncrs->list; ncr != NULL; ncr = ncr->next)
       if (strcmp (ncr->name, defsecname) == 0)
 	for (ref = h->refs; ref != NULL; ref = ref->next)
-	  check_refs (hl->root.string, hl->u.def.section, ref->abfd, ncrs);
+	  check_refs (hl->root.string, NULL, hl->u.def.section,
+		      ref->abfd, ncrs);
 
   return TRUE;
 }
@@ -439,6 +440,7 @@ check_nocrossref (struct cref_hash_entry
 
 struct check_refs_info {
   const char *sym_name;
+  asymbol *sym;
   asection *defsec;
   struct lang_nocrossrefs *ncrs;
   asymbol **asymbols;
@@ -451,6 +453,7 @@ struct check_refs_info {
 
 static void
 check_refs (const char *name,
+	    asymbol *sym,
 	    asection *sec,
 	    bfd *abfd,
 	    struct lang_nocrossrefs *ncrs)
@@ -488,6 +491,7 @@ check_refs (const char *name,
     }
 
   info.sym_name = name;
+  info.sym = sym;
   info.defsec = sec;
   info.ncrs = ncrs;
   info.asymbols = asymbols;
@@ -513,6 +517,7 @@ check_reloc_refs (bfd *abfd, asection *s
   const char *outdefsecname;
   struct lang_nocrossref *ncr;
   const char *symname;
+  asymbol *sym;
   long relsize;
   arelent **relpp;
   long relcount;
@@ -538,9 +543,13 @@ check_reloc_refs (bfd *abfd, asection *s
   /* This section is one for which cross references are prohibited.
      Look through the relocations, and see if any of them are to
      INFO->SYM_NAME.  If INFO->SYMNAME is NULL, check for relocations
-     against the section symbol.  */
+     against the section symbol.  If INFO->SYM is NULL, the definition
+     is global, check for relocations against the global symbols. 
+     Otherwise check for relocations against the local and section
+     symbols.  */
 
   symname = info->sym_name;
+  sym = info->sym;
 
   relsize = bfd_get_reloc_upper_bound (abfd, sec);
   if (relsize < 0)
@@ -561,6 +570,14 @@ check_reloc_refs (bfd *abfd, asection *s
 
       if (q->sym_ptr_ptr != NULL
 	  && *q->sym_ptr_ptr != NULL
+	  && ((sym == NULL
+	       && (bfd_is_und_section (bfd_get_section (*q->sym_ptr_ptr))
+		   || bfd_is_com_section (bfd_get_section (*q->sym_ptr_ptr))
+		   || ((*q->sym_ptr_ptr)->flags & (BSF_GLOBAL
+						   | BSF_WEAK)) != 0))
+	      || (sym != NULL
+		  && ((*q->sym_ptr_ptr)->flags & (BSF_LOCAL
+						  | BSF_SECTION_SYM)) != 0))
 	  && (symname != NULL
 	      ? strcmp (bfd_asymbol_name (*q->sym_ptr_ptr), symname) == 0
 	      : (((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
--- ld/ldmisc.c.local	2005-06-03 22:27:08.000000000 -0700
+++ ld/ldmisc.c	2005-10-04 10:51:59.000000000 -0700
@@ -339,7 +339,7 @@ vfinfo (FILE *fp, const char *fmt, va_li
 				&& strcmp (last_file, filename) != 0)
 			    || strcmp (last_function, functionname) != 0)
 			  {
-			    lfinfo (fp, _("%B: In function `%T':\n"),
+			    lfinfo (fp, _("%B: In function `%T'"),
 				    abfd, functionname);
 
 			    last_bfd = abfd;
@@ -355,19 +355,19 @@ vfinfo (FILE *fp, const char *fmt, va_li
 			discard_last = FALSE;
 		      }
 		    else
-		      lfinfo (fp, "%B:", abfd);
+		      lfinfo (fp, "%B", abfd);
 
 		    if (filename != NULL)
-		      fprintf (fp, "%s:", filename);
+		      fprintf (fp, ":%s", filename);
 
 		    if (functionname != NULL && fmt[-1] == 'G')
-		      lfinfo (fp, "%T", functionname);
+		      lfinfo (fp, ":%T", functionname);
 		    else if (filename != NULL)
 		      {
 			if (linenumber != 0)
-			  fprintf (fp, "%u", linenumber);
+			  fprintf (fp, ":%u", linenumber);
 			else
-			  lfinfo (fp, "(%A+0x%v)", section, offset);
+			  lfinfo (fp, ":(%A+0x%v)", section, offset);
 		      }
 		  }
 		else



More information about the Binutils mailing list