[Issue 17788] New: MSCOFF: TLS broken when linking with linker from VS2017 15.3.1
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Sun Aug 27 08:20:16 PDT 2017
    
    
  
https://issues.dlang.org/show_bug.cgi?id=17788
          Issue ID: 17788
           Summary: MSCOFF: TLS broken when linking with linker from
                    VS2017 15.3.1
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: r.sagitario at gmx.de
When linking with the recent update 15.3.1 of VS2017, TLS ranges are broken:
/////////////////////////////
module tls;
import core.stdc.stdio;
int x = 7;
extern(C) extern
{
    int _tls_start;
    int _tls_end;
}
void[] initTLSRanges() nothrow @nogc
{
    auto pbeg = cast(void*)&_tls_start;
    auto pend = cast(void*)&_tls_end;
    return pbeg[0 .. pend - pbeg];
}
void main()
{
    printf("%p: %d\n", &x, x);
    auto r = initTLSRanges();
    printf("%p: %d\n", r.ptr, r.length);
    assert(r.ptr <= &x && &x < r.ptr + r.length);
}
/////////////////
compile with "dmd -m64 tls.d" or "dmd -m32mscoff tls.d" to produce an
executable that triggers the assert.
This works with older VS linker versions (up to update 2 of VS2017). 
This seems caused by the linker treating _tls_start and _tls_end no longer as
thread local (or rather the segments they are in). TLS segments are no longer a
separate section in the final image, but just part of the DATA section.
--
    
    
More information about the Digitalmars-d-bugs
mailing list