]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PowerPC ld segfault on script discarding dynamic sections
authorAlan Modra <amodra@gmail.com>
Tue, 21 Feb 2017 21:40:58 +0000 (08:10 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 21 Feb 2017 23:31:18 +0000 (10:01 +1030)
bfd/
* elf64-ppc.c (ppc64_elf_finish_dynamic_sections): Don't segfault
on .got or .plt output section being discarded by script.
* elf32-ppc.c (ppc_elf_finish_dynamic_sections): Likewise.  Move
vxworks splt temp.
gold/
* powerpc.cc (Target_powerpc::make_iplt_section): Check that
output_section exists before attempting add_output_section_data.
(Target_powerpc::make_brlt_section): Likewise.

bfd/ChangeLog
bfd/elf32-ppc.c
bfd/elf64-ppc.c
gold/ChangeLog
gold/powerpc.cc

index c511b2674c6a04454ce2cd73389e807f302c37ff..d8e4e99f1c35124f96e39357e884b9b7e231873c 100644 (file)
@@ -1,3 +1,10 @@
+2017-02-22  Alan Modra  <amodra@gmail.com>
+
+       * elf64-ppc.c (ppc64_elf_finish_dynamic_sections): Don't segfault
+       on .got or .plt output section being discarded by script.
+       * elf32-ppc.c (ppc_elf_finish_dynamic_sections): Likewise.  Move
+       vxworks splt temp.
+
 2017-02-21  Alan Modra  <amodra@gmail.com>
 
        Apply from master
index e42ef1cc885db0d86ec52937b628909e9817cf7c..8b191056cfe4fd71f57f2e363303528e3c5abcb9 100644 (file)
@@ -10303,11 +10303,6 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
   htab = ppc_elf_hash_table (info);
   dynobj = elf_hash_table (info)->dynobj;
   sdyn = bfd_get_linker_section (dynobj, ".dynamic");
-  if (htab->is_vxworks)
-    splt = bfd_get_linker_section (dynobj, ".plt");
-  else
-    splt = NULL;
-
   got = 0;
   if (htab->elf.hgot != NULL)
     got = SYM_VAL (htab->elf.hgot);
@@ -10370,7 +10365,8 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
        }
     }
 
-  if (htab->got != NULL)
+  if (htab->got != NULL
+      && htab->got->output_section != bfd_abs_section_ptr)
     {
       if (htab->elf.hgot->root.u.def.section == htab->got
          || htab->elf.hgot->root.u.def.section == htab->sgotplt)
@@ -10410,7 +10406,12 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
     }
 
   /* Fill in the first entry in the VxWorks procedure linkage table.  */
-  if (splt && splt->size > 0)
+  splt = NULL;
+  if (htab->is_vxworks)
+    splt = bfd_get_linker_section (dynobj, ".plt");
+  if (splt != NULL
+      && splt->size != 0
+      && splt->output_section != bfd_abs_section_ptr)
     {
       /* Use the right PLT. */
       const bfd_vma *plt_entry = (bfd_link_pic (info)
index dbd423029b26ae1045a0c9cc4cb7fd55fc64eabd..0b7f1d7d1eb5d1456eeae45a6c0639cbf6ad3031 100644 (file)
@@ -15532,7 +15532,8 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
        }
     }
 
-  if (htab->elf.sgot != NULL && htab->elf.sgot->size != 0)
+  if (htab->elf.sgot != NULL && htab->elf.sgot->size != 0
+      && htab->elf.sgot->output_section != bfd_abs_section_ptr)
     {
       /* Fill in the first entry in the global offset table.
         We use it to hold the link-time TOCbase.  */
@@ -15544,7 +15545,8 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
       elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 8;
     }
 
-  if (htab->elf.splt != NULL && htab->elf.splt->size != 0)
+  if (htab->elf.splt != NULL && htab->elf.splt->size != 0
+      && htab->elf.splt->output_section != bfd_abs_section_ptr)
     {
       /* Set .plt entry size.  */
       elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize
index 30d3244f744595c0695b6af176b7012b9a051439..59c60e7929c941cc46839d76b07b806b25378f35 100644 (file)
@@ -1,6 +1,10 @@
 2017-02-22  Alan Modra  <amodra@gmail.com>
 
        Apply from master
+       * powerpc.cc (Target_powerpc::make_iplt_section): Check that
+       output_section exists before attempting add_output_section_data.
+       (Target_powerpc::make_brlt_section): Likewise.
+
        2017-02-03  Alan Modra  <amodra@gmail.com>
        * powerpc.cc (Powerpc_relobj::make_toc_relative): Don't crash
        when no .toc section exists.
index 81f9bff1c5de3423a4cde258dfebb74437c329fb..2c70f9f8e4cd89c3db1609ead769579a0b8128ba 100644 (file)
@@ -3608,11 +3608,13 @@ Target_powerpc<size, big_endian>::make_iplt_section(Symbol_table* symtab,
       this->make_plt_section(symtab, layout);
 
       Reloc_section* iplt_rel = new Reloc_section(false);
-      this->rela_dyn_->output_section()->add_output_section_data(iplt_rel);
+      if (this->rela_dyn_->output_section())
+       this->rela_dyn_->output_section()->add_output_section_data(iplt_rel);
       this->iplt_
        = new Output_data_plt_powerpc<size, big_endian>(this, iplt_rel,
                                                        "** IPLT");
-      this->plt_->output_section()->add_output_section_data(this->iplt_);
+      if (this->plt_->output_section())
+       this->plt_->output_section()->add_output_section_data(this->iplt_);
     }
 }
 
@@ -3708,14 +3710,16 @@ Target_powerpc<size, big_endian>::make_brlt_section(Layout* layout)
        {
          // When PIC we can't fill in .branch_lt (like .plt it can be
          // a bss style section) but must initialise at runtime via
-         // dynamic relocats.
+         // dynamic relocations.
          this->rela_dyn_section(layout);
          brlt_rel = new Reloc_section(false);
-         this->rela_dyn_->output_section()->add_output_section_data(brlt_rel);
+         if (this->rela_dyn_->output_section())
+           this->rela_dyn_->output_section()
+             ->add_output_section_data(brlt_rel);
        }
       this->brlt_section_
        = new Output_data_brlt_powerpc<size, big_endian>(this, brlt_rel);
-      if (this->plt_ && is_pic)
+      if (this->plt_ && is_pic && this->plt_->output_section())
        this->plt_->output_section()
          ->add_output_section_data(this->brlt_section_);
       else