Thread overview
-fpic option and dynimic so libs
Jun 11, 2005
Denis R
Jun 12, 2005
David Friedman
Jun 12, 2005
Denis R
Jun 12, 2005
David Friedman
Jun 12, 2005
Denis R
June 11, 2005
Hey,

I've seen -fpic/-fPIC patch sometime ago, but I dont see it anymore. I've got gdc now now, so perhaps its already all in ? No patch needed?

Also, are there already examples of how to build *.so from D code ?

How would I make equivalent gdc initialization routes

__attribute__((constructor)) init() { // init stuff }
__attribute__((destructor)) deinit() { // deinit stuff :) }


Gdc doest seem to have __attribute__ as gcc does.
June 12, 2005
Denis R wrote:
> Hey, 
> 
> I've seen -fpic/-fPIC patch sometime ago, but I dont see it anymore. I've got gdc now now, so perhaps its already all in ? No patch needed?
> 
> Also, are there already examples of how to build *.so from D code ?
> 
> How would I make equivalent gdc initialization routes
> 
> __attribute__((constructor)) init() { // init stuff }
> __attribute__((destructor)) deinit() { // deinit stuff :) }
> 
> 
> Gdc doest seem to have __attribute__ as gcc does. 

The -fpic patch was rolled into 0.12.1 and 0.13.

There is no way to speciy attributes now, but I plan to support them with "pragma(attribute,etc...)"

If you are building a shared library that will be linked with an executable, you can just use the normal D static constructors.  This works on Linux and some other OSes.

If you are loading a module at runtime, you need a workaround.  The easiest way is to have C function declared as a constructor calll a D function.

David

June 12, 2005
On Sun, 12 Jun 2005 09:02:19 -0400
David Friedman <d3rdclsmail_a_@_t_earthlink_d_._t_net> wrote:

Hello David, Thank you for reply.

Yes, i was wondering about loading at run time.

I dont really know how to declare a C function to be a constructor, in D. :$
Did you mean just have one function which the user must call explicitly first thing  after dlopen ?

I thought I would do something like that in D :  extern(C) { void init(); void deinit();  }, and use gcc' s like attributes for them, so that init()/deinit() are automagically called when needed.


> Denis R wrote:
> > Hey,
> > 
> > I've seen -fpic/-fPIC patch sometime ago, but I dont see it anymore. I've got gdc now now, so perhaps its already all in ? No patch needed?
> > 
> > Also, are there already examples of how to build *.so from D code ?
> > 
> > How would I make equivalent gdc initialization routes
> > 
> > __attribute__((constructor)) init() { // init stuff }
> > __attribute__((destructor)) deinit() { // deinit stuff :) }
> > 
> > 
> > Gdc doest seem to have __attribute__ as gcc does.
> 
> The -fpic patch was rolled into 0.12.1 and 0.13.
> 
> There is no way to speciy attributes now, but I plan to support them with "pragma(attribute,etc...)"
> 
> If you are building a shared library that will be linked with an executable, you can just use the normal D static constructors.  This works on Linux and some other OSes.
> 
> If you are loading a module at runtime, you need a workaround.  The easiest way is to have C function declared as a constructor calll a D function.
> 
> David
> 
June 12, 2005
This is what I had in mind:

--- somecfile.c:

extern void dinit(void);
static void cinit() __attribute__((constructor))
{
   dinit();
}

--- somedfile.d:

extern (C) void dinit()
{
   // D initialization...
}

David

Denis R wrote:
> On Sun, 12 Jun 2005 09:02:19 -0400
> David Friedman <d3rdclsmail_a_@_t_earthlink_d_._t_net> wrote:
> 
> Hello David, Thank you for reply.
> 
> Yes, i was wondering about loading at run time.
> 
> I dont really know how to declare a C function to be a constructor, in D. :$
> Did you mean just have one function which the user must call explicitly first thing  after dlopen ?
> 
> I thought I would do something like that in D :  extern(C) { void init(); void deinit();  }, and use gcc' s like attributes for them, so that init()/deinit() are automagically called when needed.
> 
> 
> 
>>Denis R wrote:
>>
>>>Hey, 
>>>
>>>I've seen -fpic/-fPIC patch sometime ago, but I dont see it anymore. I've got gdc now now, so perhaps its already all in ? No patch needed?
>>>
>>>Also, are there already examples of how to build *.so from D code ?
>>>
>>>How would I make equivalent gdc initialization routes
>>>
>>>__attribute__((constructor)) init() { // init stuff }
>>>__attribute__((destructor)) deinit() { // deinit stuff :) }
>>>
>>>
>>>Gdc doest seem to have __attribute__ as gcc does. 
>>
>>The -fpic patch was rolled into 0.12.1 and 0.13.
>>
>>There is no way to speciy attributes now, but I plan to support them with "pragma(attribute,etc...)"
>>
>>If you are building a shared library that will be linked with an executable, you can just use the normal D static constructors.  This works on Linux and some other OSes.
>>
>>If you are loading a module at runtime, you need a workaround.  The easiest way is to have C function declared as a constructor calll a D function.
>>
>>David
>>
June 12, 2005
Ah, sweet :)

Thanks again

On Sun, 12 Jun 2005 11:24:28 -0400
David Friedman <d3rdclsmail_a_@_t_earthlink_d_._t_net> wrote:

> This is what I had in mind:
> 
> --- somecfile.c:
> 
> extern void dinit(void);
> static void cinit() __attribute__((constructor))
> {
>     dinit();
> }
> 
> --- somedfile.d:
> 
> extern (C) void dinit()
> {
>     // D initialization...
> }
> 
> David
> 
> Denis R wrote:
> > On Sun, 12 Jun 2005 09:02:19 -0400
> > David Friedman <d3rdclsmail_a_@_t_earthlink_d_._t_net> wrote:
> > 
> > Hello David, Thank you for reply.
> > 
> > Yes, i was wondering about loading at run time.
> > 
> > I dont really know how to declare a C function to be a constructor, in D. :$
> > Did you mean just have one function which the user must call explicitly first thing  after dlopen ?
> > 
> > I thought I would do something like that in D :  extern(C) { void init(); void deinit();  }, and use gcc' s like attributes for them, so that init()/deinit() are automagically called when needed.
> > 
> > 
> > 
> >>Denis R wrote:
> >>
> >>>Hey,
> >>>
> >>>I've seen -fpic/-fPIC patch sometime ago, but I dont see it anymore. I've got gdc now now, so perhaps its already all in ? No patch needed?
> >>>
> >>>Also, are there already examples of how to build *.so from D code ?
> >>>
> >>>How would I make equivalent gdc initialization routes
> >>>
> >>>__attribute__((constructor)) init() { // init stuff }
> >>>__attribute__((destructor)) deinit() { // deinit stuff :) }
> >>>
> >>>
> >>>Gdc doest seem to have __attribute__ as gcc does.
> >>
> >>The -fpic patch was rolled into 0.12.1 and 0.13.
> >>
> >>There is no way to speciy attributes now, but I plan to support them with "pragma(attribute,etc...)"
> >>
> >>If you are building a shared library that will be linked with an executable, you can just use the normal D static constructors.  This works on Linux and some other OSes.
> >>
> >>If you are loading a module at runtime, you need a workaround.  The easiest way is to have C function declared as a constructor calll a D function.
> >>
> >>David
> >>