This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


>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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]