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]

Re: [PATCH] add --ignore-unresolved-symbol from NetBSD (bug#14426)


On Mon, Aug 13, 2012 at 08:49:07AM -0700, Jan Beich wrote:
> Alan Modra <amodra@gmail.com> writes:
> 
> > On Wed, Aug 01, 2012 at 12:43:23PM +0000, Jan Beich wrote:
> >
> >> Allow a specific symbol to be unresolved. This can be useful to let
> >> runtime linker resolve the symbol despite using -Wl,-z,defs.
> >> ---
> >>  include/bfdlink.h |  4 ++++
> >>  ld/ldlex.h        |  1 +
> >>  ld/ldmain.c       | 35 +++++++++++++++++++++++++++--------
> >>  ld/ldmain.h       |  1 +
> >>  ld/lexsup.c       |  7 +++++++
> >
> > This is OK with suitable ChangeLog entries.
> 
> Is the followup enough or do I need to resubmit the patch?
> 
> http://sourceware.org/ml/binutils/2012-08/msg00211.html

Sorry I left this so long.  I modified your patch a little, adding
a struct bfd_link_info* param to add_ignoresym() so the function could
be called from undefined_symbol(), and fixed a couple of other errors
in ldmain.c.

include/
	PR ld/14426
	* bfdlink.h (bfd_link_info): Add ignore_hash.
ld/
	PR ld/14426
	* ldlex.h (option_values): Add OPTION_IGNORE_UNRESOLVED_SYMBOL.
	* lexsup.c (parse_args): Likewise.
	(ld_options): Describe --ignore-unresolved-symbol.
	* ldmain.h (add_ignoresym): Declare.
	* ldmain.c (add_ignoresym): New function, extracted from..
	(undefined_symbol): ..here.  Return if the symbol is in ignore_hash.
	(constructor_callback): Don't use global link_info here.
	(reloc_overflow): Likewise.

Index: include/bfdlink.h
===================================================================
RCS file: /cvs/src/src/include/bfdlink.h,v
retrieving revision 1.95
diff -u -p -r1.95 bfdlink.h
--- include/bfdlink.h	9 Apr 2012 16:27:18 -0000	1.95
+++ include/bfdlink.h	22 Oct 2012 12:55:38 -0000
@@ -435,6 +435,10 @@ struct bfd_link_info
      option).  If this is NULL, no symbols are being wrapped.  */
   struct bfd_hash_table *wrap_hash;
 
+  /* Hash table of symbols which may be left unresolved during
+     a link.  If this is NULL, no symbols can be left unresolved.  */
+  struct bfd_hash_table *ignore_hash;
+
   /* The output BFD.  */
   bfd *output_bfd;
 
Index: ld/ldlex.h
===================================================================
RCS file: /cvs/src/src/ld/ldlex.h,v
retrieving revision 1.11
diff -u -p -r1.11 ldlex.h
--- ld/ldlex.h	26 May 2012 11:13:19 -0000	1.11
+++ ld/ldlex.h	22 Oct 2012 12:55:38 -0000
@@ -135,6 +135,7 @@ enum option_values
 #endif /* ENABLE_PLUGINS */
   OPTION_DEFAULT_SCRIPT,
   OPTION_PRINT_OUTPUT_FORMAT,
+  OPTION_IGNORE_UNRESOLVED_SYMBOL,
 };
 
 /* The initial parser states.  */
Index: ld/ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.165
diff -u -p -r1.165 ldmain.c
--- ld/ldmain.c	13 Jul 2012 13:20:26 -0000	1.165
+++ ld/ldmain.c	22 Oct 2012 12:55:38 -0000
@@ -643,6 +643,23 @@ add_ysym (const char *name)
     einfo (_("%P%F: bfd_hash_lookup failed: %E\n"));
 }
 
+void
+add_ignoresym (struct bfd_link_info *info, const char *name)
+{
+  if (info->ignore_hash == NULL)
+    {
+      info->ignore_hash = xmalloc (sizeof (struct bfd_hash_table));
+      if (! bfd_hash_table_init_n (info->ignore_hash,
+				   bfd_hash_newfunc,
+				   sizeof (struct bfd_hash_entry),
+				   61))
+	einfo (_("%P%F: bfd_hash_table_init failed: %E\n"));
+    }
+
+  if (bfd_hash_lookup (info->ignore_hash, name, TRUE, TRUE) == NULL)
+    einfo (_("%P%F: bfd_hash_lookup failed: %E\n"));
+}
+
 /* Record a symbol to be wrapped, from the --wrap option.  */
 
 void
@@ -1091,7 +1108,7 @@ constructor_callback (struct bfd_link_in
 
   /* Ensure that BFD_RELOC_CTOR exists now, so that we can give a
      useful error message.  */
-  if (bfd_reloc_type_lookup (link_info.output_bfd, BFD_RELOC_CTOR) == NULL
+  if (bfd_reloc_type_lookup (info->output_bfd, BFD_RELOC_CTOR) == NULL
       && (info->relocatable
 	  || bfd_reloc_type_lookup (abfd, BFD_RELOC_CTOR) == NULL))
     einfo (_("%P%F: BFD backend error: BFD_RELOC_CTOR unsupported\n"));
@@ -1228,7 +1245,7 @@ warning_find_reloc (bfd *abfd, asection 
 /* This is called when an undefined symbol is found.  */
 
 static bfd_boolean
-undefined_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
+undefined_symbol (struct bfd_link_info *info,
 		  const char *name,
 		  bfd *abfd,
 		  asection *section,
@@ -1240,25 +1257,14 @@ undefined_symbol (struct bfd_link_info *
 
 #define MAX_ERRORS_IN_A_ROW 5
 
+  if (info->ignore_hash != NULL
+      && bfd_hash_lookup (info->ignore_hash, name, FALSE, FALSE) != NULL)
+    return TRUE;
+
   if (config.warn_once)
     {
-      static struct bfd_hash_table *hash;
-
       /* Only warn once about a particular undefined symbol.  */
-      if (hash == NULL)
-	{
-	  hash = (struct bfd_hash_table *)
-              xmalloc (sizeof (struct bfd_hash_table));
-	  if (!bfd_hash_table_init (hash, bfd_hash_newfunc,
-				    sizeof (struct bfd_hash_entry)))
-	    einfo (_("%F%P: bfd_hash_table_init failed: %E\n"));
-	}
-
-      if (bfd_hash_lookup (hash, name, FALSE, FALSE) != NULL)
-	return TRUE;
-
-      if (bfd_hash_lookup (hash, name, TRUE, TRUE) == NULL)
-	einfo (_("%F%P: bfd_hash_lookup failed: %E\n"));
+      add_ignoresym (info, name);
     }
 
   /* We never print more than a reasonable number of errors in a row
@@ -1336,7 +1342,7 @@ int overflow_cutoff_limit = 10;
 /* This is called when a reloc overflows.  */
 
 static bfd_boolean
-reloc_overflow (struct bfd_link_info *info ATTRIBUTE_UNUSED,
+reloc_overflow (struct bfd_link_info *info,
 		struct bfd_link_hash_entry *entry,
 		const char *name,
 		const char *reloc_name,
@@ -1375,7 +1381,7 @@ reloc_overflow (struct bfd_link_info *in
 		 reloc_name, entry->root.string,
 		 entry->u.def.section,
 		 entry->u.def.section == bfd_abs_section_ptr
-		 ? link_info.output_bfd : entry->u.def.section->owner);
+		 ? info->output_bfd : entry->u.def.section->owner);
 	  break;
 	default:
 	  abort ();
Index: ld/ldmain.h
===================================================================
RCS file: /cvs/src/src/ld/ldmain.h,v
retrieving revision 1.18
diff -u -p -r1.18 ldmain.h
--- ld/ldmain.h	13 Jul 2012 13:20:26 -0000	1.18
+++ ld/ldmain.h	22 Oct 2012 12:55:38 -0000
@@ -41,6 +41,7 @@ extern int overflow_cutoff_limit;
 
 extern void add_ysym (const char *);
 extern void add_wrap (const char *);
+extern void add_ignoresym (struct bfd_link_info *, const char *);
 extern void add_keepsyms_file (const char *);
 
 #endif
Index: ld/lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.133
diff -u -p -r1.133 lexsup.c
--- ld/lexsup.c	13 Jul 2012 13:20:26 -0000	1.133
+++ ld/lexsup.c	22 Oct 2012 12:55:38 -0000
@@ -496,6 +496,10 @@ static const struct ld_option ld_options
     TWO_DASHES },
   { {"wrap", required_argument, NULL, OPTION_WRAP},
     '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
+  { {"ignore-unresolved-symbol", required_argument, NULL,
+    OPTION_IGNORE_UNRESOLVED_SYMBOL},
+    '\0', N_("SYMBOL"),
+    N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
 };
 
 #define OPTION_COUNT ARRAY_SIZE (ld_options)
@@ -1341,6 +1345,9 @@ parse_args (unsigned argc, char **argv)
 	case OPTION_WRAP:
 	  add_wrap (optarg);
 	  break;
+	case OPTION_IGNORE_UNRESOLVED_SYMBOL:
+	  add_ignoresym (&link_info, optarg);
+	  break;
 	case OPTION_DISCARD_NONE:
 	  link_info.discard = discard_none;
 	  break;


-- 
Alan Modra
Australia Development Lab, IBM


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