TLS/GC issues on macOS
David Nadlinger
code at klickverbot.at
Thu Jan 3 20:18:56 UTC 2019
On 3 Jan 2019, at 12:58, Sönke Ludwig via digitalmars-d-ldc wrote:
> There appears to be a GC visibility issue of TLS sections on macOS
> when multiple threads are involved. I added a test case to what looks
> like the same issue: https://github.com/ldc-developers/ldc/issues/2187
Try this patch:
```
diff --git a/src/rt/sections_elf_shared.d b/src/rt/sections_elf_shared.d
index a7b3336a..bc84a116 100644
--- a/src/rt/sections_elf_shared.d
+++ b/src/rt/sections_elf_shared.d
@@ -296,6 +296,20 @@ else
{
_tlsRanges = cast(Array!(void[])*)calloc(1,
Array!(void[]).sizeof);
_tlsRanges || assert(0, "Could not allocate TLS range
storage");
+
+ version (Shared) {} else
+ {
+ version (Linux)
+ {
+ // Nothing to do; glibc allocates the TLS area for
additional
+ // threads at the beginning of the stack space, so
they will already
+ // be scanned.
+ }
+ else version (OSX)
+ {
+
_tlsRanges.insertBack(getTLSRange(&dummyTlsSymbol));
+ }
+ }
}
return _tlsRanges;
}
```
Still trying to figure out how much of that code can be stripped away
for non-Shared builds (it's a mess, as DMD partially supports shared
libraries on Linux with a static runtime), or how on earth nobody has
found this before.
Best,
David
More information about the digitalmars-d-ldc
mailing list