Bug 17788 – MSCOFF: TLS broken when linking with linker from VS2017 15.3.1
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2017-08-27T15:20:16Z
Last change time
2017-10-01T15:41:39Z
Assigned to
No Owner
Creator
Rainer Schuetze
Comments
Comment #0 by r.sagitario — 2017-08-27T15:20:16Z
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.
Comment #1 by github-bugzilla — 2017-09-05T10:52:47Z