[Bug target/58066] GCC mis-compiles access to TLS variable with -fPIC on x86_64

2014-12-18 Thread dvyukov at google dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066

--- Comment #8 from Dmitry Vyukov  ---
Is there any progress on this? Is it fixed?

I've hit this issue in ThreadSanitizer. It intercepts __tls_get_addr and then
code that uses MOVDQA [rbp] crashes. I remember that I hit it previously in
some other context as well.


[Bug target/58066] GCC mis-compiles access to TLS variable with -fPIC on x86_64

2014-05-18 Thread wmi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066

--- Comment #7 from wmi at gcc dot gnu.org ---
Author: wmi
Date: Mon May 19 05:25:45 2014
New Revision: 210601

URL: http://gcc.gnu.org/viewcvs?rev=210601&root=gcc&view=rev
Log:
2014-05-18  Wei Mi  

PR target/58066
* gcc.target/i386/pr58066.c: Replace pattern matching of .cfi
directive with rtl insns. Add effective-target of fpic and
tls_native.

Modified:
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.target/i386/pr58066.c


[Bug target/58066] GCC mis-compiles access to TLS variable with -fPIC on x86_64

2014-05-08 Thread wmi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066

--- Comment #6 from wmi at gcc dot gnu.org ---
Author: wmi
Date: Thu May  8 16:44:52 2014
New Revision: 210222

URL: http://gcc.gnu.org/viewcvs?rev=210222&root=gcc&view=rev
Log:
gcc/
2014-05-08  Wei Mi  

PR target/58066
* config/i386/i386.c (ix86_compute_frame_layout):
Update preferred_stack_boundary for call, expanded from
tls descriptor.
* config/i386/i386.md:
(*tls_global_dynamic_32_gnu): Update RTX to depend on
SP register.
(*tls_local_dynamic_base_32_gnu): Ditto.
(*tls_local_dynamic_32_once): Ditto.
(tls_global_dynamic_64_): Set
ix86_tls_descriptor_calls_expanded_in_cfun.
(tls_local_dynamic_base_64_): Ditto.
(tls_global_dynamic_32): Set
ix86_tls_descriptor_calls_expanded_in_cfun. Update RTX
to depend on SP register.
(tls_local_dynamic_base_32): Ditto.

gcc/testsuite/
2014-05-08  Wei Mi  

PR target/58066
* gcc.target/i386/pr58066.c: New test.


Added:
trunk/gcc/testsuite/gcc.target/i386/pr58066.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/config/i386/i386.c
trunk/gcc/config/i386/i386.md
trunk/gcc/testsuite/ChangeLog


[Bug target/58066] GCC mis-compiles access to TLS variable with -fPIC on x86_64

2014-03-12 Thread hjl.tools at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066

--- Comment #5 from H.J. Lu  ---
Another problem:

[hjl@gnu-6 gcc]$ cat /tmp/c.i 
static __thread char ccc;

void* __cxa_get_globals()
{
 return &ccc;
}
[hjl@gnu-6 gcc]$ ./xgcc -B./ -S -O2 -fPIC /tmp/c.i 
[hjl@gnu-6 gcc]$ cat /tmp/c.i 
static __thread char ccc;

void* __cxa_get_globals()
{
 return &ccc;
}
[hjl@gnu-6 gcc]$ ./xgcc -B./ -S -O2 -fPIC /tmp/c.i  -m32
[hjl@gnu-6 gcc]$ cat c.s
.file"c.i"
.section.text.unlikely,"ax",@progbits
.LCOLDB0:
.text
.LHOTB0:
.p2align 4,,15
.globl__cxa_get_globals
.type__cxa_get_globals, @function
__cxa_get_globals:
.LFB0:
.cfi_startproc
pushl%ebx
.cfi_def_cfa_offset 8
.cfi_offset 3, -8
call__x86.get_pc_thunk.bx
addl$_GLOBAL_OFFSET_TABLE_, %ebx
subl$8, %esp
.cfi_def_cfa_offset 16
addl$8, %esp
.cfi_def_cfa_offset 8
lealccc@tlsgd(,%ebx,1), %eax
call___tls_get_addr@PLT
popl%ebx
.cfi_restore 3
.cfi_def_cfa_offset 4
ret
.cfi_endproc
.LFE0:
.size__cxa_get_globals, .-__cxa_get_globals

sched2 doesn't know

(insn:TI 15 25 13 2 (parallel [
(set (reg:SI 0 ax [86])
(unspec:SI [
(reg:SI 3 bx)
(symbol_ref:SI ("ccc") [flags 0x1a]  )
(symbol_ref:SI ("___tls_get_addr"))
] UNSPEC_TLS_GD))
(clobber (reg:SI 1 dx [88]))
(clobber (reg:SI 2 cx [89]))
(clobber (reg:CC 17 flags))
]) /tmp/c.i:5 772 {*tls_global_dynamic_32_gnu}
 (expr_list:REG_DEAD (reg:SI 3 bx)
(expr_list:REG_UNUSED (reg:CC 17 flags)
(expr_list:REG_UNUSED (reg:SI 2 cx [89])
(expr_list:REG_UNUSED (reg:SI 1 dx [88])
(expr_list:REG_EQUIV (unspec:SI [
(reg:SI 3 bx)
(symbol_ref:SI ("ccc") [flags 0x1a]  )
(symbol_ref:SI ("___tls_get_addr"))
] UNSPEC_TLS_GD)
(nil)))

is a function call and move stack adjustment cross it.


[Bug target/58066] GCC mis-compiles access to TLS variable with -fPIC on x86_64

2014-03-12 Thread hjl.tools at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066

--- Comment #4 from H.J. Lu  ---
Created attachment 32341
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32341&action=edit
A patch

This patch sets ix86_tls_descriptor_calls_expanded_in_cfun after
reload is complete and checks it for stack boundary in
ix86_frame_pointer_required.


[Bug target/58066] GCC mis-compiles access to TLS variable with -fPIC on x86_64

2013-08-06 Thread ppluzhnikov at google dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066

--- Comment #3 from Paul Pluzhnikov  ---
(In reply to Paul Pluzhnikov from comment #2)

> What is the way to turn it on?

Compiling test case with -mtls-dialect=gnu2 does appear to improve the picture:

g++ -fPIC -O2 -S t.cc -mtls-dialect=gnu2

__cxa_get_globals:
leaq_ZL3ccc@TLSDESC(%rip), %rax
call*_ZL3ccc@TLSCALL(%rax)
addq%fs:0, %rax
ret

The indirect call goes to _dl_tlsdesc_dynamic in ld-linux-x86-64.so.2 with
misaligned stack, and the latter re-aligns it.


[Bug target/58066] GCC mis-compiles access to TLS variable with -fPIC on x86_64

2013-08-02 Thread ppluzhnikov at google dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066

--- Comment #2 from Paul Pluzhnikov  ---
(In reply to Andrew Pinski from comment #1)

> Which most Linux distro default to anyways ...

Ubuntu 12.04.1 LTS doesn't.
Configuring trunk GCC on it doesn't default to GNU2 TLS either.

What is the way to turn it on?


[Bug target/58066] GCC mis-compiles access to TLS variable with -fPIC on x86_64

2013-08-02 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066

Andrew Pinski  changed:

   What|Removed |Added

  Component|c   |target

--- Comment #1 from Andrew Pinski  ---
> However, it appears to have only been fully implemented for the GNU2 TLS
>  descriptor style ...

Which most Linux distro default to anyways ...