Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0000041 [libFirm] backend minor always 2009-03-03 01:34 2017-05-08 16:14
Reporter moritz View Status public  
Assigned To
Priority normal Resolution open Platform
Status confirmed   OS
Projection none   OS Version
ETA none Fixed in Version Product Version 1.16.0
  Product Build
Summary 0000041: TLS does not work on Cygwin
Description In MinGW mode, libFirm generates invalid assembler code for testcase firm_testsuite/opt/thread.c which uses "__thread" modifiers (invalid section declaration: '.section .tbss,"awT",@nobits').
Steps To Reproduce
Additional Information Just removing ",@nobits" results in the GAS warning "unknown section attribute 'T'".
The generated code tries to get a TLS pointer from gs:[0] which is simply not valid on Windows.

Trying to build this testcase with gcc 3.4.4 on Cygwin results in this error messages:
opt/thread.c:5: error: thread-local storage not supported for this target
opt/thread.c:6: error: thread-local storage not supported for this target
Tags No tags attached.
Attached Files

- Relationships

-  Notes
Matze (administrator)
2009-03-03 21:16

so what's the correct solution, disallowing thread local storage on mingw target?
moritz (manager)
2009-03-04 12:26

Looking at how Visual C compiles thread.c it uses a special .tls PE section:

PUBLIC _tls_i
PUBLIC _tls_j
_tls_i DD 0aH DUP (?)
_tls_j DD 05H
PUBLIC _test
EXTRN __tls_array:DWORD
EXTRN __tls_index:DWORD


; 9 : tls_j = i;

    mov eax, DWORD PTR __tls_index
    mov ecx, DWORD PTR fs:__tls_array
    mov edx, DWORD PTR [ecx+eax*4]
    mov eax, DWORD PTR _i$[ebp]
    mov DWORD PTR _tls_j[edx], eax

More info on this can be found at: [^]

According to [^] and [^] binutils already have some support for the .tls table ("Fortunately, the linker already supports setting the TLS directory entry in the PE header if a symbol named "__tls_used" exists.").
Sadly I didn't find a proper example on how an according .s file should look like. Trying

    .section .tls
.globl __tls_used
    .long 2
.globl _tls_i
    .p2align 2
    .space 40
.globl _tls_j
    .p2align 2
    .long 0x00000005

causes an segmentation fault in ld...
moritz (manager)
2009-03-04 17:11

The definition of __tls_used was missing. I fixed the bug in ld nonetheless ( [^]
Now __tls_used must only be filled with some sensible data (IMAGE_TLS_DIRECTORY). A C example can be found here: [^]
travm1 (reporter)
2017-04-07 05:49

The wiki page for Cygwin has some interesting points: [^]
waldgrasgeniesser (reporter)
2017-05-08 16:14

I don't care that you broke your elbow.

- Issue History
Date Modified Username Field Change
2009-03-03 01:34 moritz New Issue
2009-03-03 21:16 Matze Note Added: 0000061
2009-03-03 21:16 Matze Status new => confirmed
2009-03-03 21:20 Matze version => 1.16.0
2009-03-04 12:26 moritz Note Added: 0000066
2009-03-04 17:11 moritz Note Added: 0000067
2017-04-07 05:49 travm1 Note Added: 0000288
2017-05-08 16:14 waldgrasgeniesser Note Added: 0000293

Mantis 1.1.5[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker