[LLVMdev] problem with __thread on linux/x86_64

Jay Foad jay.foad at gmail.com
Tue Nov 9 08:42:13 PST 2010


Hi,

On Ubuntu Linux/x86_64, I get:

$ cat t.c
#include <stdio.h>
__thread int i = 7;
int main() { printf("%d\n", i); }
$ clang -o t t.c
$ ./t
Segmentation fault

(gdb) disas
Dump of assembler code for function main:
   0x0000000000400560 <+0>:	push   %rbp
   0x0000000000400561 <+1>:	mov    %rsp,%rbp
   0x0000000000400564 <+4>:	sub    $0x10,%rsp
   0x0000000000400568 <+8>:	movl   $0x0,-0x4(%rbp)
=> 0x000000000040056f <+15>:	mov    %fs:0x402034,%esi
   0x0000000000400577 <+23>:	xor    %al,%al
   0x0000000000400579 <+25>:	mov    $0x40066c,%edi
   0x000000000040057e <+30>:	callq  0x4006e0 <printf at plt>
   0x0000000000400583 <+35>:	mov    %eax,-0x8(%rbp)
   0x0000000000400586 <+38>:	mov    -0x4(%rbp),%eax
   0x0000000000400589 <+41>:	add    $0x10,%rsp
   0x000000000040058d <+45>:	pop    %rbp
   0x000000000040058e <+46>:	retq
End of assembler dump.
(gdb) p $fs
$1 = 0
(gdb) p *(int*)0x402034
$2 = 0

I don't really understand why it's segfaulting here, but presumably
it's something to do with thread-local storage not being set up
properly?

I'm using Clang and LLVM from svn trunk, updated a few minutes ago.

Thanks,
Jay.



More information about the llvm-dev mailing list