XCOFF linker segmentation fault
authorAlan Modra <amodra@gmail.com>
Mon, 27 May 2019 06:08:55 +0000 (15:38 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 28 May 2019 00:35:02 +0000 (10:05 +0930)
The XCOFF linker temporarily trims the output bfd section list,
without adjusting section_count to suit.  This is a little rude, but
the dwarf line number code can easily cope with this situation.  So
check for a NULL end of list as well as limiting the saved section
VMAs to the first section_count list entries.

Also fixes
-FAIL: Weak test 3 (main, static) (32-bit)
-FAIL: Weak test 3 (main, static) (64-bit)

PR 24596
* dwarf2.c (save_section_vma, section_vma_same): Check for NULL
end of section list as well as section_count.
* xcofflink.c (xcoff_link_add_symbols): Fix temporarily changed
section list before returning error.

bfd/ChangeLog
bfd/dwarf2.c
bfd/xcofflink.c

index 18bed0699d45821fa2595837e53be5ecff4f8c0a..3460d78f3f3cce9f61ae4c70fbb26b6ea51d2988 100644 (file)
@@ -1,3 +1,11 @@
+2019-05-28  Alan Modra  <amodra@gmail.com>
+
+       PR 24596
+       * dwarf2.c (save_section_vma, section_vma_same): Check for NULL
+       end of section list as well as section_count.
+       * xcofflink.c (xcoff_link_add_symbols): Fix temporarily changed
+       section list before returning error.
+
 2019-05-27  Alan Modra  <amodra@gmail.com>
 
        * elf.c (bfd_elf_set_group_contents): Exit on zero size section.
index 76af009e33aaf19014fc713ab9122891280cba7d..65c41611710e33462dc328ce827caa38d87a49f9 100644 (file)
@@ -4272,7 +4272,9 @@ save_section_vma (const bfd *abfd, struct dwarf2_debug *stash)
   if (stash->sec_vma == NULL)
     return FALSE;
   stash->sec_vma_count = abfd->section_count;
-  for (i = 0, s = abfd->sections; i < abfd->section_count; i++, s = s->next)
+  for (i = 0, s = abfd->sections;
+       s != NULL && i < abfd->section_count;
+       i++, s = s->next)
     {
       if (s->output_section != NULL)
        stash->sec_vma[i] = s->output_section->vma + s->output_offset;
@@ -4301,7 +4303,9 @@ section_vma_same (const bfd *abfd, const struct dwarf2_debug *stash)
   if (abfd->section_count != stash->sec_vma_count)
     return FALSE;
 
-  for (i = 0, s = abfd->sections; i < abfd->section_count; i++, s = s->next)
+  for (i = 0, s = abfd->sections;
+       s != NULL && i < abfd->section_count;
+       i++, s = s->next)
     {
       bfd_vma vma;
 
index e7f50d169069477278e9316b561f875a9ff356bb..f9c12e40f343963805e8a76825fc971ce15a9eeb 100644 (file)
@@ -1882,7 +1882,7 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
 
       if (EXTERN_SYM_P (sym.n_sclass))
        {
-         bfd_boolean copy;
+         bfd_boolean copy, ok;
          flagword flags;
 
          BFD_ASSERT (section != NULL);
@@ -2022,12 +2022,12 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
          BFD_ASSERT (last_real->next == first_csect);
          last_real->next = NULL;
          flags = (sym.n_sclass == C_EXT ? BSF_GLOBAL : BSF_WEAK);
-         if (! (_bfd_generic_link_add_one_symbol
-                (info, abfd, name, flags, section, value,
-                 NULL, copy, TRUE,
-                 (struct bfd_link_hash_entry **) sym_hash)))
-           goto error_return;
+         ok = (_bfd_generic_link_add_one_symbol
+               (info, abfd, name, flags, section, value, NULL, copy, TRUE,
+                (struct bfd_link_hash_entry **) sym_hash));
          last_real->next = first_csect;
+         if (!ok)
+           goto error_return;
 
          if (smtyp == XTY_CM)
            {
This page took 0.030956 seconds and 4 git commands to generate.