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

[Bug target/29198] New: Incorrect reference to __thread array with -fPIC -O2 on x86


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


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