Nicholas Clifton 8d40e3
diff -rup ../binutils-2.20.51.0.2/bfd/elflink.c ./bfd/elflink.c
Nicholas Clifton 8d40e3
--- ../binutils-2.20.51.0.2/bfd/elflink.c	2010-01-20 08:27:19.000000000 +0000
Nicholas Clifton 8d40e3
+++ ./bfd/elflink.c	2010-01-20 08:35:12.000000000 +0000
Nicholas Clifton 7bd7de
@@ -3918,6 +3918,7 @@ error_free_dyn:
Nicholas Clifton 7bd7de
       bfd_boolean common;
Nicholas Clifton 7bd7de
       unsigned int old_alignment;
Nicholas Clifton 7bd7de
       bfd *old_bfd;
Nicholas Clifton 7bd7de
+      bfd * undef_bfd = NULL;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
       override = FALSE;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 8d40e3
@@ -4042,6 +4043,20 @@ error_free_dyn:
Nicholas Clifton 8d40e3
 	  unsigned int vernum = 0;
Nicholas Clifton 8d40e3
 	  bfd_boolean skip;
Nicholas Clifton 8d40e3
 
Nicholas Clifton 8d40e3
+	  /* If this is a definition of a symbol which was previously
Nicholas Clifton 8d40e3
+	     referenced in a non-weak manner then make a note of the bfd
Nicholas Clifton 8d40e3
+	     that contained the reference.  This is used if we need to
Nicholas Clifton 8d40e3
+	     refer to the source of the reference later on.  */
Nicholas Clifton 8d40e3
+	  if (! bfd_is_und_section (sec))
Nicholas Clifton 8d40e3
+	    {
Nicholas Clifton 8d40e3
+	      h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE, FALSE);
Nicholas Clifton 8d40e3
+
Nicholas Clifton 8d40e3
+	      if (h != NULL
Nicholas Clifton 8d40e3
+		  && h->root.type == bfd_link_hash_undefined
Nicholas Clifton 8d40e3
+		  && h->root.u.undef.abfd)
Nicholas Clifton 8d40e3
+		undef_bfd = h->root.u.undef.abfd;
Nicholas Clifton 8d40e3
+	    }
Nicholas Clifton 8d40e3
+	  
Nicholas Clifton 8d40e3
 	  if (ever == NULL)
Nicholas Clifton 8d40e3
 	    {
Nicholas Clifton 8d40e3
 	      if (info->default_imported_symver)
Nicholas Clifton 8d40e3
@@ -4149,6 +4164,19 @@ error_free_dyn:
Nicholas Clifton 7bd7de
 	      name = newname;
Nicholas Clifton 7bd7de
 	    }
Nicholas Clifton 7bd7de
 
Nicholas Clifton 8d40e3
+	  /* If necessary, make a second attempt to locate the bfd
Nicholas Clifton 8d40e3
+	     containing an unresolved, non-weak reference to the
Nicholas Clifton 8d40e3
+	     current symbol.  */
Nicholas Clifton 8d40e3
+	  if (! bfd_is_und_section (sec) && undef_bfd == NULL)
Nicholas Clifton 7bd7de
+	    {
Nicholas Clifton 7bd7de
+	      h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE, FALSE);
Nicholas Clifton 7bd7de
+
Nicholas Clifton 7bd7de
+	      if (h != NULL
Nicholas Clifton 8d40e3
+		  && h->root.type == bfd_link_hash_undefined
Nicholas Clifton 7bd7de
+		  && h->root.u.undef.abfd)
Nicholas Clifton 7bd7de
+		undef_bfd = h->root.u.undef.abfd;
Nicholas Clifton 7bd7de
+	    }
Nicholas Clifton 7bd7de
+
Nicholas Clifton 7bd7de
 	  if (!_bfd_elf_merge_symbol (abfd, info, name, isym, &sec,
Nicholas Clifton 7bd7de
 				      &value, &old_alignment,
Nicholas Clifton 7bd7de
 				      sym_hash, &skip, &override,
Nicholas Clifton 8d40e3
@@ -4502,13 +4530,18 @@ error_free_dyn:
Nicholas Clifton 8d40e3
 	      /* A symbol from a library loaded via DT_NEEDED of some
Nicholas Clifton 8d40e3
 		 other library is referenced by a regular object.
Nicholas Clifton 8d40e3
 		 Add a DT_NEEDED entry for it.  Issue an error if
Nicholas Clifton 8d40e3
-		 --no-add-needed is used.  */
Nicholas Clifton 8d40e3
-	      if ((elf_dyn_lib_class (abfd) & DYN_NO_NEEDED) != 0)
Nicholas Clifton 8d40e3
+		 --no-add-needed is used and the reference was not
Nicholas Clifton 8d40e3
+		 a weak one.  */
Nicholas Clifton 8d40e3
+	      if (undef_bfd != NULL
Nicholas Clifton 8d40e3
+		  && (elf_dyn_lib_class (abfd) & DYN_NO_NEEDED) != 0)
Nicholas Clifton 7bd7de
 		{
Nicholas Clifton 7bd7de
 		  (*_bfd_error_handler)
Nicholas Clifton 7bd7de
-		    (_("%s: invalid DSO for symbol `%s' definition"),
Nicholas Clifton 7bd7de
+		    (_("%B: undefined reference to symbol '%s'"),
Nicholas Clifton 8d40e3
+		     undef_bfd, name);
Nicholas Clifton 7bd7de
+		  (*_bfd_error_handler)
Nicholas Clifton 7bd7de
+		    (_("note: '%s' is defined in DSO %B so try adding it to the linker command line"),
Nicholas Clifton 7bd7de
 		     abfd, name);
Nicholas Clifton 7bd7de
-		  bfd_set_error (bfd_error_bad_value);
Nicholas Clifton 7bd7de
+		  bfd_set_error (bfd_error_invalid_operation);
Nicholas Clifton 7bd7de
 		  goto error_free_vers;
Nicholas Clifton 7bd7de
 		}
Nicholas Clifton 7bd7de
 
Nicholas Clifton 8d40e3
diff -rup ../binutils-2.20.51.0.2/ld/emultempl/elf32.em ./ld/emultempl/elf32.em
Nicholas Clifton 8d40e3
--- ../binutils-2.20.51.0.2/ld/emultempl/elf32.em	2009-10-09 23:26:22.000000000 +0100
Nicholas Clifton 8d40e3
+++ ./ld/emultempl/elf32.em	2010-01-13 16:01:13.000000000 +0000
Nicholas Clifton 7bd7de
@@ -110,7 +110,7 @@ fi
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
 if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then
Nicholas Clifton 7bd7de
 fragment <
Nicholas Clifton 7bd7de
-/* Handle as_needed DT_NEEDED.  */
Nicholas Clifton 7bd7de
+/* Handle the generation of DT_NEEDED tags.  */
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
 static bfd_boolean
Nicholas Clifton 7bd7de
 gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *entry)
Nicholas Clifton 7bd7de
@@ -120,13 +120,13 @@ gld${EMULATION_NAME}_load_symbols (lang_
Nicholas Clifton 7bd7de
   /* Tell the ELF linker that we don't want the output file to have a
Nicholas Clifton 7bd7de
      DT_NEEDED entry for this file, unless it is used to resolve
Nicholas Clifton 7bd7de
      references in a regular object.  */
Nicholas Clifton 7bd7de
-  if (entry->as_needed)
Nicholas Clifton 7bd7de
+  if (entry->add_DT_NEEDED_for_regular)
Nicholas Clifton 7bd7de
     link_class = DYN_AS_NEEDED;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
   /* Tell the ELF linker that we don't want the output file to have a
Nicholas Clifton 7bd7de
      DT_NEEDED entry for any dynamic library in DT_NEEDED tags from
Nicholas Clifton 7bd7de
      this file at all.  */
Nicholas Clifton 7bd7de
-  if (!entry->add_needed)
Nicholas Clifton 7bd7de
+  if (!entry->add_DT_NEEDED_for_dynamic)
Nicholas Clifton 7bd7de
     link_class |= DYN_NO_ADD_NEEDED;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
   if (entry->just_syms_flag
Nicholas Clifton 7bd7de
@@ -134,7 +134,7 @@ gld${EMULATION_NAME}_load_symbols (lang_
Nicholas Clifton 7bd7de
     einfo (_("%P%F: --just-symbols may not be used on DSO: %B\n"),
Nicholas Clifton 7bd7de
 	   entry->the_bfd);
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
-  if (!link_class
Nicholas Clifton 7bd7de
+  if (link_class == 0
Nicholas Clifton 7bd7de
       || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0)
Nicholas Clifton 7bd7de
     return FALSE;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 8d40e3
diff -rup ../binutils-2.20.51.0.2/ld/ldgram.y ./ld/ldgram.y
Nicholas Clifton 8d40e3
--- ../binutils-2.20.51.0.2/ld/ldgram.y	2009-09-08 18:11:39.000000000 +0100
Nicholas Clifton 8d40e3
+++ ./ld/ldgram.y	2010-01-13 16:01:16.000000000 +0000
Nicholas Clifton 7bd7de
@@ -378,17 +378,17 @@ input_list:
Nicholas Clifton 7bd7de
 		{ lang_add_input_file($2,lang_input_file_is_l_enum,
Nicholas Clifton 7bd7de
 				 (char *)NULL); }
Nicholas Clifton 7bd7de
 	|	AS_NEEDED '('
Nicholas Clifton 7bd7de
-		  { $<integer>$ = as_needed; as_needed = TRUE; }
Nicholas Clifton 7bd7de
+		  { $<integer>$ = add_DT_NEEDED_for_regular; add_DT_NEEDED_for_regular = TRUE; }
Nicholas Clifton 7bd7de
 		     input_list ')'
Nicholas Clifton 7bd7de
-		  { as_needed = $<integer>3; }
Nicholas Clifton 7bd7de
+		  { add_DT_NEEDED_for_regular = $<integer>3; }
Nicholas Clifton 7bd7de
 	|	input_list ',' AS_NEEDED '('
Nicholas Clifton 7bd7de
-		  { $<integer>$ = as_needed; as_needed = TRUE; }
Nicholas Clifton 7bd7de
+		  { $<integer>$ = add_DT_NEEDED_for_regular; add_DT_NEEDED_for_regular = TRUE; }
Nicholas Clifton 7bd7de
 		     input_list ')'
Nicholas Clifton 7bd7de
-		  { as_needed = $<integer>5; }
Nicholas Clifton 7bd7de
+		  { add_DT_NEEDED_for_regular = $<integer>5; }
Nicholas Clifton 7bd7de
 	|	input_list AS_NEEDED '('
Nicholas Clifton 7bd7de
-		  { $<integer>$ = as_needed; as_needed = TRUE; }
Nicholas Clifton 7bd7de
+		  { $<integer>$ = add_DT_NEEDED_for_regular; add_DT_NEEDED_for_regular = TRUE; }
Nicholas Clifton 7bd7de
 		     input_list ')'
Nicholas Clifton 7bd7de
-		  { as_needed = $<integer>4; }
Nicholas Clifton 7bd7de
+		  { add_DT_NEEDED_for_regular = $<integer>4; }
Nicholas Clifton 7bd7de
 	;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
 sections:
Nicholas Clifton 8d40e3
diff -rup ../binutils-2.20.51.0.2/ld/ldlang.c ./ld/ldlang.c
Nicholas Clifton 8d40e3
--- ../binutils-2.20.51.0.2/ld/ldlang.c	2009-10-09 23:25:30.000000000 +0100
Nicholas Clifton 8d40e3
+++ ./ld/ldlang.c	2010-01-13 16:01:16.000000000 +0000
Nicholas Clifton 7bd7de
@@ -1056,8 +1056,8 @@ new_afile (const char *name,
Nicholas Clifton 7bd7de
   p->next_real_file = NULL;
Nicholas Clifton 7bd7de
   p->next = NULL;
Nicholas Clifton 7bd7de
   p->dynamic = config.dynamic_link;
Nicholas Clifton 7bd7de
-  p->add_needed = add_needed;
Nicholas Clifton 7bd7de
-  p->as_needed = as_needed;
Nicholas Clifton 7bd7de
+  p->add_DT_NEEDED_for_dynamic = add_DT_NEEDED_for_dynamic;
Nicholas Clifton 7bd7de
+  p->add_DT_NEEDED_for_regular = add_DT_NEEDED_for_regular;
Nicholas Clifton 7bd7de
   p->whole_archive = whole_archive;
Nicholas Clifton 7bd7de
   p->loaded = FALSE;
Nicholas Clifton 7bd7de
   lang_statement_append (&input_file_chain,
Nicholas Clifton 7bd7de
@@ -2592,7 +2592,8 @@ load_symbols (lang_input_statement_type 
Nicholas Clifton 7bd7de
     {
Nicholas Clifton 7bd7de
       bfd_error_type err;
Nicholas Clifton 7bd7de
       bfd_boolean save_ldlang_sysrooted_script;
Nicholas Clifton 7bd7de
-      bfd_boolean save_as_needed, save_add_needed;
Nicholas Clifton 7bd7de
+      bfd_boolean save_add_DT_NEEDED_for_regular;
Nicholas Clifton 7bd7de
+      bfd_boolean save_add_DT_NEEDED_for_dynamic;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
       err = bfd_get_error ();
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
@@ -2623,10 +2624,10 @@ load_symbols (lang_input_statement_type 
Nicholas Clifton 7bd7de
       push_stat_ptr (place);
Nicholas Clifton 7bd7de
       save_ldlang_sysrooted_script = ldlang_sysrooted_script;
Nicholas Clifton 7bd7de
       ldlang_sysrooted_script = entry->sysrooted;
Nicholas Clifton 7bd7de
-      save_as_needed = as_needed;
Nicholas Clifton 7bd7de
-      as_needed = entry->as_needed;
Nicholas Clifton 7bd7de
-      save_add_needed = add_needed;
Nicholas Clifton 7bd7de
-      add_needed = entry->add_needed;
Nicholas Clifton 7bd7de
+      save_add_DT_NEEDED_for_regular = add_DT_NEEDED_for_regular;
Nicholas Clifton 7bd7de
+      add_DT_NEEDED_for_regular = entry->add_DT_NEEDED_for_regular;
Nicholas Clifton 7bd7de
+      save_add_DT_NEEDED_for_dynamic = add_DT_NEEDED_for_dynamic;
Nicholas Clifton 7bd7de
+      add_DT_NEEDED_for_dynamic = entry->add_DT_NEEDED_for_dynamic;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
       ldfile_assumed_script = TRUE;
Nicholas Clifton 7bd7de
       parser_input = input_script;
Nicholas Clifton 7bd7de
@@ -2637,8 +2638,8 @@ load_symbols (lang_input_statement_type 
Nicholas Clifton 7bd7de
       ldfile_assumed_script = FALSE;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
       ldlang_sysrooted_script = save_ldlang_sysrooted_script;
Nicholas Clifton 7bd7de
-      as_needed = save_as_needed;
Nicholas Clifton 7bd7de
-      add_needed = save_add_needed;
Nicholas Clifton 7bd7de
+      add_DT_NEEDED_for_regular = save_add_DT_NEEDED_for_regular;
Nicholas Clifton 7bd7de
+      add_DT_NEEDED_for_dynamic = save_add_DT_NEEDED_for_dynamic;
Nicholas Clifton 7bd7de
       pop_stat_ptr ();
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
       return TRUE;
Nicholas Clifton 8d40e3
diff -rup ../binutils-2.20.51.0.2/ld/ldlang.h ./ld/ldlang.h
Nicholas Clifton 8d40e3
--- ../binutils-2.20.51.0.2/ld/ldlang.h	2009-10-09 23:25:30.000000000 +0100
Nicholas Clifton 8d40e3
+++ ./ld/ldlang.h	2010-01-13 16:01:13.000000000 +0000
Nicholas Clifton 7bd7de
@@ -270,11 +270,11 @@ typedef struct lang_input_statement_stru
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
   /* Whether DT_NEEDED tags should be added for dynamic libraries in
Nicholas Clifton 7bd7de
      DT_NEEDED tags from this entry.  */
Nicholas Clifton 7bd7de
-  unsigned int add_needed : 1;
Nicholas Clifton 7bd7de
+  unsigned int add_DT_NEEDED_for_dynamic : 1;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
   /* Whether this entry should cause a DT_NEEDED tag only when
Nicholas Clifton 7bd7de
      satisfying references from regular files, or always.  */
Nicholas Clifton 7bd7de
-  unsigned int as_needed : 1;
Nicholas Clifton 7bd7de
+  unsigned int add_DT_NEEDED_for_regular : 1;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
   /* Whether to include the entire contents of an archive.  */
Nicholas Clifton 7bd7de
   unsigned int whole_archive : 1;
Nicholas Clifton 8d40e3
diff -rup ../binutils-2.20.51.0.2/ld/ldmain.c ./ld/ldmain.c
Nicholas Clifton 8d40e3
--- ../binutils-2.20.51.0.2/ld/ldmain.c	2010-01-20 08:27:18.000000000 +0000
Nicholas Clifton 8d40e3
+++ ./ld/ldmain.c	2010-01-13 16:01:16.000000000 +0000
Nicholas Clifton 7bd7de
@@ -93,13 +93,14 @@ bfd_boolean version_printed;
Nicholas Clifton 7bd7de
 /* Nonzero means link in every member of an archive.  */
Nicholas Clifton 7bd7de
 bfd_boolean whole_archive;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
-/* Nonzero means create DT_NEEDED entries only if a dynamic library
Nicholas Clifton 7bd7de
-   actually satisfies some reference in a regular object.  */
Nicholas Clifton 7bd7de
-bfd_boolean as_needed;
Nicholas Clifton 7bd7de
-
Nicholas Clifton 7bd7de
-/* Nonzero means never create DT_NEEDED entries for dynamic libraries
Nicholas Clifton 7bd7de
-   in DT_NEEDED tags.  */
Nicholas Clifton 7bd7de
-bfd_boolean add_needed = TRUE;
Nicholas Clifton 7bd7de
+/* True means only create DT_NEEDED entries for dynamic libraries
Nicholas Clifton 7bd7de
+   if they actually satisfy some reference in a regular object.  */
Nicholas Clifton 7bd7de
+bfd_boolean add_DT_NEEDED_for_regular;
Nicholas Clifton 7bd7de
+
Nicholas Clifton 7bd7de
+/* True means create DT_NEEDED entries for dynamic libraries that
Nicholas Clifton 7bd7de
+   are DT_NEEDED by dynamic libraries specifically mentioned on
Nicholas Clifton 7bd7de
+   the command line.  */
Nicholas Clifton eb06af
+bfd_boolean add_DT_NEEDED_for_dynamic = TRUE;
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
 /* TRUE if we should demangle symbol names.  */
Nicholas Clifton 7bd7de
 bfd_boolean demangling;
Nicholas Clifton 8d40e3
diff -rup ../binutils-2.20.51.0.2/ld/ldmain.h ./ld/ldmain.h
Nicholas Clifton 8d40e3
--- ../binutils-2.20.51.0.2/ld/ldmain.h	2009-10-09 23:26:22.000000000 +0100
Nicholas Clifton 8d40e3
+++ ./ld/ldmain.h	2010-01-13 16:01:12.000000000 +0000
Nicholas Clifton 7bd7de
@@ -1,6 +1,6 @@
Nicholas Clifton 7bd7de
 /* ldmain.h -
Nicholas Clifton 7bd7de
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2002, 2003, 2004,
Nicholas Clifton 7bd7de
-   2005, 2007, 2008 Free Software Foundation, Inc.
Nicholas Clifton 7bd7de
+   2005, 2007, 2008, 2009 Free Software Foundation, Inc.
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
    This file is part of the GNU Binutils.
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
@@ -34,8 +34,8 @@ extern bfd_boolean trace_files;
Nicholas Clifton 7bd7de
 extern bfd_boolean trace_file_tries;
Nicholas Clifton 7bd7de
 extern bfd_boolean version_printed;
Nicholas Clifton 7bd7de
 extern bfd_boolean whole_archive;
Nicholas Clifton 7bd7de
-extern bfd_boolean as_needed;
Nicholas Clifton 7bd7de
-extern bfd_boolean add_needed;
Nicholas Clifton 7bd7de
+extern bfd_boolean add_DT_NEEDED_for_regular;
Nicholas Clifton 7bd7de
+extern bfd_boolean add_DT_NEEDED_for_dynamic;
Nicholas Clifton 7bd7de
 extern bfd_boolean demangling;
Nicholas Clifton 7bd7de
 extern enum report_method how_to_report_unresolved_symbols;
Nicholas Clifton 7bd7de
 extern int g_switch_value;
Nicholas Clifton 8d40e3
diff -rup ../binutils-2.20.51.0.2/ld/ld.texinfo ./ld/ld.texinfo
Nicholas Clifton 8d40e3
--- ../binutils-2.20.51.0.2/ld/ld.texinfo	2010-01-20 08:27:18.000000000 +0000
Nicholas Clifton 8d40e3
+++ ./ld/ld.texinfo	2010-01-13 16:01:12.000000000 +0000
Nicholas Clifton 7bd7de
@@ -1132,27 +1132,24 @@ restore the old behaviour.
Nicholas Clifton 7bd7de
 @item --as-needed
Nicholas Clifton 7bd7de
 @itemx --no-as-needed
Nicholas Clifton 7bd7de
 This option affects ELF DT_NEEDED tags for dynamic libraries mentioned
Nicholas Clifton 7bd7de
-on the command line after the @option{--as-needed} option.  Normally,
Nicholas Clifton 7bd7de
+on the command line after the @option{--as-needed} option.  Normally
Nicholas Clifton 7bd7de
 the linker will add a DT_NEEDED tag for each dynamic library mentioned
Nicholas Clifton 7bd7de
 on the command line, regardless of whether the library is actually
Nicholas Clifton 7bd7de
-needed.  @option{--as-needed} causes a DT_NEEDED tag to only be emitted
Nicholas Clifton 7bd7de
-for a library that satisfies a symbol reference from regular objects
Nicholas Clifton 7bd7de
-which is undefined at the point that the library was linked, or, if
Nicholas Clifton 7bd7de
-the library is not found in the DT_NEEDED lists of other libraries
Nicholas Clifton 7bd7de
-linked up to that point, a reference from another dynamic library.
Nicholas Clifton 7bd7de
+needed or not.  @option{--as-needed} causes a DT_NEEDED tag to only be
Nicholas Clifton 7bd7de
+emitted for a library that satisfies an undefined symbol reference
Nicholas Clifton 7bd7de
+from a regular object file or, if the library is not found in the
Nicholas Clifton 7bd7de
+DT_NEEDED lists of other libraries linked up to that point, an
Nicholas Clifton 7bd7de
+undefined symbol reference from another dynamic library.
Nicholas Clifton 7bd7de
 @option{--no-as-needed} restores the default behaviour.
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
 @kindex --add-needed
Nicholas Clifton 7bd7de
 @kindex --no-add-needed
Nicholas Clifton 7bd7de
 @item --add-needed
Nicholas Clifton 7bd7de
 @itemx --no-add-needed
Nicholas Clifton 7bd7de
-This option affects the treatment of dynamic libraries from ELF
Nicholas Clifton 7bd7de
-DT_NEEDED tags in dynamic libraries mentioned on the command line after
Nicholas Clifton 7bd7de
-the @option{--no-add-needed} option.  Normally, the linker will add
Nicholas Clifton 7bd7de
-a DT_NEEDED tag for each dynamic library from DT_NEEDED tags.
Nicholas Clifton 7bd7de
-@option{--no-add-needed} causes DT_NEEDED tags will never be emitted
Nicholas Clifton 7bd7de
-for those libraries from DT_NEEDED tags. @option{--add-needed} restores
Nicholas Clifton 7bd7de
-the default behaviour.
Nicholas Clifton 7bd7de
+These two options have been deprecated because of the similarity of
Nicholas Clifton 7bd7de
+their names to the @option{--as-needed} and @option{--no-as-needed}
Nicholas Clifton 7bd7de
+options.  They have been replaced by @option{--copy-dt-needed-entries}
Nicholas Clifton 7bd7de
+and @option{--no-copy-dt-needed-entries}.
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
 @kindex -assert @var{keyword}
Nicholas Clifton 7bd7de
 @item -assert @var{keyword}
Nicholas Clifton 7bd7de
@@ -1253,6 +1250,29 @@ Section overlap is not usually checked f
Nicholas Clifton 7bd7de
 force checking in that case by using the @option{--check-sections}
Nicholas Clifton 7bd7de
 option.
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
+@kindex --copy-dt-needed-entries
Nicholas Clifton 7bd7de
+@kindex --no-copy-dt-needed-entries
Nicholas Clifton 7bd7de
+@item --copy-dt-needed-entries
Nicholas Clifton 7bd7de
+@itemx --no-copy-dt-needed-entries
Nicholas Clifton 7bd7de
+This option affects the treatment of dynamic libraries referred to 
Nicholas Clifton 7bd7de
+by DT_NEEDED tags @emph{inside} ELF dynamic libraries mentioned on the
Nicholas Clifton 7bd7de
+command line.  Normally the linker will add a DT_NEEDED tag to the
Nicholas Clifton 7bd7de
+output binary for each library mentioned in a DT_NEEDED tag in an
Nicholas Clifton 7bd7de
+input dynamic library.  With @option{--no-copy-dt-needed-entries}
Nicholas Clifton 7bd7de
+specified on the command line however any dynamic libraries that
Nicholas Clifton 7bd7de
+follow it will have their DT_NEEDED entries ignored.  The default
Nicholas Clifton 7bd7de
+behaviour can be restored with @option{--copy-dt-needed-entries}.
Nicholas Clifton 7bd7de
+
Nicholas Clifton 7bd7de
+This option also has an effect on the resolution of symbols in dynamic
Nicholas Clifton 7bd7de
+libraries.  With the default setting dynamic libraries mentioned on
Nicholas Clifton 7bd7de
+the command line will be recursively searched, following their
Nicholas Clifton 7bd7de
+DT_NEEDED tags to other libraries, in order to resolve symbols
Nicholas Clifton 7bd7de
+required by the output binary.  With
Nicholas Clifton 7bd7de
+@option{--no-copy-dt-needed-entries} specified however the searching
Nicholas Clifton 7bd7de
+of dynamic libraries that follow it will stop with the dynamic
Nicholas Clifton 7bd7de
+library itself.  No DT_NEEDED links will be traversed to resolve
Nicholas Clifton 7bd7de
+symbols.
Nicholas Clifton 7bd7de
+
Nicholas Clifton 7bd7de
 @cindex cross reference table
Nicholas Clifton 7bd7de
 @kindex --cref
Nicholas Clifton 7bd7de
 @item --cref
Nicholas Clifton 8d40e3
diff -rup ../binutils-2.20.51.0.2/ld/lexsup.c ./ld/lexsup.c
Nicholas Clifton 8d40e3
--- ../binutils-2.20.51.0.2/ld/lexsup.c	2009-10-09 23:26:22.000000000 +0100
Nicholas Clifton 8d40e3
+++ ./ld/lexsup.c	2010-01-13 16:01:15.000000000 +0000
Nicholas Clifton 7bd7de
@@ -125,10 +125,10 @@ enum option_values
Nicholas Clifton 7bd7de
   OPTION_SPLIT_BY_RELOC,
Nicholas Clifton 7bd7de
   OPTION_SPLIT_BY_FILE ,
Nicholas Clifton 7bd7de
   OPTION_WHOLE_ARCHIVE,
Nicholas Clifton 7bd7de
-  OPTION_ADD_NEEDED,
Nicholas Clifton 7bd7de
-  OPTION_NO_ADD_NEEDED,
Nicholas Clifton 7bd7de
-  OPTION_AS_NEEDED,
Nicholas Clifton 7bd7de
-  OPTION_NO_AS_NEEDED,
Nicholas Clifton 7bd7de
+  OPTION_ADD_DT_NEEDED_FOR_DYNAMIC,
Nicholas Clifton 7bd7de
+  OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC,
Nicholas Clifton 7bd7de
+  OPTION_ADD_DT_NEEDED_FOR_REGULAR,
Nicholas Clifton 7bd7de
+  OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR,
Nicholas Clifton 7bd7de
   OPTION_WRAP,
Nicholas Clifton 7bd7de
   OPTION_FORCE_EXE_SUFFIX,
Nicholas Clifton 7bd7de
   OPTION_GC_SECTIONS,
Nicholas Clifton 7bd7de
@@ -333,19 +333,22 @@ static const struct ld_option ld_options
Nicholas Clifton 7bd7de
      OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH},
Nicholas Clifton 7bd7de
     '\0', NULL, N_("Reject input files whose architecture is unknown"),
Nicholas Clifton 7bd7de
     TWO_DASHES },
Nicholas Clifton 7bd7de
-  { {"add-needed", no_argument, NULL, OPTION_ADD_NEEDED},
Nicholas Clifton 7bd7de
-    '\0', NULL, N_("Set DT_NEEDED tags for DT_NEEDED entries in\n"
Nicholas Clifton 7bd7de
-		   "                                following dynamic libs"),
Nicholas Clifton 7bd7de
-    TWO_DASHES },
Nicholas Clifton 7bd7de
-  { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_NEEDED},
Nicholas Clifton 7bd7de
-    '\0', NULL, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n"
Nicholas Clifton 7bd7de
-		   "                                in following dynamic libs"),
Nicholas Clifton 7bd7de
-    TWO_DASHES },
Nicholas Clifton 7bd7de
-  { {"as-needed", no_argument, NULL, OPTION_AS_NEEDED},
Nicholas Clifton 7bd7de
+
Nicholas Clifton 7bd7de
+  /* The next two options are deprecated because of their similarity to
Nicholas Clifton 7bd7de
+     --as-needed and --no-as-needed.  They have been replaced by
Nicholas Clifton 7bd7de
+     --resolve-implicit-dynamic-symbols and
Nicholas Clifton 7bd7de
+     --no-resolve-implicit-dynamic-symbols.  */
Nicholas Clifton 7bd7de
+  { {"add-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
Nicholas Clifton 7bd7de
+    '\0', NULL, NULL, NO_HELP },
Nicholas Clifton 7bd7de
+  { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
Nicholas Clifton 7bd7de
+    '\0', NULL, NULL, NO_HELP },
Nicholas Clifton 7bd7de
+
Nicholas Clifton 7bd7de
+  { {"as-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_REGULAR},
Nicholas Clifton 7bd7de
     '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"),
Nicholas Clifton 7bd7de
     TWO_DASHES },
Nicholas Clifton 7bd7de
-  { {"no-as-needed", no_argument, NULL, OPTION_NO_AS_NEEDED},
Nicholas Clifton 7bd7de
-    '\0', NULL, N_("Always set DT_NEEDED for following dynamic libs"),
Nicholas Clifton 7bd7de
+  { {"no-as-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR},
Nicholas Clifton 7bd7de
+    '\0', NULL, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
Nicholas Clifton 7bd7de
+		   "                                the command line"),
Nicholas Clifton 7bd7de
     TWO_DASHES },
Nicholas Clifton 7bd7de
   { {"assert", required_argument, NULL, OPTION_ASSERT},
Nicholas Clifton 7bd7de
     '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
Nicholas Clifton 7bd7de
@@ -373,6 +376,15 @@ static const struct ld_option ld_options
Nicholas Clifton 7bd7de
   { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
Nicholas Clifton 7bd7de
     '\0', NULL, N_("Do not check section addresses for overlaps"),
Nicholas Clifton 7bd7de
     TWO_DASHES },
Nicholas Clifton 7bd7de
+  { {"copy-dt-needed-entries", no_argument, NULL,
Nicholas Clifton 7bd7de
+     OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
Nicholas Clifton 7bd7de
+    '\0', NULL, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
Nicholas Clifton 7bd7de
+    TWO_DASHES },
Nicholas Clifton 7bd7de
+  { {"no-copy-dt-needed-entries", no_argument, NULL,
Nicholas Clifton 7bd7de
+     OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
Nicholas Clifton 7bd7de
+    '\0', NULL, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
Nicholas Clifton 7bd7de
+    TWO_DASHES },
Nicholas Clifton 7bd7de
+
Nicholas Clifton 7bd7de
   { {"cref", no_argument, NULL, OPTION_CREF},
Nicholas Clifton 7bd7de
     '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
Nicholas Clifton 7bd7de
   { {"defsym", required_argument, NULL, OPTION_DEFSYM},
Nicholas Clifton 7bd7de
@@ -1373,17 +1385,17 @@ parse_args (unsigned argc, char **argv)
Nicholas Clifton 7bd7de
 	case OPTION_WHOLE_ARCHIVE:
Nicholas Clifton 7bd7de
 	  whole_archive = TRUE;
Nicholas Clifton 7bd7de
 	  break;
Nicholas Clifton 7bd7de
-	case OPTION_ADD_NEEDED:
Nicholas Clifton 7bd7de
-	  add_needed = TRUE;
Nicholas Clifton 7bd7de
+	case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC:
Nicholas Clifton 7bd7de
+	  add_DT_NEEDED_for_dynamic = TRUE;
Nicholas Clifton 7bd7de
 	  break;
Nicholas Clifton 7bd7de
-	case OPTION_NO_ADD_NEEDED:
Nicholas Clifton 7bd7de
-	  add_needed = FALSE;
Nicholas Clifton 7bd7de
+	case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC:
Nicholas Clifton 7bd7de
+	  add_DT_NEEDED_for_dynamic = FALSE;
Nicholas Clifton 7bd7de
 	  break;
Nicholas Clifton 7bd7de
-	case OPTION_AS_NEEDED:
Nicholas Clifton 7bd7de
-	  as_needed = TRUE;
Nicholas Clifton 7bd7de
+	case OPTION_ADD_DT_NEEDED_FOR_REGULAR:
Nicholas Clifton 7bd7de
+	  add_DT_NEEDED_for_regular = TRUE;
Nicholas Clifton 7bd7de
 	  break;
Nicholas Clifton 7bd7de
-	case OPTION_NO_AS_NEEDED:
Nicholas Clifton 7bd7de
-	  as_needed = FALSE;
Nicholas Clifton 7bd7de
+	case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR:
Nicholas Clifton 7bd7de
+	  add_DT_NEEDED_for_regular = FALSE;
Nicholas Clifton 7bd7de
 	  break;
Nicholas Clifton 7bd7de
 	case OPTION_WRAP:
Nicholas Clifton 7bd7de
 	  add_wrap (optarg);
Nicholas Clifton 8d40e3
diff -rup ../binutils-2.20.51.0.2/ld/NEWS ./ld/NEWS
Nicholas Clifton 8d40e3
--- ../binutils-2.20.51.0.2/ld/NEWS	2010-01-20 08:27:18.000000000 +0000
Nicholas Clifton 8d40e3
+++ ./ld/NEWS	2010-01-13 16:01:16.000000000 +0000
Nicholas Clifton 7bd7de
@@ -1,5 +1,8 @@
Nicholas Clifton 7bd7de
 -*- text -*-
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
+* --add-needed renamed to --copy-dt-needed-entries in order to avoid confusion
Nicholas Clifton 7bd7de
+  with --as-needed option.
Nicholas Clifton 7bd7de
+
Nicholas Clifton 7bd7de
 * Add support for the Renesas RX processor.
Nicholas Clifton 7bd7de
 
Nicholas Clifton 7bd7de
 Changes in 2.20: