Thread local variables in betterC
Blatnik
blatblatnik at gmail.com
Sun May 9 23:11:08 UTC 2021
On Sunday, 9 May 2021 at 22:55:41 UTC, Imperatorn wrote:
> Check the assembly
I already did, here's the "wrong" version when I only run `$ dmd
-betterC -m64 test.d`:
```
Dump of file test.obj
main:
push rbp
mov rbp,rsp
mov rax,qword ptr gs:[58h]
mov rcx,qword ptr [rax]
mov edx,offset _D4test1ai
mov dword ptr [rcx+rdx],42
xor eax,eax
pop rbp
ret
```
And here it is when I run `$ dmd -betterC -m64 -c test.d`:
```
Dump of file test.obj
main:
push rbp
mov rbp,rsp
push rbx
mov eax,dword ptr [_tls_index] <--------
mov rcx,qword ptr gs:[58h]
mov rdx,qword ptr [rcx+rax*8]
mov ebx,offset _D4test1ai
mov dword ptr [rdx+rbx],42
xor eax,eax
pop rbx
rbp
ret
```
So this just seems like some sort of compiler bug. It doesn't
emit the TLS index retrieval unless you compile with `-c` and
link separately.
Also, I've looked into this now, and thread locals _should_ work
in -betterC as far as I can tell. There's no mention of them not
working on https://dlang.org/spec/betterc.html, and if they
really didn't work it would have been mentioned there in bold all
caps. It would be pretty important to mention that `int a = 0;`
doesn't work correctly.
More information about the Digitalmars-d-learn
mailing list