PATCH: ld/2008: Segfault on IA64, something to do with Unwind and section ordering

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

PATCH: ld/2008: Segfault on IA64, something to do with Unwind and section ordering

H.J. Lu-27
PR 1991 may leave bogus valus in the sh_link field, which leads to
PR 2008 where linker will segfault. This patch bails out if the section
which the sh_link field points to doesn't have an output section.


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

        PR ld/2008
        * elflink.c (elf_get_linked_section_vma): Bail out if the
        section which the sh_link field points to doesn't have an
        output section.

--- bfd/elflink.c.bad 2005-12-12 06:51:51.000000000 -0800
+++ bfd/elflink.c 2005-12-12 06:53:19.000000000 -0800
@@ -7600,8 +7600,19 @@ elf_get_linked_section_vma (struct bfd_l
     }
   else
     {
-      s = elf_shdrp[elfsec]->bfd_section;
-      return s->output_section->vma + s->output_offset;
+      asection *link = elf_shdrp[elfsec]->bfd_section;
+      /* PR 1991, 2008:
+ Some strip/objcopy may leave an incorrect value in sh_link.
+ We will bail out now.  */
+      if (link == NULL)
+ {
+  (*_bfd_error_handler)
+  (_("%B: sh_link [%d] in section `%A' is incorrect"),
+   s->owner, s, elfsec);
+  unlink_if_ordinary (s->output_section->owner->filename);
+  xexit (EXIT_FAILURE);
+ }
+      return link->output_section->vma + link->output_offset;
     }
 }
 
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: ld/2008: Segfault on IA64, something to do with Unwind and section ordering

H.J. Lu-27
On Mon, Dec 12, 2005 at 06:59:56AM -0800, H. J. Lu wrote:
> PR 1991 may leave bogus valus in the sh_link field, which leads to
> PR 2008 where linker will segfault. This patch bails out if the section
> which the sh_link field points to doesn't have an output section.
>
>

Here is an update. I moved the check from elf_get_linked_section_vma
to _bfd_elf_setup_sections.

Does anyone know why bfd_check_format_matches checks the default
target twice? This patch also removed the duplicate.



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

        PR ld/2008
        * elf.c (_bfd_elf_setup_sections): Return FALSE if
        elf_linked_to_section will be set to NULL.

        * format.c (bfd_check_format_matches): Don't check the default
        target twice.

--- bfd/elf.c.bad 2005-12-08 07:06:37.000000000 -0800
+++ bfd/elf.c 2005-12-12 11:04:26.000000000 -0800
@@ -654,8 +654,23 @@ _bfd_elf_setup_sections (bfd *abfd)
     }
   else
     {
+      asection *link;
+
       this_hdr = elf_elfsections (abfd)[elfsec];
-      elf_linked_to_section (s) = this_hdr->bfd_section;
+
+      /* PR 1991, 2008:
+ Some strip/objcopy may leave an incorrect value in
+ sh_link.  We don't want to proceed.  */
+      link = this_hdr->bfd_section;
+      if (link == NULL)
+ {
+  (*_bfd_error_handler)
+    (_("%B: sh_link [%d] in section `%A' is incorrect"),
+     s->owner, s, elfsec);
+  result = FALSE;
+ }
+
+      elf_linked_to_section (s) = link;
     }
  }
     }
--- bfd/format.c.bad 2005-10-07 13:47:31.000000000 -0700
+++ bfd/format.c 2005-12-12 11:14:20.000000000 -0800
@@ -217,7 +217,9 @@ bfd_check_format_matches (bfd *abfd, bfd
       const bfd_target *temp;
       bfd_error_type err;
 
-      if (*target == &binary_vec)
+      /* Don't check the default target twice.  */
+      if (*target == &binary_vec
+  || (!abfd->target_defaulted && *target == save_targ))
  continue;
 
       abfd->xvec = *target; /* Change BFD's target temporarily.  */
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: ld/2008: Segfault on IA64, something to do with Unwind and section ordering

Alan Modra
On Mon, Dec 12, 2005 at 11:44:00AM -0800, H. J. Lu wrote:
> 2005-12-12  H.J. Lu  <[hidden email]>
>
> PR ld/2008
> * elf.c (_bfd_elf_setup_sections): Return FALSE if
> elf_linked_to_section will be set to NULL.
>
> * format.c (bfd_check_format_matches): Don't check the default
> target twice.

OK.

--
Alan Modra
IBM OzLabs - Linux Technology Centre