Fix for bnc#830516, aka http://sourceware.org/bugzilla/show_bug.cgi?id=15762,
some broken patches lead to .gnu.warning.* not to be emitted into
libc.so, so that linking programs against the dynamic library didn't
warn about obsolete/dangerous symbols.

bfd/

2013-07-25  Alan Modra  <amodra@gmail.com>

	PR ld/15762
	PR ld/12761
	* elflink.c (elf_link_add_object_symbols): Correct test in
	last patch.  Remove unnecessary code.

2013-07-20  Alan Modra  <amodra@gmail.com>

	PR ld/15762
	PR ld/12761
	* elflink.c (elf_link_add_object_symbols): Don't clobber
	.gnu.warning.symbol sections when shared.

ld/testsuite/

2013-07-24  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/15762
	* ld-elf/shared.exp (build_tests): Check .gnu.warning section
	in the libbarw.so library.
	* ld-elf/libbarw.rd: New.

	* lib/ld-lib.exp (run_cc_link_tests): Support checking on
	output with warning message.

Index: ld/testsuite/ld-elf/shared.exp
===================================================================
--- ld/testsuite/ld-elf/shared.exp.orig	2013-08-28 16:03:16.000000000 +0200
+++ ld/testsuite/ld-elf/shared.exp	2013-08-28 16:03:20.000000000 +0200
@@ -50,7 +50,7 @@ set build_tests {
    {begin.c end.c} {} "libbar.so"}
   {"Build warn libbar.so"
    "-shared" "-fPIC"
-   {beginwarn.c end.c} {} "libbarw.so"
+   {beginwarn.c end.c} {{readelf {-S --wide} libbarw.rd}} "libbarw.so"
     "C" "^.*\\\): warning: function foo is deprecated$"}
   {"Build hidden libbar.so"
    "-shared" "-fPIC"
Index: ld/testsuite/ld-elf/libbarw.rd
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ ld/testsuite/ld-elf/libbarw.rd	2013-08-28 16:03:20.000000000 +0200
@@ -0,0 +1,3 @@
+#...
+  \[[ 0-9]+\] \.gnu.warning.foo[ \t]+PROGBITS[ \t0-9a-f]+.*
+#pass
Index: bfd/elflink.c
===================================================================
--- bfd/elflink.c.orig	2013-08-28 16:03:16.000000000 +0200
+++ bfd/elflink.c	2013-08-28 16:03:56.000000000 +0200
@@ -3381,6 +3381,7 @@ elf_link_add_object_symbols (bfd *abfd,
   long old_dynsymcount = 0;
   size_t tabsize = 0;
   size_t hashsize = 0;
+  asection *s;
 
   htab = elf_hash_table (info);
   bed = get_elf_backend_data (abfd);
@@ -3422,75 +3423,64 @@ elf_link_add_object_symbols (bfd *abfd,
      symbol.  This differs from .gnu.warning sections, which generate
      warnings when they are included in an output file.  */
   /* PR 12761: Also generate this warning when building shared libraries.  */
-  if (info->executable || info->shared)
+  for (s = abfd->sections; s != NULL; s = s->next)
     {
-      asection *s;
+      const char *name;
 
-      for (s = abfd->sections; s != NULL; s = s->next)
+      name = bfd_get_section_name (abfd, s);
+      if (CONST_STRNEQ (name, ".gnu.warning."))
 	{
-	  const char *name;
+	  char *msg;
+	  bfd_size_type sz;
 
-	  name = bfd_get_section_name (abfd, s);
-	  if (CONST_STRNEQ (name, ".gnu.warning."))
+	  name += sizeof ".gnu.warning." - 1;
+
+	  /* If this is a shared object, then look up the symbol
+	     in the hash table.  If it is there, and it is already
+	     been defined, then we will not be using the entry
+	     from this shared object, so we don't need to warn.
+	     FIXME: If we see the definition in a regular object
+	     later on, we will warn, but we shouldn't.  The only
+	     fix is to keep track of what warnings we are supposed
+	     to emit, and then handle them all at the end of the
+	     link.  */
+	  if (dynamic)
 	    {
-	      char *msg;
-	      bfd_size_type sz;
+	      struct elf_link_hash_entry *h;
+
+	      h = elf_link_hash_lookup (htab, name, FALSE, FALSE, TRUE);
+
+	      /* FIXME: What about bfd_link_hash_common?  */
+	      if (h != NULL
+		  && (h->root.type == bfd_link_hash_defined
+		      || h->root.type == bfd_link_hash_defweak))
+		continue;
+	    }
 
-	      name += sizeof ".gnu.warning." - 1;
+	  sz = s->size;
+	  msg = (char *) bfd_alloc (abfd, sz + 1);
+	  if (msg == NULL)
+	    goto error_return;
 
-	      /* If this is a shared object, then look up the symbol
-		 in the hash table.  If it is there, and it is already
-		 been defined, then we will not be using the entry
-		 from this shared object, so we don't need to warn.
-		 FIXME: If we see the definition in a regular object
-		 later on, we will warn, but we shouldn't.  The only
-		 fix is to keep track of what warnings we are supposed
-		 to emit, and then handle them all at the end of the
-		 link.  */
-	      if (dynamic)
-		{
-		  struct elf_link_hash_entry *h;
-
-		  h = elf_link_hash_lookup (htab, name, FALSE, FALSE, TRUE);
-
-		  /* FIXME: What about bfd_link_hash_common?  */
-		  if (h != NULL
-		      && (h->root.type == bfd_link_hash_defined
-			  || h->root.type == bfd_link_hash_defweak))
-		    {
-		      /* We don't want to issue this warning.  Clobber
-			 the section size so that the warning does not
-			 get copied into the output file.  */
-		      s->size = 0;
-		      continue;
-		    }
-		}
-
-	      sz = s->size;
-	      msg = (char *) bfd_alloc (abfd, sz + 1);
-	      if (msg == NULL)
-		goto error_return;
-
-	      if (! bfd_get_section_contents (abfd, s, msg, 0, sz))
-		goto error_return;
-
-	      msg[sz] = '\0';
-
-	      if (! (_bfd_generic_link_add_one_symbol
-		     (info, abfd, name, BSF_WARNING, s, 0, msg,
-		      FALSE, bed->collect, NULL)))
-		goto error_return;
-
-	      if (! info->relocatable)
-		{
-		  /* Clobber the section size so that the warning does
-		     not get copied into the output file.  */
-		  s->size = 0;
-
-		  /* Also set SEC_EXCLUDE, so that symbols defined in
-		     the warning section don't get copied to the output.  */
-		  s->flags |= SEC_EXCLUDE;
-		}
+	  if (! bfd_get_section_contents (abfd, s, msg, 0, sz))
+	    goto error_return;
+
+	  msg[sz] = '\0';
+
+	  if (! (_bfd_generic_link_add_one_symbol
+		 (info, abfd, name, BSF_WARNING, s, 0, msg,
+		  FALSE, bed->collect, NULL)))
+	    goto error_return;
+
+	  if (!info->relocatable && info->executable)
+	    {
+	      /* Clobber the section size so that the warning does
+		 not get copied into the output file.  */
+	      s->size = 0;
+
+	      /* Also set SEC_EXCLUDE, so that symbols defined in
+		 the warning section don't get copied to the output.  */
+	      s->flags |= SEC_EXCLUDE;
 	    }
 	}
     }
@@ -3516,7 +3506,6 @@ elf_link_add_object_symbols (bfd *abfd,
     goto error_return;
   else
     {
-      asection *s;
       const char *soname = NULL;
       char *audit = NULL;
       struct bfd_link_needed_list *rpath = NULL, *runpath = NULL;
