Static Initializers

You must invoke static initializers to initialize static data before the start of main(). To do so, use the STATICINIT keyword to have the linker generate the static initializer sections.

In your linker command file, use lines similar to these:

  ___sinit__ = .;
  
  

STATICINIT

to tell the linker where to put the table of static initializers (relative to the ' .' location counter).

The program identifies the symbol ___sinit__ at runtime. So in startup code, you can use corresponding lines such as these:

  #ifdef __cplusplus
  
  
  /* call the c++ static initializers */
  
  
  __call_static_initializers();
  
  
  #endif