shared libs for OSX
Jacob Carlborg via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 25 11:39:37 PDT 2015
On 2015-05-25 16:33, bitwise wrote:
> I've been reading through the Mach-O docs[1], and it seems that dynamic
> libs are treated the same as static libs in that exported symbols can
> only be defined once, even across dynamically loaded libraries. This is
> why calling rt_init from my dylib ended up calling the one that was
> already defined in the application image. I was able to call the rt_init
> from the dylib by specifically requesting it through dlsym, but then,
> all the global variables it used(_isRuntimeInitialized, etc) still ended
> up resolving to the ones in the application image.
>
> At this point, my impression is that it would be very impractical, if
> not impossible to have separate druntimes for each shared library. Even
> when you do link separate runtimes, dyld still treats all the exported
> symbols as shared.
>
>
> @Martin
> So correct me if I'm wrong, but it seems the _only_ choice is a shared
> druntime for osx.
> Could you elaborate a bit on how you've managed to do this for linux?
If I recall correctly, this is how it works:
On Linux the compiler will generate a function which is placed in a
special section in the binary, same as annotating a C function with
__attribute__((constructor)). This function calls a function in the
druntime. This will give similar properties as
_dyld_register_func_for_add_image on OS X but without the issues with
registered callbacks
Each image then becomes responsible to initialize itself. The image
updates the shared data structure containing the necessary data (TLS,
exception handling tables, ...). As you noticed yourself, all global
symbols are shared across all images.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list