[Issue 22681] New: rt_moduleTlsCtor/Dtor() don't work with phobos dynamically linked

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 16 21:50:33 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=22681

          Issue ID: 22681
           Summary: rt_moduleTlsCtor/Dtor() don't work with phobos
                    dynamically linked
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: duser at airmail.cc

```
__gshared int ctors, dtors;
static this() { ctors++; }
static ~this() { dtors++; }
import core.thread;
import core.stdc.stdio;
void main() {
        ctors = 0;
        dtors = 0;
        createLowLevelThread({
                scope(failure) assert(0); // satisfy nothrow
                thread_attachThis();
                rt_moduleTlsCtor();
                rt_moduleTlsDtor();
                thread_detachThis();
        }).joinLowLevelThread;
        printf("ctors %d dtors %d\n", ctors, dtors);
        assert(ctors == 1 && dtors == 1);
}
```

with these commands, it works:
% dmd -run tlstest.d
% ldc2 -run tlstest.d

with these commands, the constructor and destructor don't run:
% dmd -defaultlib=phobos2 -run tlstest.d
% dmd -L-lphobos2 -run tlstest.d
% ldc2 --link-defaultlib-shared -run tlstest.d

other things that do TLS initialization like `new Thread()` and `rt_init()`
work normally

--


More information about the Digitalmars-d-bugs mailing list