This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

PPC32 TLS GD and LD force old GOT/PLT layout


When compiling code that accesses thread-local variables with -fPIC on
PPC, the code used to compute the address of _GLOBAL_OFFSET_TABLE_ is
not compatible with -msecure-plt.

It's not that it fails at run time, it's just that it causes the
linker to decide that the dynamic libraries need the old GOT and PLT
layouts, that require executable code in .got and .plt in the data
segment, rendering the entire data segment executable.  This defeats
the whole point of -msecure-plt.

After struggling for a while trying to find out a reasonable way to
compute the address of _GLOBAL_OFFSET_TABLE_ (not of the local TOC),
RTH and I ended up settling for this.  It looks simpler than it
actually is, since for PIC we'll actually use a TOC entry to hold the
address of _GLOBAL_OFFSET_TABLE_.  It requires a relative dynamic
relocation, but the alternatives either triggered the old layout in
the linker (.word _GLOBAL_OFFSET_TABLE_ - $ does, that's exactly what
the old current code does) or required a lot of code very similar to
what the prologue normally emits to compute the TOC address.

Are we both missing something obvious, or is this really the best
approach?  In the latter case, is this ok for mainline and then 4.1
branch?  It's bootstrapped successfully on ppc64-linux-gnu and
ppc-linux-gnu, and test results look great so far (all of GCC and most
libraries).

for gcc/ChangeLog
from  Richard Henderson  <rth@redhat.com>, Alexandre Oliva  <aoliva@redhat.com>

	* config/rs6000/rs6000.c (rs6000_legitimize_tls_address): Use
	secure-plt-compatible load sequence to compute the GOT address
	for -fPIC -msecure-plt.

Index: gcc/config/rs6000/rs6000.c
===================================================================
--- gcc/config/rs6000/rs6000.c.orig	2006-02-25 02:06:30.000000000 -0300
+++ gcc/config/rs6000/rs6000.c	2006-03-10 00:20:51.000000000 -0300
@@ -3113,7 +3113,7 @@ rs6000_legitimize_tls_address (rtx addr,
 	    {
 	      rtx gsym = rs6000_got_sym ();
 	      got = gen_reg_rtx (Pmode);
-	      if (flag_pic == 0)
+	      if (flag_pic == 0 || TARGET_SECURE_PLT)
 		rs6000_emit_move (got, gsym, Pmode);
 	      else
 		{
-- 
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]