public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* fix ppc32 -msecure-plt TLS relaxation GD->LE
@ 2006-03-10  3:10 Alexandre Oliva
  2006-03-15  2:32 ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Oliva @ 2006-03-10  3:10 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 562 bytes --]

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?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: binutils-ppc-TLS-relax-GD-LE.patch --]
[-- Type: text/x-patch, Size: 1850 bytes --]

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.

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-09 23:23:41.000000000 -0300
+++ bfd/elf32-ppc.c	2006-03-09 23:25:57.000000000 -0300
@@ -5799,13 +5799,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	2006-03-09 23:31:33.000000000 -0300
+++ ld/testsuite/ld-powerpc/tls32.s	2006-03-09 23:31:52.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
 

[-- Attachment #3: Type: text/plain, Size: 249 bytes --]


-- 
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}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: fix ppc32 -msecure-plt TLS relaxation GD->LE
  2006-03-10  3:10 fix ppc32 -msecure-plt TLS relaxation GD->LE Alexandre Oliva
@ 2006-03-15  2:32 ` Alan Modra
  2006-03-17  7:56   ` Alexandre Oliva
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2006-03-15  2:32 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: binutils

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.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: fix ppc32 -msecure-plt TLS relaxation GD->LE
  2006-03-15  2:32 ` Alan Modra
@ 2006-03-17  7:56   ` Alexandre Oliva
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2006-03-17  7:56 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 912 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: binutils-ppc-TLS-relax-GD-LE.patch --]
[-- Type: text/x-patch, Size: 2266 bytes --]

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
 

[-- Attachment #3: Type: text/plain, Size: 249 bytes --]


-- 
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}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-03-17  6:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-10  3:10 fix ppc32 -msecure-plt TLS relaxation GD->LE Alexandre Oliva
2006-03-15  2:32 ` Alan Modra
2006-03-17  7:56   ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).