PATCH: PR 233: Check non-debug local references to discarded sections

H. J. Lu hjl@lucon.org
Wed Jun 30 04:39:00 GMT 2004


On Wed, Jun 30, 2004 at 01:25:07PM +0930, Alan Modra wrote:
> On Tue, Jun 29, 2004 at 09:13:16AM -0700, H. J. Lu wrote:
> > @@ -6277,6 +6277,10 @@ elf_section_ignore_discarded_relocs (ase
> >        && (*bed->elf_backend_ignore_discarded_relocs) (sec))
> >      return TRUE;
> >  
> > +  /* Catch all .eh_frame sections.  */
> > +  if (strcmp (sec->name, ".eh_frame") == 0)
> > +    return TRUE;
> > +
> >    return FALSE;
> >  }
> 
> Huh?  Why wasn't sec->sec_info_type == ELF_INFO_TYPE_EH_FRAME?

Because some ld tests have some bogus .eh_frame sections which won't
have it set.

> 
> > @@ -6593,9 +6596,11 @@ elf_link_input_bfd (struct elf_final_lin
> >  			  else
> >  			    finfo->info->callbacks->error_handler
> >  			      (LD_DEFINITION_IN_DISCARDED_SECTION,
> > -			       _("%T: discarded in section `%s' from %s\n"),
> > +			       _("`%T' referenced in section `%s' from %s: discarded in section `%s' from %s\n"),
> >  			       h->root.root.string,
> >  			       h->root.root.string,
> > +			       o->name,
> > +			       bfd_archive_filename (o->owner),
> >  			       h->root.u.def.section->name,
> >  			       bfd_archive_filename (h->root.u.def.section->owner));
> >  			}
> 
> You can't call bfd_archive_filename twice in the one error message,
> as it uses a static buffer.
> 

Here is the new one.


H.J.
-------------- next part --------------
bfd/

2004-06-29  H.J. Lu  <hongjiu.lu@intel.com>

	PR 233
	* elflink.c (elf_section_ignore_discarded_relocs): Return
	TRUE for .eh_frame sections.
	(elf_link_input_bfd): Issue an error for non-debug local
	references to discarded sections and report their locations.

ld/testsuite/

2004-06-29  H.J. Lu  <hongjiu.lu@intel.com>

	PR 233
	* ld-discard/extern.d: Updated.
	* ld-discard/start.d: Likewise.
	* ld-discard/static.d: Likewise.

--- binutils/bfd/elflink.c.linkonce	2004-06-28 19:02:08.000000000 -0700
+++ binutils/bfd/elflink.c	2004-06-29 21:35:22.046587022 -0700
@@ -6277,6 +6277,11 @@ elf_section_ignore_discarded_relocs (ase
       && (*bed->elf_backend_ignore_discarded_relocs) (sec))
     return TRUE;
 
+  /* FIXME: Catch all bogus .eh_frame sections. Some linker tests
+     use them.  */
+  if (strcmp (sec->name, ".eh_frame") == 0)
+    return TRUE;
+
   return FALSE;
 }
 
@@ -6582,8 +6587,7 @@ elf_link_input_bfd (struct elf_final_lin
 			    {
 			      BFD_ASSERT (r_symndx != 0);
 			      /* Try to preserve debug information.  */
-			      if ((o->flags & SEC_DEBUGGING) != 0
-				  && sec->kept_section != NULL
+			      if (sec->kept_section != NULL
 				  && sec->size == sec->kept_section->size)
 				h->root.u.def.section
 				  = sec->kept_section;
@@ -6591,13 +6595,20 @@ elf_link_input_bfd (struct elf_final_lin
 				memset (rel, 0, sizeof (*rel));
 			    }
 			  else
-			    finfo->info->callbacks->error_handler
-			      (LD_DEFINITION_IN_DISCARDED_SECTION,
-			       _("%T: discarded in section `%s' from %s\n"),
-			       h->root.root.string,
-			       h->root.root.string,
-			       h->root.u.def.section->name,
-			       bfd_archive_filename (h->root.u.def.section->owner));
+			    {
+			      char *r_name
+				= xstrdup (bfd_archive_filename (o->owner));
+			      finfo->info->callbacks->error_handler
+				(LD_DEFINITION_IN_DISCARDED_SECTION,
+				 _("`%T' referenced in section `%s' from %s: discarded in section `%s' from %s\n"),
+				 h->root.root.string,
+				 h->root.root.string,
+				 o->name, r_name,
+				 h->root.u.def.section->name,
+				 bfd_archive_filename (h->root.u.def.section->owner));
+			      if (r_name)
+				free (r_name);
+			    }
 			}
 		    }
 		  else
@@ -6606,13 +6617,11 @@ elf_link_input_bfd (struct elf_final_lin
 
 		      if (sec != NULL && elf_discarded_section (sec))
 			{
-			  if ((o->flags & SEC_DEBUGGING) != 0
-			      || (sec->flags & SEC_LINK_ONCE) != 0)
+			  if ((o->flags & SEC_DEBUGGING) != 0)
 			    {
 			      BFD_ASSERT (r_symndx != 0);
 			      /* Try to preserve debug information.  */
-			      if ((o->flags & SEC_DEBUGGING) != 0
-				  && sec->kept_section != NULL
+			      if (sec->kept_section != NULL
 				  && sec->size == sec->kept_section->size)
 				finfo->sections[r_symndx]
 				  = sec->kept_section;
@@ -6634,8 +6643,8 @@ elf_link_input_bfd (struct elf_final_lin
 				buf = (char *) "local symbol";
 			      finfo->info->callbacks->error_handler
 				(LD_DEFINITION_IN_DISCARDED_SECTION,
-				 _("%T: discarded in section `%s' from %s\n"),
-				 buf, buf, sec->name,
+				 _("`%T' referenced in section `%s': discarded in section `%s' from %s\n"),
+				 buf, buf, o->name, sec->name,
 				 bfd_archive_filename (input_bfd));
 			      if (ok != -1)
 				free (buf);
--- binutils/ld/testsuite/ld-discard/extern.d.linkonce	2003-06-04 10:28:29.000000000 -0700
+++ binutils/ld/testsuite/ld-discard/extern.d	2004-06-29 11:22:55.000000000 -0700
@@ -1,3 +1,3 @@
 #source: extern.s
 #ld: -T discard.ld
-#error: data: discarded in section `\.data\.exit' from tmpdir/dump0.o
+#error: `data' referenced in section `\.text' from tmpdir/dump0.o: discarded in section `\.data\.exit' from tmpdir/dump0.o
--- binutils/ld/testsuite/ld-discard/start.d.linkonce	2003-06-04 10:28:29.000000000 -0700
+++ binutils/ld/testsuite/ld-discard/start.d	2004-06-29 11:22:55.000000000 -0700
@@ -1,4 +1,4 @@
 #source: start.s
 #source: exit.s
 #ld: -T discard.ld
-#error: data: discarded in section `\.data\.exit' from tmpdir/dump1.o
+#error: `data' referenced in section `\.text' from tmpdir/dump0.o: discarded in section `\.data\.exit' from tmpdir/dump1.o
--- binutils/ld/testsuite/ld-discard/static.d.linkonce	2003-06-04 10:28:29.000000000 -0700
+++ binutils/ld/testsuite/ld-discard/static.d	2004-06-29 11:22:55.000000000 -0700
@@ -1,3 +1,3 @@
 #source: static.s
 #ld: -T discard.ld
-#error: local symbol 0: discarded in section `\.data\.exit' from tmpdir/dump0.o
+#error: `local symbol 0' referenced in section `\.text': discarded in section `\.data\.exit' from tmpdir/dump0.o


More information about the Binutils mailing list