Showing with 14 additions and 1 deletion.
  1. +4 −1 src/core/thread.d
  2. +10 −0 src/rt/sections_elf_shared.d
5 changes: 4 additions & 1 deletion src/core/thread.d
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ else version( Posix )
}
assert( obj );

// loadedLibraries need to be inherited from parent thread
// before initilizing GC for TLS (rt_tlsgc_init)
version (Shared) inheritLoadedLibraries(loadedLibraries);

assert( obj.m_curr is &obj.m_main );
obj.m_main.bstack = getStackBottom();
obj.m_main.tstack = obj.m_main.bstack;
Expand Down Expand Up @@ -378,7 +382,6 @@ else version( Posix )

try
{
version (Shared) inheritLoadedLibraries(loadedLibraries);
rt_moduleTlsCtor();
try
{
Expand Down
10 changes: 10 additions & 0 deletions src/rt/sections_elf_shared.d
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ version (Shared)
assert(_loadedDSOs.empty);
_loadedDSOs.swap(*cast(Array!(ThreadDSO)*)p);
.free(p);
foreach (ref dso; _loadedDSOs)
{
// the copied _tlsRange corresponds to parent thread
dso.updateTLSRange();
}
}

// Called after all TLS dtors ran, decrements all remaining dlopen refs.
Expand Down Expand Up @@ -267,6 +272,11 @@ version (Shared)
else static assert(0, "unimplemented");
void[] _tlsRange;
alias _pdso this;
// update the _tlsRange for the executing thread
void updateTLSRange()
{
_tlsRange = getTLSRange(_pdso._tlsMod, _pdso._tlsSize);
}
}
Array!(ThreadDSO) _loadedDSOs;

Expand Down