This is the mail archive of the binutils@sources.redhat.com 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]

zero sym index tls relocs


Ehhm, it appears ld.so wants to resolve a zero symbol index on a dynamic
TLS reloc to a zero value relative to the tls segment, not a zero
relative to the base of the object.  I suppose that makes sense, but
really needs a mention in the ELF spec, or at least Ulrich's TLS
supplement.

bfd/ChangeLog
	* elf32-ppc.c (ppc_elf_relocate_section): Subtract tls seg vma from
	zero index dynamic tls relocs generated for the GOT.  Tidy code.
	Set "relocation" to 1 on DTPMOD32 relocs.  Optimize HA adjustment.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.

ld/testsuite/ChangeLog
	* ld-powerpc/tlsso.r: Adjust for corrected zero symbol index relocs.
	* ld-powerpc/tlsso32.r: Likewise.

Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.71
diff -u -p -r1.71 elf32-ppc.c
--- bfd/elf32-ppc.c	7 Mar 2003 01:09:01 -0000	1.71
+++ bfd/elf32-ppc.c	10 Mar 2003 22:10:44 -0000
@@ -4779,10 +4779,10 @@ ppc_elf_relocate_section (output_bfd, in
 			outrel.r_offset = (htab->got->output_section->vma
 					   + htab->got->output_offset
 					   + off);
+			outrel.r_addend = 0;
 			if (tls_ty & (TLS_LD | TLS_GD))
 			  {
 			    outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
-			    outrel.r_addend = 0;
 			    if (tls_ty == (TLS_TLS | TLS_GD))
 			      {
 				loc = htab->relgot->contents;
@@ -4790,9 +4790,9 @@ ppc_elf_relocate_section (output_bfd, in
 					* sizeof (Elf32_External_Rela));
 				bfd_elf32_swap_reloca_out (output_bfd,
 							   &outrel, loc);
+				outrel.r_offset += 4;
 				outrel.r_info
 				  = ELF32_R_INFO (indx, R_PPC_DTPREL32);
-				outrel.r_offset += 4;
 			      }
 			  }
 			else if (tls_ty == (TLS_TLS | TLS_DTPREL))
@@ -4803,9 +4803,12 @@ ppc_elf_relocate_section (output_bfd, in
 			  outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE);
 			else
 			  outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
-			outrel.r_addend = 0;
 			if (indx == 0)
-			  outrel.r_addend += relocation;
+			  {
+			    outrel.r_addend += relocation;
+			    if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
+			      outrel.r_addend -= htab->tls_sec->vma;
+			  }
 			loc = htab->relgot->contents;
 			loc += (htab->relgot->reloc_count++
 				* sizeof (Elf32_External_Rela));
@@ -4933,6 +4936,11 @@ ppc_elf_relocate_section (output_bfd, in
 	  addend -= htab->tls_sec->vma + DTP_OFFSET;
 	  goto dodyn;
 
+	case R_PPC_DTPMOD32:
+	  relocation = 1;
+	  addend = 0;
+	  goto dodyn;
+
 	case R_PPC_REL24:
 	case R_PPC_REL32:
 	case R_PPC_REL14:
@@ -4959,7 +4967,6 @@ ppc_elf_relocate_section (output_bfd, in
 	case R_PPC_ADDR14_BRNTAKEN:
 	case R_PPC_UADDR32:
 	case R_PPC_UADDR16:
-	case R_PPC_DTPMOD32:
 	  /* r_symndx will be zero only for relocs against symbols
 	     from removed linkonce sections, or sections discarded by
 	     a linker script.  */
@@ -5332,8 +5339,9 @@ ppc_elf_relocate_section (output_bfd, in
 	     'sec' would be NULL, and we should leave the symbol
 	     alone (it will be set to zero elsewhere in the link).  */
 	  if (sec != NULL)
-	    /* Add 0x10000 if sign bit in 0:15 is set.  */
-	    addend += ((relocation + addend) & 0x8000) << 1;
+	    /* Add 0x10000 if sign bit in 0:15 is set.
+	       Bits 0:15 are not used.  */
+	    addend += 0x8000;
 	  break;
 	}
 
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.91
diff -u -p -r1.91 elf64-ppc.c
--- bfd/elf64-ppc.c	6 Mar 2003 23:26:20 -0000	1.91
+++ bfd/elf64-ppc.c	10 Mar 2003 22:10:53 -0000
@@ -7638,8 +7638,8 @@ ppc64_elf_relocate_section (output_bfd, 
 				       + off);
 		    if (tls_type & (TLS_LD | TLS_GD))
 		      {
-			outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64);
 			outrel.r_addend = 0;
+			outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64);
 			if (tls_type == (TLS_TLS | TLS_GD))
 			  {
 			    loc = htab->srelgot->contents;
@@ -7647,9 +7647,9 @@ ppc64_elf_relocate_section (output_bfd, 
 				    * sizeof (Elf64_External_Rela));
 			    bfd_elf64_swap_reloca_out (output_bfd,
 						       &outrel, loc);
+			    outrel.r_offset += 8;
 			    outrel.r_info
 			      = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
-			    outrel.r_offset += 8;
 			  }
 		      }
 		    else if (tls_type == (TLS_TLS | TLS_DTPREL))
@@ -7662,7 +7662,11 @@ ppc64_elf_relocate_section (output_bfd, 
 		      outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT);
 		    outrel.r_addend = rel->r_addend;
 		    if (indx == 0)
-		      outrel.r_addend += relocation;
+		      {
+			outrel.r_addend += relocation;
+			if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL))
+			  outrel.r_addend -= htab->tls_sec->vma;
+		      }
 		    loc = htab->srelgot->contents;
 		    loc += (htab->srelgot->reloc_count++
 			    * sizeof (Elf64_External_Rela));
@@ -7798,6 +7802,11 @@ ppc64_elf_relocate_section (output_bfd, 
 	  addend -= htab->tls_sec->vma + DTP_OFFSET;
 	  break;
 
+	case R_PPC64_DTPMOD64:
+	  relocation = 1;
+	  addend = 0;
+	  goto dodyn;
+
 	case R_PPC64_TPREL64:
 	  addend -= htab->tls_sec->vma + TP_OFFSET;
 	  goto dodyn;
@@ -7808,7 +7817,6 @@ ppc64_elf_relocate_section (output_bfd, 
 
 	  /* Relocations that may need to be propagated if this is a
 	     dynamic object.  */
-	case R_PPC64_DTPMOD64:
 	case R_PPC64_REL30:
 	case R_PPC64_REL32:
 	case R_PPC64_REL64:
@@ -8028,8 +8036,9 @@ ppc64_elf_relocate_section (output_bfd, 
 	     'sec' would be NULL, and we should leave the symbol
 	     alone (it will be set to zero elsewhere in the link).  */
 	  if (sec != NULL)
-	    /* Add 0x10000 if sign bit in 0:15 is set.  */
-	    addend += ((relocation + addend) & 0x8000) << 1;
+	    /* Add 0x10000 if sign bit in 0:15 is set.
+	       Bits 0:15 are not used.  */
+	    addend += 0x8000;
 	  break;
 
 	case R_PPC64_ADDR16_DS:
Index: ld/testsuite/ld-powerpc/tlsso.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsso.r,v
retrieving revision 1.1
diff -u -p -r1.1 tlsso.r
--- ld/testsuite/ld-powerpc/tlsso.r	4 Feb 2003 14:52:11 -0000	1.1
+++ ld/testsuite/ld-powerpc/tlsso.r	10 Mar 2003 22:10:53 -0000
@@ -59,8 +59,8 @@ Relocation section '\.rela\.dyn' at offs
 0+7ca +0+900000046 R_PPC64_TPREL16_LO +0+107f8 \.tdata \+ 30
 0+10988 +0+44 R_PPC64_DTPMOD64 +0+
 0+10998 +0+44 R_PPC64_DTPMOD64 +0+
-0+109a0 +0+4e R_PPC64_DTPREL64 +0+107f8
-0+109a8 +0+4e R_PPC64_DTPREL64 +0+10810
+0+109a0 +0+4e R_PPC64_DTPREL64 +0+
+0+109a8 +0+4e R_PPC64_DTPREL64 +0+18
 0+109b0 +0+1300000044 R_PPC64_DTPMOD64 +0+ gd \+ 0
 0+109b8 +0+130000004e R_PPC64_DTPREL64 +0+ gd \+ 0
 0+109c0 +0+1b0000004e R_PPC64_DTPREL64 +0+50 ld2 \+ 0
Index: ld/testsuite/ld-powerpc/tlsso32.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsso32.r,v
retrieving revision 1.1
diff -u -p -r1.1 tlsso32.r
--- ld/testsuite/ld-powerpc/tlsso32.r	18 Feb 2003 06:11:32 -0000	1.1
+++ ld/testsuite/ld-powerpc/tlsso32.r	10 Mar 2003 22:10:53 -0000
@@ -62,7 +62,7 @@ Relocation section '\.rela\.dyn' at offs
 0+5a6 +0+846 R_PPC_TPREL16_LO +0+105a8 +\.tdata \+ 105c0
 0+10674 +0+44 R_PPC_DTPMOD32 +0+
 0+1067c +0+44 R_PPC_DTPMOD32 +0+
-0+10680 +0+4e R_PPC_DTPREL32 +0+105a8
+0+10680 +0+4e R_PPC_DTPREL32 +0+
 0+10684 +0+1244 R_PPC_DTPMOD32 +0+ +gd \+ 0
 0+10688 +0+124e R_PPC_DTPREL32 +0+ +gd \+ 0
 0+1068c +0+2144 R_PPC_DTPMOD32 +0+1c +gd0 \+ 0

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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