RE: dynamic libraries: custom _init() without losing default _init()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, Matze!
I'm actually surprised that preinit_array disallowed for DSO. 

Thus you may try to use ".init_array" section in the same manner. That
works fine for DSO but makes your initialization routine called _after_
C++ file-scope object constructors. Does the order really matter?

- Grigory

>-----Original Message-----
>From: matze [mailto:matze@xxxxxxxxxxxxx]
>Sent: Wednesday, March 30, 2005 2:34 AM
>To: Zagorodnev, Grigory
>Cc: gcc-help@xxxxxxx
>Subject: Re: dynamic libraries: custom _init() without losing default
>_init()
>
>El Wed, Mar 30, 2005 at 01:05:26AM +0400 Zagorodnev, Grigory ha dit:
>
>> >to initialize the dynamic library a custom _init() is called. is it
>> >possible to call default _init() from the custom one or is there
>> >another way to invoke a custom function from default _init() or
>> >directly afterwards?
>>
>> It would be safer to not override default startup code, but use one
of
>> the following:
>>
>> Once your code is C++ you can create file-scope instance of some
>> initialization class so its constructor will do the work. This is
most
>> portable approach.
>>
>> In case library initialization code must be executed _before_ any C++
>> object constructor, you may use ".preinit_array"
>> 	static preinit(int argc, char *argv[]);
>> 	static void (*const preinit_ptr) (int argc, char *argv[])
>> 	     __attribute__ ((section (".preinit_array"))) = &preinit;
>
>thanks for your answer grigory, if that works it's actually cook :)
>
>i tried it, but the linker complains about the following:
>
>matze@assata:/tmp$ g++ -shared foo.cpp -o foo.so
>/usr/bin/ld: /tmp/cc1zrrRc.o: .preinit_array section is not allowed in
>DSO
>
>any idea?
>
>matze
>
>--
>             You must have a plan. If you don't have a plan,
>               you'll become part of somebody else's plan
>
>    ( ( ( i ) ) )  http://barcelona.indymedia.org  ( ( ( i ) ) )
>                                                                 .''`.
>    using free software / Debian GNU/Linux | http://debian.org  : :'  :
>                                                                `. `'`
>gpg --keyserver keys.indymedia.org --recv-keys B9A88F6F           `-


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux