Don't segfault on discarded section dynsyms
authorAlan Modra <amodra@gmail.com>
Wed, 29 Jul 2020 08:04:18 +0000 (17:34 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 29 Jul 2020 08:09:54 +0000 (17:39 +0930)
We get lots of errors before we get to this code, but let's not
segfault.

* elflink.c (bfd_elf_final_link): Don't segfault on local dynsyms
defined in excluded sections.

bfd/ChangeLog
bfd/elflink.c

index 1e7fb4a87537278cede4eca4d0bff43ab4c6a0d4..8e8dc99c1aa487aeaab4d965e88c25324652f1b4 100644 (file)
@@ -1,3 +1,8 @@
+2020-07-29  Alan Modra  <amodra@gmail.com>
+
+       * elflink.c (bfd_elf_final_link): Don't segfault on local dynsyms
+       defined in excluded sections.
+
 2020-07-28  Alan Modra  <amodra@gmail.com>
 
        * elf.c (assign_section_numbers): Comment.  Don't segfault on
index a3823e63222d09984e75c91304d20b6fe46f7687..5089616aeefb103ffc28aa52bf2aeb8fc1f92815 100644 (file)
@@ -12599,10 +12599,13 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
                 the original st_name with the dynstr_index.  */
              sym = e->isym;
              sym.st_other &= ~ELF_ST_VISIBILITY (-1);
+             sym.st_shndx = SHN_UNDEF;
 
              s = bfd_section_from_elf_index (e->input_bfd,
                                              e->isym.st_shndx);
-             if (s != NULL)
+             if (s != NULL
+                 && s->output_section != NULL
+                 && elf_section_data (s->output_section) != NULL)
                {
                  sym.st_shndx =
                    elf_section_data (s->output_section)->this_idx;