PR23207, hppa ld SIGSEGVs on invalid object files

Message ID 20180522055626.GX23663@bubble.grove.modra.org
State New
Headers show
Series
  • PR23207, hppa ld SIGSEGVs on invalid object files
Related show

Commit Message

Alan Modra May 22, 2018, 5:56 a.m.
We don't create PLT call stubs for anything in non-alloc sections,
so it doesn't pay to go looking for them.  The problem is that
non-alloc sections aren't processed by group_sections and thus don't
get a link_sec set up for them.

	PR 23207
	* elf32-hppa.c (final_link_relocate): Don't look for plt call
	stubs in non-alloc sections.


-- 
Alan Modra
Australia Development Lab, IBM

Comments

Alan Modra May 22, 2018, 12:50 p.m. | #1
On Tue, May 22, 2018 at 03:26:26PM +0930, Alan Modra wrote:
> 	PR 23207

> 	* elf32-hppa.c (final_link_relocate): Don't look for plt call

> 	stubs in non-alloc sections.


The last patch was enough to cure the testcase, but not the original
object file.  This patch does the same for hppa as is done for ppc64,
simply test for the section belonging to a group.  I've also
restricted stubs to load, alloc, code sections.

	PR 23207
	* elf32-hppa.c (hppa_get_stub_entry): Return NULL when link_sec
	is NULL.
	(elf32_hppa_size_stubs): Only create stubs for load, alloc, code
	sections.
	(final_link_relocate): Revert last change.

diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
index 5ad49abfe0..efab20fbd3 100644
--- a/bfd/elf32-hppa.c
+++ b/bfd/elf32-hppa.c
@@ -503,6 +503,8 @@ hppa_get_stub_entry (const asection *input_section,
      more than one stub used to reach say, printf, and we need to
      distinguish between them.  */
   id_sec = htab->stub_group[input_section->id].link_sec;
+  if (id_sec == NULL)
+    return NULL;
 
   if (hh != NULL && hh->hsh_cache != NULL
       && hh->hsh_cache->hh == hh
@@ -2795,6 +2797,9 @@ elf32_hppa_size_stubs
 	      /* If there aren't any relocs, then there's nothing more
 		 to do.  */
 	      if ((section->flags & SEC_RELOC) == 0
+		  || (section->flags & SEC_ALLOC) == 0
+		  || (section->flags & SEC_LOAD) == 0
+		  || (section->flags & SEC_CODE) == 0
 		  || section->reloc_count == 0)
 		continue;
 
@@ -3267,16 +3272,15 @@ final_link_relocate (asection *input_section,
     case R_PARISC_PCREL22F:
       /* If this call should go via the plt, find the import stub in
 	 the stub hash.  */
-      if ((input_section->flags & SEC_ALLOC) != 0
-	  && (sym_sec == NULL
-	      || sym_sec->output_section == NULL
-	      || (hh != NULL
-		  && hh->eh.plt.offset != (bfd_vma) -1
-		  && hh->eh.dynindx != -1
-		  && !hh->plabel
-		  && (bfd_link_pic (info)
-		      || !hh->eh.def_regular
-		      || hh->eh.root.type == bfd_link_hash_defweak))))
+      if (sym_sec == NULL
+	  || sym_sec->output_section == NULL
+	  || (hh != NULL
+	      && hh->eh.plt.offset != (bfd_vma) -1
+	      && hh->eh.dynindx != -1
+	      && !hh->plabel
+	      && (bfd_link_pic (info)
+		  || !hh->eh.def_regular
+		  || hh->eh.root.type == bfd_link_hash_defweak)))
 	{
 	  hsh = hppa_get_stub_entry (input_section, sym_sec,
 				     hh, rela, htab);


-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
index 722452b5af..5ad49abfe0 100644
--- a/bfd/elf32-hppa.c
+++ b/bfd/elf32-hppa.c
@@ -3267,18 +3267,19 @@  final_link_relocate (asection *input_section,
     case R_PARISC_PCREL22F:
       /* If this call should go via the plt, find the import stub in
 	 the stub hash.  */
-      if (sym_sec == NULL
-	  || sym_sec->output_section == NULL
-	  || (hh != NULL
-	      && hh->eh.plt.offset != (bfd_vma) -1
-	      && hh->eh.dynindx != -1
-	      && !hh->plabel
-	      && (bfd_link_pic (info)
-		  || !hh->eh.def_regular
-		  || hh->eh.root.type == bfd_link_hash_defweak)))
+      if ((input_section->flags & SEC_ALLOC) != 0
+	  && (sym_sec == NULL
+	      || sym_sec->output_section == NULL
+	      || (hh != NULL
+		  && hh->eh.plt.offset != (bfd_vma) -1
+		  && hh->eh.dynindx != -1
+		  && !hh->plabel
+		  && (bfd_link_pic (info)
+		      || !hh->eh.def_regular
+		      || hh->eh.root.type == bfd_link_hash_defweak))))
 	{
 	  hsh = hppa_get_stub_entry (input_section, sym_sec,
-					    hh, rela, htab);
+				     hh, rela, htab);
 	  if (hsh != NULL)
 	    {
 	      value = (hsh->stub_offset
@@ -3478,7 +3479,7 @@  final_link_relocate (asection *input_section,
       if (value + addend + max_branch_offset >= 2*max_branch_offset)
 	{
 	  hsh = hppa_get_stub_entry (input_section, sym_sec,
-					    hh, rela, htab);
+				     hh, rela, htab);
 	  if (hsh == NULL)
 	    return bfd_reloc_undefined;