D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21186 - Inline Assembler: static (thread-local) variables cannot be used
Summary: Inline Assembler: static (thread-local) variables cannot be used
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid, iasm, wrong-code
Depends on:
Blocks:
 
Reported: 2020-08-22 00:16 UTC by Walter Bright
Modified: 2020-08-22 08:19 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2020-08-22 00:16:00 UTC
Moved from https://issues.dlang.org/show_bug.cgi?id=5922

bearophile_hugs@eml.cc 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 Walter Bright 2020-08-22 08:19:39 UTC
The current dmd says:

test.d(7): Error: cannot directly load TLS variable `x`