24465 – [4.1 Regression] -mminimal-toc miscompilation of __thread vars (original) (raw)
Description Alan Modra 2005-10-21 03:40:46 UTC
RS6000_PIC_OFFSET_TABLE_REGNUM isn't being set up for functions that don't need a constant pool but access __thread vars using __tls_get_addr.
/* Fails with -m64 -mminimal-toc -fPIC */ static __thread int x; int foo (void) { return x; }
This is the reason why powerpc64 has been getting lots of libjava failures since this libjava change: 2005-09-27 Tom Tromey <tromey@redhat.com>
Comment 1 Drea Pinski 2005-10-21 03:47:35 UTC
Confirmed, This is a latent bug but shows up as testsuite regressions which is why I am marking it as a regression.
Comment 2 Alan Modra 2005-10-21 05:05:51 UTC
Actually, it's not that RS6000_PIC_OFFSET_TABLE_REGNUM isn't being set up, it's that RS6000_PIC_OFFSET_TABLE_REGNUM is wrongly being using for tls accesses. As currently implemented by gcc, powerpc tls uses x@got@tlsgd and similar. ie. we are expecting the linker to manage allocation of tls entries in the got rather than having gcc allocate them itself in toc sections. This means that powerpc64 should use r2 for tls always, even when -mminimal-toc.
Testing the following fix.
Index: gcc/config/rs6000/rs6000.c
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v retrieving revision 1.872 diff -u -p -r1.872 rs6000.c --- gcc/config/rs6000/rs6000.c 6 Oct 2005 22:58:59 -0000 1.872 +++ gcc/config/rs6000/rs6000.c 21 Oct 2005 05:02:57 -0000 @@ -2979,7 +2979,7 @@ rs6000_legitimize_tls_address (rtx addr, rtx r3, got, tga, tmp1, tmp2, eqv;
if (TARGET_64BIT)- got = gen_rtx_REG (Pmode, TOC_REGISTER);
- got = gen_rtx_REG (Pmode, 2); else { if (flag_pic == 1)
Comment 6 Alan Modra 2005-10-21 07:49:20 UTC
Fixed on all active branches