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 22:14:41 +0000 (08:44 +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 ac3f160b0781b018767011116137dccaad0710eb..cf5c41b5d483b05b654287c22f4a0438f5bb02f5 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>
 
        * elf64-alpha.c (elf64_alpha_size_dynamic_sections): Only emit
index 30998b1ade11b9576b254c103677746e267d56e3..d82193560e2ad4d3fa097a58532034432906d304 100644 (file)
@@ -10418,7 +10418,6 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
                                 struct bfd_link_info *info)
 {
   asection *sdyn;
-  asection *splt;
   struct ppc_elf_link_hash_table *htab;
   bfd_vma got;
   bfd *dynobj;
@@ -10431,10 +10430,6 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
   htab = ppc_elf_hash_table (info);
   dynobj = htab->elf.dynobj;
   sdyn = bfd_get_linker_section (dynobj, ".dynamic");
-  if (htab->is_vxworks)
-    splt = htab->elf.splt;
-  else
-    splt = NULL;
 
   got = 0;
   if (htab->elf.hgot != NULL)
@@ -10489,7 +10484,8 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
        }
     }
 
-  if (htab->elf.sgot != NULL)
+  if (htab->elf.sgot != NULL
+      && htab->elf.sgot->output_section != bfd_abs_section_ptr)
     {
       if (htab->elf.hgot->root.u.def.section == htab->elf.sgot
          || htab->elf.hgot->root.u.def.section == htab->elf.sgotplt)
@@ -10531,8 +10527,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)
+  if (htab->is_vxworks
+      && htab->elf.splt != NULL
+      && htab->elf.splt->size != 0
+      && htab->elf.splt->output_section != bfd_abs_section_ptr)
     {
+      asection *splt = htab->elf.splt;
       /* Use the right PLT. */
       const bfd_vma *plt_entry = (bfd_link_pic (info)
                                  ? ppc_elf_vxworks_pic_plt0_entry
index 56b94f9b8d8b7310d79b268e242eac138be6f500..4d90e0a1a6a130ec0397a5292a0f64704415bceb 100644 (file)
@@ -15603,7 +15603,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.  */
@@ -15615,7 +15616,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 3f41834689140e74c57f4bb07f86a1a5fc66af7e..4e1fb95f73413c999ab46226dff61c3ab39b89ab 100644 (file)
@@ -1,3 +1,9 @@
+2017-02-22  Alan Modra  <amodra@gmail.com>
+
+       * 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-15  Vladimir Radosavljevic  <Vladimir.Radosavljevic@imgtec.com>
 
        * mips.cc (Target_mips::Scan::get_reference_flags): Remove
index 4abfcec16d6efa765310d71758beb0eba698b0ed..1477a10d671d3f3593d4364e7616e1f01995bbb7 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
This page took 0.038163 seconds and 4 git commands to generate.