xref: /netbsd-src/external/gpl3/gcc.old/dist/libphobos/testsuite/libphobos.shared/load_13414.d (revision 627f7eb200a4419d89b531d55fccd2ee3ffdcde0)
1 import core.runtime;
2 import core.atomic;
3 import core.stdc.string;
4 import core.sys.posix.dlfcn;
5 
6 shared uint tlsDtor, dtor;
staticDtorHook()7 void staticDtorHook() { atomicOp!"+="(tlsDtor, 1); }
sharedStaticDtorHook()8 void sharedStaticDtorHook() { atomicOp!"+="(dtor, 1); }
9 
runTest(string name)10 void runTest(string name)
11 {
12     auto h = Runtime.loadLibrary(name);
13     assert(h !is null);
14 
15     *cast(void function()*).dlsym(h, "_D9lib_1341414staticDtorHookOPFZv") = &staticDtorHook;
16     *cast(void function()*).dlsym(h, "_D9lib_1341420sharedStaticDtorHookOPFZv") = &sharedStaticDtorHook;
17 
18     Runtime.unloadLibrary(h);
19     assert(tlsDtor == 1);
20     assert(dtor == 1);
21 }
22 
main(string[]args)23 void main(string[] args)
24 {
25     auto name = args[0] ~ '\0';
26     const pathlen = strrchr(name.ptr, '/') - name.ptr + 1;
27     name = name[0 .. pathlen] ~ "lib_13414.so";
28 
29     runTest(name);
30 }
31