- Timestamp:
-
06/26/07 21:23:49 (17 years ago)
- Author:
-
Rsg
- Comment:
-
/* C++ .init Linker Magic */
Legend:
- Unmodified
- Added
- Removed
- Modified
-
v9
|
v10
|
|
110 | 110 | * 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 |
111 | 111 | |
112 | | |
113 | 112 | do_something (); |
114 | 113 | do_something_else (); |
115 | 114 | |
116 | | |
117 | 115 | that 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) : |
118 | 116 | |
119 | | |
120 | 117 | ecrti.o my_object.o ecrtn.o |
121 | 118 | |
122 | | you end up with something like ('translated into C'): |
123 | | |
| 119 | you end up with something like ('translated into C'): |
124 | 120 | |
125 | 121 | _init () |
… |
… |
|
131 | 127 | } /* from ecrtn.o */ |
132 | 128 | |
133 | | |
134 | 129 | Hence, the rtems_crti.S file does the following : |
135 | 130 | |
136 | | |
137 | 131 | /* from ecrti.o: */ |
138 | 132 | __init() |
… |
… |
|
151 | 145 | } |
152 | 146 | |
153 | | |
154 | 147 | GCC uses this feature to call C++ static constructors by sticking a call to : |
155 | | |
156 | 148 | |
157 | 149 | __do_global_ctors_aux() |
158 | 150 | |
159 | | |
160 | 151 | into the '''.init''' section of '''crtend.o''' hence if you don't link against '''crtbegin/crtend''' (bsp_specs) your constructors are not called. |
161 | 152 | |
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> |