I found out the GCC gets round this by exporting

void __attribute__ ((constructor)) my_init(void)
void __attribute__ ((destructor)) my_fini(void)

form the library, these get called before the dlopen and dlclose functions return to the main application. This would be a perfect place to call the shared memory manager.

I don't know if there is any way to support those attributes under free pascal though :?: :?: