www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Tango built as a dynamic library

reply Jacob Carlborg <doob me.com> writes:
I've managed to build Tango as a dynamic library with DMD on Mac OS X. I 
had some problems first but I managed to solve them and everything seems 
to work now.

What I had to do to build it as a dynamic library was:

Resolve the undefined symbol _Dmain.

Remove the globals _deh_beg and _deh_end in the deh module and 
_minfo_beg and _minfo_end in the object module. The beg and end 
variables are for determine the beginning and the end of special 
sections in the binaries but they're not put into the dynamic library 
and therefore cause linker errors (undefined symbol).

Get the module infos from the loaded executable and all the loaded 
dynamic libraries and collect them into one array (in the object module) 
in the order they are loaded (the data from executable should be last in 
the array).

Get all the exception handler tables from the loaded executable and all 
the loaded dynamic libraries and collect them into one array (in the deh 
module) in the order they are loaded (the data from executable should be 
last in the array).

Now when I thing about it what happens when a dynamic library built with 
GDC or LDC is linked with an executable built with DMD? I'm searing for 
specific segments and sections in the binaries that at least DMD puts there.

The next step is to clean up the code, create a patch, add support for 
64bit binaries and perhaps universal binaries (if that is needed). Then 
I'll do the same for Phobos 1 and 2.


/Jacob Carlborg
Mar 16 2010
next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 16 Mar 2010 06:59:19 -0400, Jacob Carlborg <doob me.com> wrote:

 I've managed to build Tango as a dynamic library with DMD on Mac OS X. I  
 had some problems first but I managed to solve them and everything seems  
 to work now.

 What I had to do to build it as a dynamic library was:

 Resolve the undefined symbol _Dmain.

 Remove the globals _deh_beg and _deh_end in the deh module and  
 _minfo_beg and _minfo_end in the object module. The beg and end  
 variables are for determine the beginning and the end of special  
 sections in the binaries but they're not put into the dynamic library  
 and therefore cause linker errors (undefined symbol).

 Get the module infos from the loaded executable and all the loaded  
 dynamic libraries and collect them into one array (in the object module)  
 in the order they are loaded (the data from executable should be last in  
 the array).

 Get all the exception handler tables from the loaded executable and all  
 the loaded dynamic libraries and collect them into one array (in the deh  
 module) in the order they are loaded (the data from executable should be  
 last in the array).

 Now when I thing about it what happens when a dynamic library built with  
 GDC or LDC is linked with an executable built with DMD? I'm searing for  
 specific segments and sections in the binaries that at least DMD puts  
 there.

 The next step is to clean up the code, create a patch, add support for  
 64bit binaries and perhaps universal binaries (if that is needed). Then  
 I'll do the same for Phobos 1 and 2.
This is awesome! I would recommend that you should do Phobos 2 before Phobos 1. Phobos 1 is pretty much dead wood IMO. I'm not even sure a patch would be accepted, since this modifies the runtime. -Steve
Mar 16 2010
prev sibling next sibling parent reply Eldar Insafutdinov <e.insafutdinov gmail.com> writes:
Jacob Carlborg Wrote:

 I've managed to build Tango as a dynamic library with DMD on Mac OS X. I 
 had some problems first but I managed to solve them and everything seems 
 to work now.
 
 What I had to do to build it as a dynamic library was:
 
 Resolve the undefined symbol _Dmain.
 
 Remove the globals _deh_beg and _deh_end in the deh module and 
 _minfo_beg and _minfo_end in the object module. The beg and end 
 variables are for determine the beginning and the end of special 
 sections in the binaries but they're not put into the dynamic library 
 and therefore cause linker errors (undefined symbol).
 
 Get the module infos from the loaded executable and all the loaded 
 dynamic libraries and collect them into one array (in the object module) 
 in the order they are loaded (the data from executable should be last in 
 the array).
 
 Get all the exception handler tables from the loaded executable and all 
 the loaded dynamic libraries and collect them into one array (in the deh 
 module) in the order they are loaded (the data from executable should be 
 last in the array).
 
 Now when I thing about it what happens when a dynamic library built with 
 GDC or LDC is linked with an executable built with DMD? I'm searing for 
 specific segments and sections in the binaries that at least DMD puts there.
 
 The next step is to clean up the code, create a patch, add support for 
 64bit binaries and perhaps universal binaries (if that is needed). Then 
 I'll do the same for Phobos 1 and 2.
 
 
 /Jacob Carlborg
Thank you very much! I suppose there should not be a major problem to make it working on Linux as well?
Mar 16 2010
parent Jacob Carlborg <doob me.com> writes:
On 3/16/10 17:51, Eldar Insafutdinov wrote:
 Jacob Carlborg Wrote:

 I've managed to build Tango as a dynamic library with DMD on Mac OS X. I
 had some problems first but I managed to solve them and everything seems
 to work now.

 What I had to do to build it as a dynamic library was:

 Resolve the undefined symbol _Dmain.

 Remove the globals _deh_beg and _deh_end in the deh module and
 _minfo_beg and _minfo_end in the object module. The beg and end
 variables are for determine the beginning and the end of special
 sections in the binaries but they're not put into the dynamic library
 and therefore cause linker errors (undefined symbol).

 Get the module infos from the loaded executable and all the loaded
 dynamic libraries and collect them into one array (in the object module)
 in the order they are loaded (the data from executable should be last in
 the array).

 Get all the exception handler tables from the loaded executable and all
 the loaded dynamic libraries and collect them into one array (in the deh
 module) in the order they are loaded (the data from executable should be
 last in the array).

 Now when I thing about it what happens when a dynamic library built with
 GDC or LDC is linked with an executable built with DMD? I'm searing for
 specific segments and sections in the binaries that at least DMD puts there.

 The next step is to clean up the code, create a patch, add support for
 64bit binaries and perhaps universal binaries (if that is needed). Then
 I'll do the same for Phobos 1 and 2.


 /Jacob Carlborg
Thank you very much! I suppose there should not be a major problem to make it working on Linux as well?
No I don't think so. I assume the same ideas can be applied to Linux as well. I just don't know how to access the ModuleInfo and EH sections on Linux.
Mar 17 2010
prev sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
Jacob Carlborg wrote:
 I've managed to build Tango as a dynamic library with DMD on Mac OS X. I 
 had some problems first but I managed to solve them and everything seems 
 to work now.
Thanks for doing this. In the next update, I plan to remove the special deh sections, and instead make the EH tables available through the ModuleInfo. This should simplify the management of multiple sections, as the only data structure that needs to be aggregated will be the ModuleInfo array.
Mar 16 2010
parent reply Michel Fortin <michel.fortin michelf.com> writes:
On 2010-03-16 15:01:43 -0400, Walter Bright <newshound1 digitalmars.com> said:

 Jacob Carlborg wrote:
 I've managed to build Tango as a dynamic library with DMD on Mac OS X. 
 I had some problems first but I managed to solve them and everything 
 seems to work now.
Thanks for doing this. In the next update, I plan to remove the special deh sections, and instead make the EH tables available through the ModuleInfo. This should simplify the management of multiple sections, as the only data structure that needs to be aggregated will be the ModuleInfo array.
Shouldn't that also apply to TLS sections for when the linker does not support the feature? I'm thinking of Mac OS X and Windows XP with dynamically-loaded DLLs. -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Mar 16 2010
parent Walter Bright <newshound1 digitalmars.com> writes:
Michel Fortin wrote:
 On 2010-03-16 15:01:43 -0400, Walter Bright <newshound1 digitalmars.com> 
 said:
 In the next update, I plan to remove the special deh sections, and 
 instead make the EH tables available through the ModuleInfo. This 
 should simplify the management of multiple sections, as the only data 
 structure that needs to be aggregated will be the ModuleInfo array.
Shouldn't that also apply to TLS sections for when the linker does not support the feature? I'm thinking of Mac OS X and Windows XP with dynamically-loaded DLLs.
Rainer Schuetze has found a way to work with the system TLS properly. It's not the linker that's the problem, it's Windows systems earlier than Vista.
Mar 16 2010