This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb/binutils-2_29-branch] PR22431, powerpc64 ld segfault when .plt discarded


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e4495167d97f38d4e1f78b518e59e00a5533d768

commit e4495167d97f38d4e1f78b518e59e00a5533d768
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Nov 14 18:47:34 2017 +1030

    PR22431, powerpc64 ld segfault when .plt discarded
    
    The fix for the PR is to not use input_section->output_section->owner
    to get to the output bfd, but use the output bfd directly since it is
    available nowadays in struct bfd_link_info.
    
    I thought it worth warning when non-empty dynamic sections are
    discarded too, which meant a tweak to one of the ld tests to avoid the
    warning.
    
    bfd/
    	PR 22431
    	* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Warn on discarding
    	non-empty dynamic section.
    	(ppc_build_one_stub): Take elf_gp from output bfd, not output
    	section owner.
    	(ppc_size_one_stub, ppc64_elf_next_toc_section): Likewise.
    ld/
    	* testsuite/ld-elf/note-3.t: Don't discard .got.
    
    (cherry picked from commit 06bcf5416feae129e239476ab1408e038bba171d)

Diff:
---
 bfd/ChangeLog                | 11 +++++++++++
 bfd/elf64-ppc.c              | 16 ++++++++++------
 ld/ChangeLog                 |  6 ++++++
 ld/testsuite/ld-elf/note-3.t |  1 +
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 4ad3675..c8bcf8e 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,14 @@
+2017-11-24  Alan Modra  <amodra@gmail.com>
+
+	Apply from master
+	2017-11-14  Alan Modra  <amodra@gmail.com>
+	PR 22431
+	* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Warn on discarding
+	non-empty dynamic section.
+	(ppc_build_one_stub): Take elf_gp from output bfd, not output
+	section owner.
+	(ppc_size_one_stub, ppc64_elf_next_toc_section): Likewise.
+
 2017-11-05  Alan Modra  <amodra@gmail.com>
 
 	PR 22397
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index 3c8e286..e2d4ba1 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -10329,6 +10329,10 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
 	  continue;
 	}
 
+      if (bfd_is_abs_section (s->output_section))
+	_bfd_error_handler (_("warning: discarding dynamic section %s"),
+			    s->name);
+
       if ((s->flags & SEC_HAS_CONTENTS) == 0)
 	continue;
 
@@ -11123,7 +11127,7 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 	      + htab->brlt->output_section->vma);
 
       off = (dest
-	     - elf_gp (htab->brlt->output_section->owner)
+	     - elf_gp (info->output_bfd)
 	     - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
 
       if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
@@ -11274,7 +11278,7 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 	}
 
       off = (dest
-	     - elf_gp (plt->output_section->owner)
+	     - elf_gp (info->output_bfd)
 	     - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
 
       if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
@@ -11422,7 +11426,7 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 	plt = htab->elf.iplt;
       off += (plt->output_offset
 	      + plt->output_section->vma
-	      - elf_gp (plt->output_section->owner)
+	      - elf_gp (info->output_bfd)
 	      - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
 
       size = plt_stub_size (htab, stub_entry, off);
@@ -11525,7 +11529,7 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 	  off = (br_entry->offset
 		 + htab->brlt->output_offset
 		 + htab->brlt->output_section->vma
-		 - elf_gp (htab->brlt->output_section->owner)
+		 - elf_gp (info->output_bfd)
 		 - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
 
 	  if (info->emitrelocations)
@@ -11645,7 +11649,7 @@ ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec)
 	 output toc base plus 0x8000.  Making the input elf_gp an
 	 offset allows us to move the toc as a whole without
 	 recalculating input elf_gp.  */
-      off = htab->toc_curr - elf_gp (isec->output_section->owner);
+      off = htab->toc_curr - elf_gp (info->output_bfd);
       off += TOC_BASE_OFF;
 
       /* Die if someone uses a linker script that doesn't keep input
@@ -11674,7 +11678,7 @@ ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec)
     }
   addr = (htab->toc_first_sec->output_offset
 	  + htab->toc_first_sec->output_section->vma);
-  off = addr - elf_gp (isec->output_section->owner) + TOC_BASE_OFF;
+  off = addr - elf_gp (info->output_bfd) + TOC_BASE_OFF;
   elf_gp (isec->owner) = off;
 
   return TRUE;
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 364b104..0415ea9 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,9 @@
+2017-11-24  Alan Modra  <amodra@gmail.com>
+
+	Apply from master
+	2017-11-14  Alan Modra  <amodra@gmail.com>
+	* testsuite/ld-elf/note-3.t: Don't discard .got.
+
 2017-11-01  Alan Modra  <amodra@gmail.com>
 
 	Apply from master
diff --git a/ld/testsuite/ld-elf/note-3.t b/ld/testsuite/ld-elf/note-3.t
index 13324ae..4c617d8 100644
--- a/ld/testsuite/ld-elf/note-3.t
+++ b/ld/testsuite/ld-elf/note-3.t
@@ -17,6 +17,7 @@ SECTIONS
   
   .dynstr : { *(.dynstr) }
   .dynsym : { *(.dynsym) }
+  .got : { *(.got .toc) *(.igot) }
   .got.plt : { *(.got.plt) *(.igot.plt) }
   /DISCARD/ : { *(*) }
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]