public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/29198]  New: Incorrect reference to __thread array with -fPIC -O2 on x86
@ 2006-09-24  5:21 ian at airs dot com
  2006-09-24  5:29 ` [Bug target/29198] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: ian at airs dot com @ 2006-09-24  5:21 UTC (permalink / raw)
  To: gcc-bugs

I compiled this C code with current mainline with -fPIC -O2 on x86 GNU/Linux:

extern int f2 (int, int, int, int);
struct s { char b[4]; };
__thread struct s a[2];
void f1 (int a1, int a2)
{
  int i, j;
  for (i = 0; i < 4; i++)
    {
      int tot = 0;
      for (j = 0; j < 4; j++)
        tot += f2 (a1, a2, i, j);
      a[0].b[i] = tot;
    }
 }

The resulting assembler file had this in it:

        movl    a@GOT(%ebx), %ecx

But a is declared with __thread.  This should instead be something like:

        leal    a@TLSGD(,%ebx,1), %eax
        call    ___tls_get_addr@PLT

In the real code there are other references to a, which leads to a linker
error:

`a' accessed both as normal and thread local symbol

I believe the bug is in legitimize_address or in legitimize_pic_address in
config/i386/i386.c.  legitimize_address gets called with

(plus:SI (reg/v:SI 64 [ i ])
    (symbol_ref:SI ("a") [flags 0x8] <var_decl 0xb7c630b0 a>))

When it sees a symbol as the right-hand operand of a PLUS, it calls
legitimize_pic_address.  That returns an UNSPEC_GOT.  Somewhere along the way,
it needs to call legitimize_tls_address.


-- 
           Summary: Incorrect reference to __thread array with -fPIC -O2 on
                    x86
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian at airs dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29198


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

end of thread, other threads:[~2007-02-03 20:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-24  5:21 [Bug target/29198] New: Incorrect reference to __thread array with -fPIC -O2 on x86 ian at airs dot com
2006-09-24  5:29 ` [Bug target/29198] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
2006-09-24  5:31 ` pinskia at gcc dot gnu dot org
2006-09-24  5:34 ` pinskia at gcc dot gnu dot org
2006-09-29 11:30 ` jakub at gcc dot gnu dot org
2006-10-01 22:59 ` mmitchel at gcc dot gnu dot org
2006-10-06  7:25 ` jakub at gcc dot gnu dot org
2006-10-06  7:36 ` jakub at gcc dot gnu dot org
2006-10-06  7:41 ` [Bug target/29198] [4.0 " jakub at gcc dot gnu dot org
2007-02-03 20:22 ` gdr at gcc dot gnu dot org

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).