Bug 13938 – IASM shouldn't be able to access TLS variables

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-01-05T19:58:00Z
Last change time
2017-07-18T13:47:25Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2015-01-05T19:58:28Z
cat > bug.d << CODE void test1() { static int val; asm { mov EAX, val; } } CODE dmd -c bug This should print an error because the TLS variable can't be accessed like that.
Comment #1 by k.hara.pg — 2015-01-06T14:14:44Z
Comment #2 by code — 2015-01-06T22:19:05Z
It's fairly tricky, we would need to ensure that the correct code sequence is used. That's not really trackable and many can't be correctly written in D's IASM. So indeed it would be better to disallow them.
Comment #3 by code — 2015-01-06T22:37:53Z
For example this is the sequence to write to a TLS variable in X86 code (non-PIC), the one for X64 doesn't work, because dmd's IASM doesn't support RIP relative addressing. size_t a; void main() { asm { mov EAX, GS:[0x00]; mov ECX, a; mov [EAX+1*ECX], 3; } }
Comment #4 by github-bugzilla — 2015-01-11T01:21:46Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/83bf7e53b2a8505444ba1eda1555aee177017749 fix Issue 13938 - IASM shouldn't be able to access TLS variables https://github.com/D-Programming-Language/dmd/commit/756cda4c5a73ac35c7f48faae20de73493d210a4 Merge pull request #4260 from 9rnsr/fix_iasm Issue 13938 & 13939 - Disallow non-trivial variable accesses in iasm
Comment #5 by github-bugzilla — 2015-02-18T03:41:57Z
Comment #6 by dlang-bugzilla — 2017-07-18T13:47:25Z
*** Issue 7720 has been marked as a duplicate of this issue. ***