PR12760 plugin vs. warning syms

Alan Modra amodra@gmail.com
Tue May 17 13:01:00 GMT 2011


On Tue, May 17, 2011 at 11:15:20AM +0930, Alan Modra wrote:
> Light dawns..  If we are making a warning sym, then we won't be
> turning the undefweak back into a defined, defweak or common when we
> return to _bfd_generic_link_add_one_symbol.  Instead we get an
> indirection.
> 
> I'll look into fixing that, and BSF_INDIRECT symbols.

include/
	* bfdlink.h (struct bfd_link_callbacks <notice>): Add "flags" and
	"string" param.
bfd/
	* coff-aux.c (coff_m68k_aux_link_add_one_symbol): Adjust "notice" call.
	* elflink.c (elf_link_add_object_symbols): Likewise.
	* linker.c (_bfd_generic_link_add_one_symbol): Likewise.
ld/
	* ldmain.c (notice): Add "flags" and "string" param.
	* plugin.c (plugin_notice): Likewise.  Handle indirect, warning
	and constructor syms.

Index: include/bfdlink.h
===================================================================
RCS file: /cvs/src/src/include/bfdlink.h,v
retrieving revision 1.86
diff -u -p -r1.86 bfdlink.h
--- include/bfdlink.h	15 May 2011 23:44:06 -0000	1.86
+++ include/bfdlink.h	17 May 2011 05:39:01 -0000
@@ -573,10 +573,13 @@ struct bfd_link_callbacks
   /* A function which is called when a symbol in notice_hash is
      defined or referenced.  H is the symbol.  ABFD, SECTION and
      ADDRESS are the (new) value of the symbol.  If SECTION is
-     bfd_und_section, this is a reference.  */
+     bfd_und_section, this is a reference.  FLAGS are the symbol
+     BSF_* flags.  STRING is the name of the symbol to indirect to if
+     the sym is indirect, or the warning string if a warning sym.  */
   bfd_boolean (*notice)
     (struct bfd_link_info *, struct bfd_link_hash_entry *h,
-     bfd *abfd, asection *section, bfd_vma address);
+     bfd *abfd, asection *section, bfd_vma address, flagword flags,
+     const char *string);
   /* Error or warning link info message.  */
   void (*einfo)
     (const char *fmt, ...);
Index: bfd/coff-aux.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-aux.c,v
retrieving revision 1.11
diff -u -p -r1.11 coff-aux.c
--- bfd/coff-aux.c	24 Apr 2011 10:02:13 -0000	1.11
+++ bfd/coff-aux.c	17 May 2011 05:38:12 -0000
@@ -105,7 +105,8 @@ coff_m68k_aux_link_add_one_symbol (info,
 	  && (bfd_hash_lookup (info->notice_hash, name, FALSE, FALSE)
 	      != (struct bfd_hash_entry *) NULL))
 	{
-	  if (! (*info->callbacks->notice) (info, h, abfd, section, value))
+	  if (! (*info->callbacks->notice) (info, h, abfd, section, value,
+					    flags, string))
 	    return FALSE;
 	}
 
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.403
diff -u -p -r1.403 elflink.c
--- bfd/elflink.c	7 May 2011 14:12:59 -0000	1.403
+++ bfd/elflink.c	17 May 2011 05:38:29 -0000
@@ -3814,7 +3814,7 @@ error_free_dyn:
       /* Make a special call to the linker "notice" function to
 	 tell it that we are about to handle an as-needed lib.  */
       if (!(*info->callbacks->notice) (info, NULL, abfd, NULL,
-				       notice_as_needed))
+				       notice_as_needed, 0, NULL))
 	goto error_free_vers;
 
       /* Clone the symbol table and sym hashes.  Remember some
@@ -4561,7 +4561,7 @@ error_free_dyn:
       /* Make a special call to the linker "notice" function to
 	 tell it that symbols added for crefs may need to be removed.  */
       if (!(*info->callbacks->notice) (info, NULL, abfd, NULL,
-				       notice_not_needed))
+				       notice_not_needed, 0, NULL))
 	goto error_free_vers;
 
       free (old_tab);
@@ -4575,7 +4575,7 @@ error_free_dyn:
   if (old_tab != NULL)
     {
       if (!(*info->callbacks->notice) (info, NULL, abfd, NULL,
-				       notice_needed))
+				       notice_needed, 0, NULL))
 	goto error_free_vers;
       free (old_tab);
       old_tab = NULL;
Index: bfd/linker.c
===================================================================
RCS file: /cvs/src/src/bfd/linker.c,v
retrieving revision 1.82
diff -u -p -r1.82 linker.c
--- bfd/linker.c	15 May 2011 23:44:07 -0000	1.82
+++ bfd/linker.c	17 May 2011 05:38:35 -0000
@@ -1607,7 +1607,8 @@ _bfd_generic_link_add_one_symbol (struct
       || (info->notice_hash != NULL
 	  && bfd_hash_lookup (info->notice_hash, name, FALSE, FALSE) != NULL))
     {
-      if (! (*info->callbacks->notice) (info, h, abfd, section, value))
+      if (! (*info->callbacks->notice) (info, h,
+					abfd, section, value, flags, string))
 	return FALSE;
     }
 
Index: ld/ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.154
diff -u -p -r1.154 ldmain.c
--- ld/ldmain.c	24 Apr 2011 10:02:14 -0000	1.154
+++ ld/ldmain.c	17 May 2011 05:39:02 -0000
@@ -151,7 +151,7 @@ static bfd_boolean unattached_reloc
   (struct bfd_link_info *, const char *, bfd *, asection *, bfd_vma);
 static bfd_boolean notice
   (struct bfd_link_info *, struct bfd_link_hash_entry *,
-   bfd *, asection *, bfd_vma);
+   bfd *, asection *, bfd_vma, flagword, const char *);
 
 static struct bfd_link_callbacks link_callbacks =
 {
@@ -1483,7 +1483,9 @@ notice (struct bfd_link_info *info,
 	struct bfd_link_hash_entry *h,
 	bfd *abfd,
 	asection *section,
-	bfd_vma value)
+	bfd_vma value,
+	flagword flags ATTRIBUTE_UNUSED,
+	const char *string ATTRIBUTE_UNUSED)
 {
   const char *name;
 
Index: ld/plugin.c
===================================================================
RCS file: /cvs/src/src/ld/plugin.c,v
retrieving revision 1.34
diff -u -p -r1.34 plugin.c
--- ld/plugin.c	16 May 2011 00:58:11 -0000	1.34
+++ ld/plugin.c	17 May 2011 12:42:18 -0000
@@ -125,9 +125,9 @@ static const enum ld_plugin_tag tv_heade
 static const size_t tv_header_size = ARRAY_SIZE (tv_header_tags);
 
 /* Forward references.  */
-static bfd_boolean plugin_notice (struct bfd_link_info *info,
-				  struct bfd_link_hash_entry *h, bfd *abfd,
-				  asection *section, bfd_vma value);
+static bfd_boolean plugin_notice (struct bfd_link_info *,
+				  struct bfd_link_hash_entry *, bfd *,
+				  asection *, bfd_vma, flagword, const char *);
 
 #if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
 
@@ -908,7 +908,9 @@ plugin_notice (struct bfd_link_info *inf
 	       struct bfd_link_hash_entry *h,
 	       bfd *abfd,
 	       asection *section,
-	       bfd_vma value)
+	       bfd_vma value,
+	       flagword flags,
+	       const char *string)
 {
   if (h != NULL)
     {
@@ -918,8 +920,33 @@ plugin_notice (struct bfd_link_info *inf
       if (is_ir_dummy_bfd (abfd))
 	return TRUE;
 
+      /* Making an indirect symbol counts as a reference unless this
+	 is a brand new symbol.  */
+      if (bfd_is_ind_section (section)
+	  || (flags & BSF_INDIRECT) != 0)
+	{
+	  if (h->type != bfd_link_hash_new)
+	    {
+	      struct bfd_link_hash_entry *inh;
+
+	      h->non_ir_ref = TRUE;
+	      inh = bfd_wrapped_link_hash_lookup (abfd, info, string, FALSE,
+						  FALSE, FALSE);
+	      if (inh != NULL)
+		inh->non_ir_ref = TRUE;
+	    }
+	}
+
+      /* Nothing to do here for warning symbols.  */
+      else if ((flags & BSF_WARNING) != 0)
+	;
+
+      /* Nothing to do here for constructor symbols.  */
+      else if ((flags & BSF_CONSTRUCTOR) != 0)
+	;
+
       /* If this is a ref, set non_ir_ref.  */
-      if (bfd_is_und_section (section))
+      else if (bfd_is_und_section (section))
 	h->non_ir_ref = TRUE;
 
       /* Otherwise, it must be a new def.  Ensure any symbol defined
@@ -945,6 +972,7 @@ plugin_notice (struct bfd_link_info *inf
       || (info->notice_hash != NULL
 	  && bfd_hash_lookup (info->notice_hash, h->root.string,
 			      FALSE, FALSE) != NULL))
-    return (*orig_callbacks->notice) (info, h, abfd, section, value);
+    return (*orig_callbacks->notice) (info, h,
+				      abfd, section, value, flags, string);
   return TRUE;
 }

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list