digitalmars.D.learn - shared lib
- Ellery Newcomer (10/10) Nov 10 2011 trying to build a .so file (actually, trying to resuscitate pyd) with gd...
- Jerry (5/15) Nov 14 2011 Shared libs on linux require things to be compiled with -fPIC so the
- Jacob Carlborg (4/24) Nov 14 2011 DMD cannot currently generate correct PIC on linux.
- Johannes Pfau (6/32) Nov 14 2011 That's a backend bug though, GDC and LDC shouldn't be affected. But
- Jacob Carlborg (4/10) Nov 14 2011 Yeah, that's right, forgot it was not about DMD.
- Ellery Newcomer (6/10) Nov 14 2011 you know, I think you're right. I even wrote out the names of all those
- Jerry (3/6) Nov 14 2011 I haven't tried LDC, sorry. I'd think you would use it similarly to
- Jacob Carlborg (8/18) Nov 14 2011 core.runtime.Runtime.initialize
- Ellery Newcomer (26/36) Nov 15 2011 yep, found that file yesterday a little after I posted
- Jacob Carlborg (14/33) Nov 15 2011 Make sure rt_init and rt_term are only called once. You can take a look
trying to build a .so file (actually, trying to resuscitate pyd) with gdc. celerid is spitting out gdc -fPIC -nostartfiles -shared -fdebug {lots of object files plus some link directives} which is spitting out /usr/bin/ld: /usr/lib64/libgphobos2.a(object_.o): relocation R_X86_64_32S against `_D11TypeInfo_Pv6__initZ' can not be used when making a shared object; recompile with -fPIC /usr/lib64/libgphobos2.a: could not read symbols: Bad value any ideas what might be wrong?
Nov 10 2011
Ellery Newcomer <ellery-newcomer utulsa.edu> writes:trying to build a .so file (actually, trying to resuscitate pyd) with gdc. celerid is spitting out gdc -fPIC -nostartfiles -shared -fdebug {lots of object files plus some link directives} which is spitting out /usr/bin/ld: /usr/lib64/libgphobos2.a(object_.o): relocation R_X86_64_32S against `_D11TypeInfo_Pv6__initZ' can not be used when making a shared object; recompile with -fPIC /usr/lib64/libgphobos2.a: could not read symbols: Bad value any ideas what might be wrong?Shared libs on linux require things to be compiled with -fPIC so the code can be relocated. The error looks like phobos wasn't build with position-independent code. Beyond that I don't know. Jerry
Nov 14 2011
On 2011-11-14 17:31, Jerry wrote:Ellery Newcomer<ellery-newcomer utulsa.edu> writes:DMD cannot currently generate correct PIC on linux. -- /Jacob Carlborgtrying to build a .so file (actually, trying to resuscitate pyd) with gdc. celerid is spitting out gdc -fPIC -nostartfiles -shared -fdebug {lots of object files plus some link directives} which is spitting out /usr/bin/ld: /usr/lib64/libgphobos2.a(object_.o): relocation R_X86_64_32S against `_D11TypeInfo_Pv6__initZ' can not be used when making a shared object; recompile with -fPIC /usr/lib64/libgphobos2.a: could not read symbols: Bad value any ideas what might be wrong?Shared libs on linux require things to be compiled with -fPIC so the code can be relocated. The error looks like phobos wasn't build with position-independent code. Beyond that I don't know. Jerry
Nov 14 2011
Jacob Carlborg wrote:On 2011-11-14 17:31, Jerry wrote:That's a backend bug though, GDC and LDC shouldn't be affected. But some inline asm in phobos also doesn't work in PIC (see https://bitbucket.org/goshawk/gdc/issue/166/add-shared-lib-support). -- Johannes PfauEllery Newcomer<ellery-newcomer utulsa.edu> writes:DMD cannot currently generate correct PIC on linux.trying to build a .so file (actually, trying to resuscitate pyd) with gdc. celerid is spitting out gdc -fPIC -nostartfiles -shared -fdebug {lots of object files plus some link directives} which is spitting out /usr/bin/ld: /usr/lib64/libgphobos2.a(object_.o): relocation R_X86_64_32S against `_D11TypeInfo_Pv6__initZ' can not be used when making a shared object; recompile with -fPIC /usr/lib64/libgphobos2.a: could not read symbols: Bad value any ideas what might be wrong?Shared libs on linux require things to be compiled with -fPIC so the code can be relocated. The error looks like phobos wasn't build with position-independent code. Beyond that I don't know. Jerry
Nov 14 2011
On 2011-11-14 19:54, Johannes Pfau wrote:Jacob Carlborg wrote:Yeah, that's right, forgot it was not about DMD. -- /Jacob CarlborgDMD cannot currently generate correct PIC on linux.That's a backend bug though, GDC and LDC shouldn't be affected. But some inline asm in phobos also doesn't work in PIC (see https://bitbucket.org/goshawk/gdc/issue/166/add-shared-lib-support).
Nov 14 2011
On 11/14/2011 10:31 AM, Jerry wrote:The error looks like phobos wasn't build with position-independent code. Jerryyou know, I think you're right. I even wrote out the names of all those *.a files when I was building a gdc rpm. *slaps head* well, it doesn't matter now. I've gotten ldc to generate shared libs successfully. Now I just need to know how to start up druntime. any ideas?
Nov 14 2011
Ellery Newcomer <ellery-newcomer utulsa.edu> writes:well, it doesn't matter now. I've gotten ldc to generate shared libs successfully. Now I just need to know how to start up druntime. any ideas?I haven't tried LDC, sorry. I'd think you would use it similarly to C++. I.e. link your main program to the shared libs and run it.
Nov 14 2011
On 2011-11-14 19:05, Ellery Newcomer wrote:On 11/14/2011 10:31 AM, Jerry wrote:core.runtime.Runtime.initialize Not sure if that will initialize everything properly. Have a look in rt.dmain2.main and make sure you do that same initialize the runtime. It would be better if rt.dmain2.main would call rt.dmain2.rt_init instead of do all the initialize directly in main. -- /Jacob CarlborgThe error looks like phobos wasn't build with position-independent code. Jerryyou know, I think you're right. I even wrote out the names of all those *.a files when I was building a gdc rpm. *slaps head* well, it doesn't matter now. I've gotten ldc to generate shared libs successfully. Now I just need to know how to start up druntime. any ideas?
Nov 14 2011
On 11/15/2011 01:19 AM, Jacob Carlborg wrote:On 2011-11-14 19:05, Ellery Newcomer wrote: core.runtime.Runtime.initializecoolNot sure if that will initialize everything properly. Have a look in rt.dmain2.main and make sure you do that same initialize the runtime.yep, found that file yesterday a little after I postedIt would be better if rt.dmain2.main would call rt.dmain2.rt_init instead of do all the initialize directly in main.I just call rt_init and rt_term. The one thing I'm wondering about is what happens when I need to load multiple d shared libs (the shallow answer is rt_term crashes, but rt_init doesn't). I assume it would create two instances of the d runtime, which is just lovely from a memory leakage perspective. So my bare bones looks like this just now: extern(C) shared bool _D2rt6dmain212_d_isHaltingOb; alias _D2rt6dmain212_d_isHaltingOb _d_isHalting; extern(C) { void rt_init(); void rt_term(); void _init() { rt_init(); } void _fini() { if(!_d_isHalting){ rt_term(); } } } /* extern(C) */ I suppose the isHalting test should go in a critical section, but otherwise I have working pyd modules! Now if only I could remember why I wanted to use pyd in the first place..
Nov 15 2011
On 2011-11-16 01:27, Ellery Newcomer wrote:On 11/15/2011 01:19 AM, Jacob Carlborg wrote:Make sure rt_init and rt_term are only called once. You can take a look how it's done in Tango, I've implemented the support for dynamic libraries for Mac OS X. http://www.dsource.org/projects/tango/browser/trunk/tango/core/rt/compiler/ldc/rt/dmain2.d If you don't want to look at Tango code you can have a look at: http://d.puremagic.com/issues/attachment.cgi?id=607 Look at the diff for src/rt/dylib_fixes.c and src/rt/dmain2.d. The GCC attribute __attribute__((constructor)) and __attribute__((destructor)) can be used to initialize and terminate the runtime, look at the diff for src/rt/dylib_fixes.cOn 2011-11-14 19:05, Ellery Newcomer wrote: core.runtime.Runtime.initializecoolNot sure if that will initialize everything properly. Have a look in rt.dmain2.main and make sure you do that same initialize the runtime.yep, found that file yesterday a little after I postedIt would be better if rt.dmain2.main would call rt.dmain2.rt_init instead of do all the initialize directly in main.I just call rt_init and rt_term. The one thing I'm wondering about is what happens when I need to load multiple d shared libs (the shallow answer is rt_term crashes, but rt_init doesn't). I assume it would create two instances of the d runtime, which is just lovely from a memory leakage perspective.Now if only I could remember why I wanted to use pyd in the first place..Haha. -- /Jacob Carlborg
Nov 15 2011