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
Thu Sep 17 08:12:42 PDT 2015


On 2015-09-17 00:29, ponce wrote:
> Context: On OSX, a C program can load a D shared library but once
> unloaded the next dlopen will crash, jumping into a callback that
> doesn't exist anymore.
>
> I've filed it here: https://issues.dlang.org/show_bug.cgi?id=15060
>
>
> It looks like this was known and discussed several times already:
> http://forum.dlang.org/post/vixoqmidlbizawbxmsao@forum.dlang.org (2015)
> https://github.com/D-Programming-Language/druntime/pull/228 (2012)
>
>
> Any idea to work-around this problem would be awesome.
>
> I'm not looking for something correct, future-proof, or pretty. Any shit
> that still stick to the wall will do. Anything!
>
> The only case I need to support is: C host, D shared library, with
> runtime statically linked.
>
> Please help!

Easiest would be to not unload the library. If that doesn't work, 
replace "_dyld_register_func_for_add_image" [1] with 
"dyld_register_image_state_change_handler" [2].

[1] 
https://github.com/D-Programming-Language/druntime/blob/master/src/rt/sections_osx.d#L76

[2] 
http://www.opensource.apple.com/source/dyld/dyld-353.2.3/include/mach-o/dyld_priv.h

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list