* RE: dynamic libraries: custom _init() without losing default _init()
@ 2005-03-29 22:03 Zagorodnev, Grigory
2005-03-29 22:46 ` matze
0 siblings, 1 reply; 5+ messages in thread
From: Zagorodnev, Grigory @ 2005-03-29 22:03 UTC (permalink / raw)
To: matze, gcc-help
>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?
>
>matze
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;
- Grigory
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dynamic libraries: custom _init() without losing default _init()
2005-03-29 22:03 dynamic libraries: custom _init() without losing default _init() Zagorodnev, Grigory
@ 2005-03-29 22:46 ` matze
0 siblings, 0 replies; 5+ messages in thread
From: matze @ 2005-03-29 22:46 UTC (permalink / raw)
To: Zagorodnev, Grigory; +Cc: gcc-help
[-- Attachment #1: Type: text/plain, Size: 1637 bytes --]
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 `-
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dynamic libraries: custom _init() without losing default _init()
2005-03-30 7:38 Zagorodnev, Grigory
@ 2005-03-30 17:24 ` matze
0 siblings, 0 replies; 5+ messages in thread
From: matze @ 2005-03-30 17:24 UTC (permalink / raw)
To: Zagorodnev, Grigory; +Cc: gcc-help
[-- Attachment #1: Type: text/plain, Size: 914 bytes --]
El Wed, Mar 30, 2005 at 10:24:46AM +0400 Zagorodnev, Grigory ha dit:
> 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?
with ".init_array" it works and fits perfectly our needs
thanks a lot!
matze
--
Comunicar bichos a <bug-coreutils@gnu.org>
(LANG=es_ES uname --help)
( ( ( i ) ) ) http://barcelona.indymedia.org ( ( ( i ) ) )
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver keys.indymedia.org --recv-keys B9A88F6F `-
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: dynamic libraries: custom _init() without losing default _init()
@ 2005-03-30 7:38 Zagorodnev, Grigory
2005-03-30 17:24 ` matze
0 siblings, 1 reply; 5+ messages in thread
From: Zagorodnev, Grigory @ 2005-03-30 7:38 UTC (permalink / raw)
To: matze; +Cc: gcc-help
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@indymedia.org]
>Sent: Wednesday, March 30, 2005 2:34 AM
>To: Zagorodnev, Grigory
>Cc: gcc-help@gnu.org
>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 `-
^ permalink raw reply [flat|nested] 5+ messages in thread
* dynamic libraries: custom _init() without losing default _init()
@ 2005-03-29 16:30 matze
0 siblings, 0 replies; 5+ messages in thread
From: matze @ 2005-03-29 16:30 UTC (permalink / raw)
To: gcc-help
[-- Attachment #1: Type: text/plain, Size: 939 bytes --]
hi,
now i understand why i had/have problems with statical member
variables (http://gcc.gnu.org/ml/gcc-help/2005-03/msg00270.html) a new
question arises:
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?
ciao
matze
--
You can chain me, you can torture me, you can even
destroy this body, but you will never imprison my mind
(Mahatma Gandhi)
( ( ( i ) ) ) http://barcelona.indymedia.org ( ( ( i ) ) )
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver keys.indymedia.org --recv-keys B9A88F6F `-
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-03-30 7:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-29 22:03 dynamic libraries: custom _init() without losing default _init() Zagorodnev, Grigory
2005-03-29 22:46 ` matze
-- strict thread matches above, loose matches on Subject: below --
2005-03-30 7:38 Zagorodnev, Grigory
2005-03-30 17:24 ` matze
2005-03-29 16:30 matze
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).