osx shared libraries.

bitwise via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 6 11:52:11 PDT 2015


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?

I don't think it would be right to add the __constructors__ to a random  
*.o produced by the compiler, because people will expect *.o files to  
behave like *.o files. On the other hand, if the __constructors__ were to  
be added by dmd at link-time, and someone used a linker other than dmd, it  
would not add in the __constructor__ code, and thus generate a defective  
dylib. This is a complicated problem with many things to consider, so I'm  
not exactly sure where to go from here.

Any ideas on this would be much appreciated.

Thanks,
   Bit


More information about the Digitalmars-d mailing list