Desperately looking for a work-around to load and unload D shared libraries from C on OSX

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 18 07:07:37 PDT 2015


On 2015-09-18 11:43, ponce wrote:

> Much success.
> Not only did this work, it worked (around) right away!
>
> Final patch here:
> https://github.com/p0nce/dplug/commit/7dc6385ebb8147cc53cfe69bfd54e41f5341e158

The way it behaves is that the runtime uses a function to register the a 
callback which is called by the dynamic linker each time an image 
(dynamic library/exectuable) is loaded.

When the callback points to a function that itself is located in a 
dynamic library it will cause dlopen to crash if the dynamic library has 
been unloaded because the callback is not valid anymore.

For some reason it's not possible to unregister a callback.

When "dyld_register_image_state_change_handler" is used instead, it pins 
the dynamic library which contains the callback and it's actually never 
unloaded, even though dlclose is called.

So when dyld_register_image_state_change_handler is called from you're 
plugin it pins the dynamic library and the callback register in the 
runtime will still be valid.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list