next up previous
Next: Using ELF with Up: Extended GCC Features Previous: Extended GCC Features

The Initialization Functions in the C library

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.



J.H.M.Dassen
Tue Aug 1 14:18:10 MDT 1995