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()7void staticDtorHook() { atomicOp!"+="(tlsDtor, 1); } sharedStaticDtorHook()8void sharedStaticDtorHook() { atomicOp!"+="(dtor, 1); } 9 runTest(string name)10void 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)23void 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