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

Re: fix ppc32 -msecure-plt TLS relaxation GD->LE


On Mar 14, 2006, Alan Modra <amodra@bigpond.net.au> wrote:

> On Fri, Mar 10, 2006 at 12:09:50AM -0300, Alexandre Oliva wrote:
>> Code compiled with -msecure-plt generates calls to __tls_get_addr with
>> a nonzero addend, that ends up making to the lower part of the TP
>> offset computed for the TL variable when Global Dynamic is relaxed to
>> Local Exec.  This patch fixes it, by arranging for us to refer to the
>> same location in both relocations.  We already did that for LD->LE,
>> but not GD->LE.  [LG[D->IE cancels out the second relocation, so its
>> addend doesn't matter, so I left it along even though it's still
>> conceptually wrong.
>> 
>> Tested on amd64-linux-gnu-x-ppc64-linux-gnu.  Ok to install?

> OK, thanks!  As you say, the GD->IE R_PPC_NONE addend doesn't matter,
> but I think it would be nicer to zero the addend.  Please make that
> change too.

Done, here's what I'm checking in.

for binutils/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* elf32-ppc.c (ppc_elf_relocate_section): Copy addend from
	first relocation to the second when relaxing TLS GD to LE;
	zero it out when relaxing to IE.

for ld/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* ld-powerpc/tls32.s: Verify that +32768 @plt addend is
	discarded.

Index: bfd/elf32-ppc.c
===================================================================
--- bfd/elf32-ppc.c.orig	2006-03-17 03:32:48.000000000 -0300
+++ bfd/elf32-ppc.c	2006-03-17 03:36:48.000000000 -0300
@@ -5768,6 +5768,7 @@ ppc_elf_relocate_section (bfd *output_bf
 		      insn1 |= 32 << 26;	/* lwz */
 		      insn2 = 0x7c631214;	/* add 3,3,2 */
 		      rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE);
+		      rel[1].r_addend = 0;
 		      r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
 				+ R_PPC_GOT_TPREL16);
 		      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
@@ -5782,13 +5783,13 @@ ppc_elf_relocate_section (bfd *output_bf
 			  /* Was an LD reloc.  */
 			  r_symndx = 0;
 			  rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
-			  rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
 			}
 		      r_type = R_PPC_TPREL16_HA;
 		      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
 		      rel[1].r_info = ELF32_R_INFO (r_symndx,
 						    R_PPC_TPREL16_LO);
 		      rel[1].r_offset += 2;
+		      rel[1].r_addend = rel->r_addend;
 		    }
 		  bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2);
 		  bfd_put_32 (output_bfd, insn2, contents + offset);
Index: ld/testsuite/ld-powerpc/tls32.s
===================================================================
--- ld/testsuite/ld-powerpc/tls32.s.orig	2004-11-23 17:10:08.000000000 -0200
+++ ld/testsuite/ld-powerpc/tls32.s	2006-03-17 03:34:38.000000000 -0300
@@ -33,11 +33,11 @@ _start:
 #global syms
 #GD
  addi 3,31,gd0@got@tlsgd	#R_PPC_GOT_TLSGD16	gd0
- bl __tls_get_addr@plt		#R_PPC_PLTREL24		__tls_get_addr
+ bl __tls_get_addr+0x8000@plt	#R_PPC_PLTREL24		__tls_get_addr
 
 #LD
  addi 3,31,ld0@got@tlsld	#R_PPC_GOT_TLSLD16	ld0
- bl __tls_get_addr@plt		#R_PPC_PLTREL24		__tls_get_addr
+ bl __tls_get_addr+0x8000@plt	#R_PPC_PLTREL24		__tls_get_addr
 
  addi 9,3,ld0@dtprel		#R_PPC_DTPREL16		ld0
 
-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
Secretary for FSF Latin America        http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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