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
Commits pushed to stable at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/07a25c9ec1deb7bcdf45d37d51a5b18d91fd1083 fix issue 17788: MSCOFF: with VS2017 15.3.1 segment .tls is no longer written to a separate image section, so _tls_start and _tls_end no longer happen to work as both __gshared and TLS section offsets. https://github.com/dlang/druntime/commit/e07fa031919579bd2b48f1f7ebb634061bd3daca Merge pull request #1910 from rainers/issue17788 fix issue 17788: MSCOFF: TLS broken with VS2017 15.3.1
Comment #2 by github-bugzilla — 2017-10-01T15:41:39Z
Commits pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/07a25c9ec1deb7bcdf45d37d51a5b18d91fd1083 fix issue 17788: MSCOFF: with VS2017 15.3.1 segment .tls is no longer written to a separate image section, so _tls_start and _tls_end no longer happen to work as both __gshared and TLS section offsets. https://github.com/dlang/druntime/commit/e07fa031919579bd2b48f1f7ebb634061bd3daca Merge pull request #1910 from rainers/issue17788