Daily bump.
[official-gcc.git] / libphobos / testsuite / libphobos.shared / load_13414.d
blob047d5079937830654f6b2727981113f50c8a7fef
1 import core.runtime;
2 import core.atomic;
3 import core.stdc.string;
4 import core.sys.posix.dlfcn;
6 shared uint tlsDtor, dtor;
7 void staticDtorHook() { atomicOp!"+="(tlsDtor, 1); }
8 void sharedStaticDtorHook() { atomicOp!"+="(dtor, 1); }
10 void runTest(string name)
12 auto h = Runtime.loadLibrary(name);
13 assert(h !is null);
15 *cast(void function()*).dlsym(h, "_D9lib_1341414staticDtorHookOPFZv") = &staticDtorHook;
16 *cast(void function()*).dlsym(h, "_D9lib_1341420sharedStaticDtorHookOPFZv") = &sharedStaticDtorHook;
18 Runtime.unloadLibrary(h);
19 version (CRuntime_Musl)
21 // On Musl, unloadLibrary is a no-op because dlclose is a no-op
22 assert(tlsDtor == 0);
23 assert(dtor == 0);
25 else
27 assert(tlsDtor == 1);
28 assert(dtor == 1);
32 void main(string[] args)
34 auto name = args[0] ~ '\0';
35 const pathlen = strrchr(name.ptr, '/') - name.ptr + 1;
36 name = name[0 .. pathlen] ~ "lib_13414.so";
38 runTest(name);