Bug 21186 – Inline Assembler: static (thread-local) variables cannot be used

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-22T00:16:00Z
Last change time
2020-08-22T08:19:39Z
Keywords
accepts-invalid, iasm, wrong-code
Assigned to
No Owner
Creator
Walter Bright
See also
https://issues.dlang.org/show_bug.cgi?id=5922

Comments

Comment #0 by bugzilla — 2020-08-22T00:16:00Z
Moved from https://issues.dlang.org/show_bug.cgi?id=5922 [email protected] writes: D2 code, static (thread-local) variables can't be used in ASM: void main() { static size_t x = 10; asm { mov EDI, x; } } It produces: object.Error: Access Violation They work using __gshared, this gives no errors: void main() { __gshared static size_t x = 10; asm { mov EDI, x; } } My suggestion is to remove this source of errors. One solution may be to disallow the direct access to static variables from asm code, avoiding this bug.
Comment #1 by bugzilla — 2020-08-22T08:19:39Z
The current dmd says: test.d(7): Error: cannot directly load TLS variable `x`