Another gcc feature is
__attribute__
((section (`` sectionname''))).
With this,
one can put a function or a data structure in any section.
static void foo (int argc, char **argv, char **envp) __attribute__ ((section ("_libc_foo"))); static void foo (int argc, char **argv, char **envp) { } static void bar (int argc, char **argv, char **envp) { } static void * __libc_subinit_bar__ __attribute__ ((section ("_libc_subinit"))) = &(bar);
Here we place foo in the _libc_foo
section and
__libc_subinit_bar__
in the _libc_subinit
section. In the Linux C library _libc_subinit
is a special
section which contains an array of function pointers with prototype
void (*) (int argc, char **argv, char **envp);
where argc, argv and envp has the same meaning as in main. Functions in this section will be called before entering the main function. They are used in the Linux C library to initialize a few global variables.