L4Re: Thread local storage

Taru Karttunen taruti at taruti.net
Tue Dec 21 20:03:39 CET 2010


The following program crashes:

#include <stdio.h>
#include <pthread.h>

__thread int i;

int main(void)
  puts("Hello World!");
  printf("address of i=%p\n", &i);
  printf("i=%d\n", i);
  return 0;

MOE: loading 'rom/hello2'
Hello World!
address of i=0xb30001fc
L4Re: unhandled exception: pc=0x100013c

How should TLS initialization be done? This is with

Dump of assembler code for function main:
   0x01000100 <+0>:	push   %ebp
   0x01000101 <+1>:	mov    %esp,%ebp
   0x01000103 <+3>:	and    $0xfffffff0,%esp
   0x01000106 <+6>:	sub    $0x10,%esp
   0x01000109 <+9>:	movl   $0x1017b20,(%esp)
   0x01000110 <+16>:	call   0x100dab0 <puts>
   0x01000115 <+21>:	movl   $0x1,(%esp)
   0x0100011c <+28>:	call   0x100f9a0 <sleep>
   0x01000121 <+33>:	mov    %gs:0x0,%eax
   0x01000127 <+39>:	movl   $0x1017b2d,(%esp)
   0x0100012e <+46>:	add    $0xfffffffc,%eax
   0x01000133 <+51>:	mov    %eax,0x4(%esp)
   0x01000137 <+55>:	call   0x100da80 <printf>
   0x0100013c <+60>:	mov    %gs:0xfffffffc,%eax
   0x01000142 <+66>:	movl   $0x1017b3e,(%esp)
   0x01000149 <+73>:	mov    %eax,0x4(%esp)
   0x0100014d <+77>:	call   0x100da80 <printf>
   0x01000152 <+82>:	xor    %eax,%eax
   0x01000154 <+84>:	leave  
   0x01000155 <+85>:	ret    

So how to get this working?

ps. I have a rudimentary port of gccgo on L4Re working, 
and am polishing it over the holidays.

- Taru Karttunen

More information about the l4-hackers mailing list