digitalmars.D.learn - equivalent of __attribute__((constructor))
- Ellery Newcomer (18/18) May 22 2013 In the context of shared libraries, with gcc
- Jacob Carlborg (5/23) May 22 2013 I don't know if it's automatically linked but here you go:
- Ellery Newcomer (2/5) May 23 2013 posix.mak makes no reference to it
- Jacob Carlborg (9/10) May 23 2013 Then I guess it's not used. Just compile it manually and link with it. I...
- Ellery Newcomer (2/10) May 24 2013 so don't document it :)
- Johannes Pfau (6/32) May 24 2013 LDC has got #pragma(LDC_global_crt_[c/d]tor) for this, see
In the context of shared libraries, with gcc __attribute__((constructor)) void myfunc() { .. } is used to make myfunc be called upon loading of the shared library (you can tell I know what I am talking about here) via some field in the ELF headers, apparently. Is there any way to get our trusty d compilers to do the equivalent? Sure, Ellery, we have this awesome feature called module constructors. Check em out. Ehh, I would be using this to initialize druntime... You could just define _init, couldn't you? Yes, but there is only one _init, while the above can be used with multiple functions and thus wouldn't inadvertently cause important code to not run. If I don't have to, I'd rather not. Wait, why are you initializing druntime? Because druntime isn't set up to do it yet for c main calling d shared lib. You'd think it would need the same sort of functionality when it does implement it, though.
May 22 2013
On 2013-05-23 06:27, Ellery Newcomer wrote:In the context of shared libraries, with gcc __attribute__((constructor)) void myfunc() { .. } is used to make myfunc be called upon loading of the shared library (you can tell I know what I am talking about here) via some field in the ELF headers, apparently. Is there any way to get our trusty d compilers to do the equivalent? Sure, Ellery, we have this awesome feature called module constructors. Check em out. Ehh, I would be using this to initialize druntime... You could just define _init, couldn't you? Yes, but there is only one _init, while the above can be used with multiple functions and thus wouldn't inadvertently cause important code to not run. If I don't have to, I'd rather not. Wait, why are you initializing druntime? Because druntime isn't set up to do it yet for c main calling d shared lib. You'd think it would need the same sort of functionality when it does implement it, though.I don't know if it's automatically linked but here you go: https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dylib_fixes.c -- /Jacob Carlborg
May 22 2013
On 05/22/2013 11:18 PM, Jacob Carlborg wrote:On 2013-05-23 06:27, Ellery Newcomer wrote: I don't know if it's automatically linked but here you go: https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dylib_fixes.cposix.mak makes no reference to it
May 23 2013
On 2013-05-24 02:02, Ellery Newcomer wrote:posix.mak makes no reference to itThen I guess it's not used. Just compile it manually and link with it. I don't think that D has anything corresponding to __attribute__((constructor)). I also see a problem with adding such feature. It will be run before the runtime is initialized (that's how it works now). Then people will start using it and complain about there code failing in mysterious ways because the runtime isn't initialized. -- /Jacob Carlborg
May 23 2013
On 05/23/2013 11:39 PM, Jacob Carlborg wrote:On 2013-05-24 02:02, Ellery Newcomer wrote:so don't document it :)posix.mak makes no reference to itThen I guess it's not used. Just compile it manually and link with it. I don't think that D has anything corresponding to __attribute__((constructor)). I also see a problem with adding such feature. It will be run before the runtime is initialized (that's how it works now). Then people will start using it and complain about there code failing in mysterious ways because the runtime isn't initialized.
May 24 2013
Am Wed, 22 May 2013 21:27:00 -0700 schrieb Ellery Newcomer <ellery-newcomer utulsa.edu>:In the context of shared libraries, with gcc __attribute__((constructor)) void myfunc() { .. } is used to make myfunc be called upon loading of the shared library (you can tell I know what I am talking about here) via some field in the ELF headers, apparently. Is there any way to get our trusty d compilers to do the equivalent? Sure, Ellery, we have this awesome feature called module constructors. Check em out. Ehh, I would be using this to initialize druntime... You could just define _init, couldn't you? Yes, but there is only one _init, while the above can be used with multiple functions and thus wouldn't inadvertently cause important code to not run. If I don't have to, I'd rather not. Wait, why are you initializing druntime? Because druntime isn't set up to do it yet for c main calling d shared lib. You'd think it would need the same sort of functionality when it does implement it, though.LDC has got #pragma(LDC_global_crt_[c/d]tor) for this, see http://wiki.dlang.org/LDC-specific_language_changes#Pragmas We will at some point implement something similar in gdc. I don't know about dmd though.
May 24 2013