PATCH: PR binutils/1991: objcopy does not update sh_link correctly

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

PATCH: PR binutils/1991: objcopy does not update sh_link correctly

H.J. Lu-27
elf_linked_to_section always points to the input section. We didn't
handle objcopy correctly. This patch fixes it.


H.J.
---
2005-12-07  H.J. Lu  <[hidden email]>

        PR binutils/1991
        * elf.c (assign_section_numbers): Properly handle SHF_LINK_ORDER
        for objcopy.

--- bfd/elf.c.link-order 2005-11-04 11:38:00.000000000 -0800
+++ bfd/elf.c 2005-12-07 10:33:35.000000000 -0800
@@ -3053,10 +3053,10 @@ assign_section_numbers (bfd *abfd, struc
   s = elf_linked_to_section (sec);
   if (s)
     {
+      /* elf_linked_to_section points to the input section.  */
       if (link_info != NULL)
  {
-  /* For linker, elf_linked_to_section points to the
-     input section.  */
+  /* Check discarded linkonce section.  */
   if (elf_discarded_section (s))
     {
       asection *kept;
@@ -3074,9 +3074,26 @@ assign_section_numbers (bfd *abfd, struc
  }
       s = kept;
     }
+ }
+      if (link_info != NULL)
+ {
+  /* Handle linker.  */
   s = s->output_section;
   BFD_ASSERT (s != NULL);
  }
+      else
+ {
+  /* Handle objcopy. */
+  if (s->output_section == NULL)
+    {
+      (*_bfd_error_handler)
+ (_("%B: sh_link of section `%A' points to removed section `%A' of `%B'"),
+ abfd, d->this_hdr.bfd_section, s, s->owner);
+      bfd_set_error (bfd_error_bad_value);
+      return FALSE;
+    }
+  s = s->output_section;
+ }
       d->this_hdr.sh_link = elf_section_data (s)->this_idx;
     }
   else