From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16689 invoked by alias); 24 Sep 2006 05:21:56 -0000 Received: (qmail 16672 invoked by uid 48); 24 Sep 2006 05:21:48 -0000 Date: Sun, 24 Sep 2006 05:21:00 -0000 Subject: [Bug target/29198] New: Incorrect reference to __thread array with -fPIC -O2 on x86 X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "ian at airs dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-09/txt/msg02275.txt.bz2 List-Id: 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] )) 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