Bug 24056 – const uninitialized data at module scope is not in TLS
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-07-25T18:31:08Z
Last change time
2023-07-28T15:04:08Z
Keywords
pull, spec, wrong-code
Assigned to
No Owner
Creator
Steven Schveighoffer
Comments
Comment #0 by schveiguy — 2023-07-25T18:31:08Z
module-level data that is declared const is stored in the global segment, yet is editable from normal static constructors.
Either const data should be put into thread local storage, or they should not be editable from static ctors that aren't shared:
```d
import std.stdio;
import std.concurrency;
import core.thread;
const void * x;
static this()
{
auto addr = cast(void*) Thread.getThis();
writeln("this thread is ", addr);
x = addr;
}
void main()
{
writeln("Before spawning thread: ", x);
static void foo(Tid owner) {
send(owner, 1);
}
auto tid = spawn(&foo, thisTid);
receive((int x) {});
writeln("After spawning thread: ", x);
}
```
Output:
this thread is 55788EDF3628
Before spawning thread: 55788EDF3628
this thread is 7FC99E404000
After spawning thread: 7FC99E404000
Comment #1 by dlang-bot — 2023-07-25T19:30:26Z
@dkorpel created dlang/dmd pull request #15458 "Fix 24056 - const uninitialized data at module scope is not in TLS" fixing this issue:
- Fix 24056 - const uninitialized data at module scope is not in TLS
https://github.com/dlang/dmd/pull/15458
Comment #2 by dlang-bot — 2023-07-28T15:04:08Z
dlang/dmd pull request #15458 "Fix 24056 - const uninitialized data at module scope is not in TLS" was merged into master:
- 3d1a8aad9cac21ba131e9ddd4993f01e91007834 by Dennis Korpel:
Fix 24056 - const uninitialized data at module scope is not in TLS
https://github.com/dlang/dmd/pull/15458