osx shared libraries.

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 6 13:08:54 PDT 2015


On 2015-06-06 20:52, bitwise wrote:
> I'm trying to fix shared libraries for OSX. I've updated sections_osx.d
> to support multiple images, however, the method of notifying druntime
> when to load/unload images needs to be fixed.
>
> Currently, the following method is used to register a callback for when
> images are loaded, which, based on the last conversation on this topic,
> is a no-go. Basically, the problem is that there is no way of
> unregistering the callbacks.
> https://github.com/D-Programming-Language/druntime/blob/master/src/rt/sections_osx.d#L76
>
>
> So the solution is to add __attribute__((constructor/destructor)) calls
> to all D binaries on OSX to initialize the images.
>
> The code looks like this:
> http://dpaste.com/0SF46B6
>
> So my question is, what is the best way to get this code into the binary?
>
> I suppose the code could be pre-compiled into an object file and linked
> by dmd during compilation, but adding external dependencies to dmd seems
> like a bad idea.
>
> I would say DMD could generate this code, but where would it go?

For Linux (and FreeBSD I think) the compiler already generates a 
__attribute__((constructor)) function which calls _d_dso_registry [1]. 
Modify the compiler to do the same thing for OS X.

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

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list