Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

Changes between Version 9 and Version 10 of TBR/UserManual/Using_C_Plus_Plus


Ignore:
Timestamp:
06/26/07 21:23:49 (17 years ago)
Author:
Rsg
Comment:

/* C++ .init Linker Magic */

Legend:

Unmodified
Added
Removed
Modified
  • TBR/UserManual/Using_C_Plus_Plus

    v9 v10  
    110110 * Note''', '''_init()''' is not an ordinary function but 'compiler/linker magic' which uses the special '''.init''' section. An object file's '''.init* section must be composed of small snippets of code like
    111111
    112  
    113112        do_something ();
    114113        do_something_else ();
    115114
    116 
    117115that should eventually go into the '''_init()''' routine. Any object may contain such code. The linker finally gathers all these snippets (in the order the objects are linked together) and that's where the '''ecrti.o/ecrtn.o''' files come into play. These two files bracket the '''.init''' snippets with a proper function prologue (from ecrti.o) and epilogue (ecrtn.o), i.e., if you link (ecrti/ecrtn implicitely provided by gcc specs) :
    118116
    119  
    120117      ecrti.o  my_object.o ecrtn.o
    121118
    122    you end up with something like ('translated into C'):
    123 
     119you end up with something like ('translated into C'):
    124120 
    125121      _init ()
     
    131127      } /* from ecrtn.o */
    132128
    133 
    134129Hence, the rtems_crti.S file does the following :
    135130
    136  
    137131      /* from ecrti.o: */
    138132      __init()
     
    151145      }
    152146
    153 
    154147GCC uses this feature to call C++ static constructors by sticking a call to :
    155 
    156148 
    157149      __do_global_ctors_aux()
    158150
    159 
    160151into the '''.init''' section of '''crtend.o''' hence if you don't link against '''crtbegin/crtend''' (bsp_specs) your constructors are not called.
    161152
    162   <big><strong>Your gcc configuration, linkcmds and bsp_specs must harmonize</strong></big>
     153<big><strong>Your gcc configuration, linkcmds and bsp_specs must harmonize</strong></big>