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_25-branch] Don't segfault or assert on NULL tls_sec


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

commit 41b7d3b8459ab326fe1703ae14203c06de97205a
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Jan 29 19:38:28 2015 +1030

    Don't segfault or assert on NULL tls_sec
    
    Real code won't hit these, but it's possible to contrive a testcase..
    
    	* elf32-ppc.c (ppc_elf_relocate_section): Don't segfault on NULL
    	tls_sec.
    	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
    	* elflink.c (elf_link_output_extsym): Don't assert on NULL tls_sec.

Diff:
---
 bfd/ChangeLog   |  6 ++++++
 bfd/elf32-ppc.c | 30 ++++++++++++++++++++++--------
 bfd/elf64-ppc.c | 30 ++++++++++++++++++++++--------
 bfd/elflink.c   |  6 ------
 4 files changed, 50 insertions(+), 22 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 45f9c69..79f333a 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,6 +1,12 @@
 2015-02-11  Alan Modra  <amodra@gmail.com>
 
 	Apply from master.
+	2015-02-09  Alan Modra  <amodra@gmail.com>
+	* elf32-ppc.c (ppc_elf_relocate_section): Don't segfault on NULL
+	tls_sec.
+	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
+	* elflink.c (elf_link_output_extsym): Don't assert on NULL tls_sec.
+
 	2015-01-29  Alan Modra  <amodra@gmail.com>
 	* elf64-ppc.c (ppc64_elf_relocate_section): Correct GOT_TLSLD
 	optimization.  Tidy mask for GOT_TLSGD optimization.
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 57d6349..83f8452 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -8215,7 +8215,12 @@ ppc_elf_relocate_section (bfd *output_bfd,
 			  {
 			    outrel.r_addend += relocation;
 			    if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
-			      outrel.r_addend -= htab->elf.tls_sec->vma;
+			      {
+				if (htab->elf.tls_sec == NULL)
+				  outrel.r_addend = 0;
+				else
+				  outrel.r_addend -= htab->elf.tls_sec->vma;
+			      }
 			  }
 			loc = rsec->contents;
 			loc += (rsec->reloc_count++
@@ -8233,9 +8238,14 @@ ppc_elf_relocate_section (bfd *output_bfd,
 			  value = 1;
 			else if (tls_ty != 0)
 			  {
-			    value -= htab->elf.tls_sec->vma + DTP_OFFSET;
-			    if (tls_ty == (TLS_TLS | TLS_TPREL))
-			      value += DTP_OFFSET - TP_OFFSET;
+			    if (htab->elf.tls_sec == NULL)
+			      value = 0;
+			    else
+			      {
+				value -= htab->elf.tls_sec->vma + DTP_OFFSET;
+				if (tls_ty == (TLS_TLS | TLS_TPREL))
+				  value += DTP_OFFSET - TP_OFFSET;
+			      }
 
 			    if (tls_ty == (TLS_TLS | TLS_GD))
 			      {
@@ -8321,7 +8331,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
 	case R_PPC_DTPREL16_LO:
 	case R_PPC_DTPREL16_HI:
 	case R_PPC_DTPREL16_HA:
-	  addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
+	  if (htab->elf.tls_sec != NULL)
+	    addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
 	  break;
 
 	  /* Relocations that may need to be propagated if this is a shared
@@ -8345,18 +8356,21 @@ ppc_elf_relocate_section (bfd *output_bfd,
 		bfd_put_32 (output_bfd, insn, p);
 	      break;
 	    }
-	  addend -= htab->elf.tls_sec->vma + TP_OFFSET;
+	  if (htab->elf.tls_sec != NULL)
+	    addend -= htab->elf.tls_sec->vma + TP_OFFSET;
 	  /* The TPREL16 relocs shouldn't really be used in shared
 	     libs as they will result in DT_TEXTREL being set, but
 	     support them anyway.  */
 	  goto dodyn;
 
 	case R_PPC_TPREL32:
-	  addend -= htab->elf.tls_sec->vma + TP_OFFSET;
+	  if (htab->elf.tls_sec != NULL)
+	    addend -= htab->elf.tls_sec->vma + TP_OFFSET;
 	  goto dodyn;
 
 	case R_PPC_DTPREL32:
-	  addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
+	  if (htab->elf.tls_sec != NULL)
+	    addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
 	  goto dodyn;
 
 	case R_PPC_DTPMOD32:
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index 2cff63e..3b64f9a 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -14110,7 +14110,12 @@ ppc64_elf_relocate_section (bfd *output_bfd,
 		      {
 			outrel.r_addend += relocation;
 			if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL))
-			  outrel.r_addend -= htab->elf.tls_sec->vma;
+			  {
+			    if (htab->elf.tls_sec == NULL)
+			      outrel.r_addend = 0;
+			    else
+			      outrel.r_addend -= htab->elf.tls_sec->vma;
+			  }
 		      }
 		    loc = relgot->contents;
 		    loc += (relgot->reloc_count++
@@ -14127,9 +14132,14 @@ ppc64_elf_relocate_section (bfd *output_bfd,
 		      relocation = 1;
 		    else if (tls_type != 0)
 		      {
-			relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
-			if (tls_type == (TLS_TLS | TLS_TPREL))
-			  relocation += DTP_OFFSET - TP_OFFSET;
+			if (htab->elf.tls_sec == NULL)
+			  relocation = 0;
+			else
+			  {
+			    relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
+			    if (tls_type == (TLS_TLS | TLS_TPREL))
+			      relocation += DTP_OFFSET - TP_OFFSET;
+			  }
 
 			if (tls_type == (TLS_TLS | TLS_GD))
 			  {
@@ -14262,7 +14272,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
 		bfd_put_32 (output_bfd, insn, p);
 	      break;
 	    }
-	  addend -= htab->elf.tls_sec->vma + TP_OFFSET;
+	  if (htab->elf.tls_sec != NULL)
+	    addend -= htab->elf.tls_sec->vma + TP_OFFSET;
 	  if (info->shared)
 	    /* The TPREL16 relocs shouldn't really be used in shared
 	       libs as they will result in DT_TEXTREL being set, but
@@ -14282,7 +14293,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
 	case R_PPC64_DTPREL16_HIGHERA:
 	case R_PPC64_DTPREL16_HIGHEST:
 	case R_PPC64_DTPREL16_HIGHESTA:
-	  addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
+	  if (htab->elf.tls_sec != NULL)
+	    addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
 	  break;
 
 	case R_PPC64_ADDR64_LOCAL:
@@ -14297,11 +14309,13 @@ ppc64_elf_relocate_section (bfd *output_bfd,
 	  goto dodyn;
 
 	case R_PPC64_TPREL64:
-	  addend -= htab->elf.tls_sec->vma + TP_OFFSET;
+	  if (htab->elf.tls_sec != NULL)
+	    addend -= htab->elf.tls_sec->vma + TP_OFFSET;
 	  goto dodyn;
 
 	case R_PPC64_DTPREL64:
-	  addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
+	  if (htab->elf.tls_sec != NULL)
+	    addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
 	  /* Fall thru */
 
 	  /* Relocations that may need to be propagated if this is a
diff --git a/bfd/elflink.c b/bfd/elflink.c
index d1d36db..9f4ee0e 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -9042,12 +9042,6 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
 		    asection *tls_sec = elf_hash_table (flinfo->info)->tls_sec;
 		    if (tls_sec != NULL)
 		      sym.st_value -= tls_sec->vma;
-		    else
-		      {
-			/* The TLS section may have been garbage collected.  */
-			BFD_ASSERT (flinfo->info->gc_sections
-				    && !input_sec->gc_mark);
-		      }
 		  }
 	      }
 	  }


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