www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - shared libraries on OS X

reply "John Colvin" <john.loughran.colvin gmail.com> writes:
what's the status?

I tried building druntime with 'make -f posix.mak dll' and got

src/rt/sections.d(52): Error: static assert  (is(typeof(__error) 
== void* function())) is false


I'd be happy to put in some work to improve the situation, but a 
brief overview of the status quo would be useful.
Nov 11 2014
parent reply Jacob Carlborg <doob me.com> writes:
On 2014-11-11 11:42, John Colvin wrote:
 what's the status?

 I tried building druntime with 'make -f posix.mak dll' and got

 src/rt/sections.d(52): Error: static assert  (is(typeof(__error) ==
 void* function())) is false


 I'd be happy to put in some work to improve the situation, but a brief
 overview of the status quo would be useful.
The first step would be to implement native TLS, see this issue [1]. The next step that would probably be to look at the changes in druntime made for Linux to add support for shared libraries. I think a major part of that is in rt_sections.d or similar. There were some changes to the compiler as well, adding some hooks when a dynamic library is loaded. But that shouldn't be needed on OS X since the dynamic linker have native support for this. [1] https://issues.dlang.org/show_bug.cgi?id=9476 -- /Jacob Carlborg
Nov 11 2014
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2014-11-11 15:05, Jacob Carlborg wrote:

 The first step would be to implement native TLS, see this issue [1].
BTW, the reason to implement native TLS is because otherwise we need to implement basically what the dynamic linker is already doing for TLS our self. Since it would be nice to have native TLS support anyway I thought that was a better idea. -- /Jacob Carlborg
Nov 11 2014
next sibling parent reply Martin Nowak <code+news.digitalmars dawg.eu> writes:
On 11/11/2014 06:24 PM, Jacob Carlborg wrote:
 BTW, the reason to implement native TLS is because otherwise we need to
 implement basically what the dynamic linker is already doing for TLS our
 self. Since it would be nice to have native TLS support anyway I thought
 that was a better idea.
What's the situation of native TLS? Any docs? What version of OSX is required?
Nov 14 2014
parent reply "David Nadlinger" <code klickverbot.at> writes:
On Friday, 14 November 2014 at 15:22:45 UTC, Martin Nowak wrote:
 What's the situation of native TLS? Any docs?
 What version of OSX is required?
10.7. And IMHO the most useful documentation for actually getting stuff done is the ld source code (opensource.apple.com). David
Nov 14 2014
parent Jacob Carlborg <doob me.com> writes:
On 2014-11-14 17:18, David Nadlinger wrote:

 10.7. And IMHO the most useful documentation for actually getting stuff
 done is the ld source code (opensource.apple.com).
There's also the source code for the compiler (Clang, LLVM) and the dynamic linker (dyld). -- /Jacob Carlborg
Nov 15 2014
prev sibling parent reply "Sean Kelly" <sean invisibleduck.org> writes:
On Tuesday, 11 November 2014 at 17:24:31 UTC, Jacob Carlborg 
wrote:
 On 2014-11-11 15:05, Jacob Carlborg wrote:

 The first step would be to implement native TLS, see this 
 issue [1].
BTW, the reason to implement native TLS is because otherwise we need to implement basically what the dynamic linker is already doing for TLS our self. Since it would be nice to have native TLS support anyway I thought that was a better idea.
We're two releases into having native support for TLS in OSX now, so it probably is time to switch over.
Nov 14 2014
parent Jacob Carlborg <doob me.com> writes:
On 2014-11-14 17:40, Sean Kelly wrote:

 We're two releases into having native support for TLS in OSX now, so it
 probably is time to switch over.
There have been four releases of OS X which support TLS, 10.7-10.10. -- /Jacob Carlborg
Nov 15 2014
prev sibling parent reply Martin Nowak <code+news.digitalmars dawg.eu> writes:
On 11/11/2014 03:05 PM, Jacob Carlborg wrote:
 There were some changes to the compiler as well, adding some hooks when
 a dynamic library is loaded. But that shouldn't be needed on OS X since
 the dynamic linker have native support for this.
Yes, you need a constructor and destructor in each shared library that call into druntime to register all modules, EH handlers and such things. There is some Mach-O support to be notified (via a callback) when a new shared library is loaded. It wasn't possible to unset that callback though, meaning it would segfault when druntime itself is unloaded. So either we get this runtime linker stuff to work or we simply use __attribute__((constructor))/__attribute__((destructor)) functions like on linux.
Nov 14 2014
parent Jacob Carlborg <doob me.com> writes:
On 2014-11-14 16:26, Martin Nowak wrote:

 There is some Mach-O support to be notified (via a callback) when a new
 shared library is loaded. It wasn't possible to unset that callback
 though, meaning it would segfault when druntime itself is unloaded.
Right, I keep forgetting that. -- /Jacob Carlborg
Nov 15 2014