annotate libgcc/crtstuff.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Specialized bits of code needed to support construction and
kono
parents:
diff changeset
2 destruction of file-scope objects in C++ code.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
3 Copyright (C) 1991-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
4 Contributed by Ron Guilmette (rfg@monkeys.com).
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 This file is part of GCC.
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
9 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
10 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
11 version.
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
16 for more details.
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
19 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
20 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
23 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
25 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 /* This file is a bit like libgcc2.c in that it is compiled
kono
parents:
diff changeset
28 multiple times and yields multiple .o files.
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 This file is useful on target machines where the object file format
kono
parents:
diff changeset
31 supports multiple "user-defined" sections (e.g. COFF, ELF, ROSE). On
kono
parents:
diff changeset
32 such systems, this file allows us to avoid running collect (or any
kono
parents:
diff changeset
33 other such slow and painful kludge). Additionally, if the target
kono
parents:
diff changeset
34 system supports a .init section, this file allows us to support the
kono
parents:
diff changeset
35 linking of C++ code with a non-C++ main program.
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 Note that if INIT_SECTION_ASM_OP is defined in the tm.h file, then
kono
parents:
diff changeset
38 this file *will* make use of the .init section. If that symbol is
kono
parents:
diff changeset
39 not defined however, then the .init section will not be used.
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 Currently, only ELF and COFF are supported. It is likely however that
kono
parents:
diff changeset
42 ROSE could also be supported, if someone was willing to do the work to
kono
parents:
diff changeset
43 make whatever (small?) adaptations are needed. (Some work may be
kono
parents:
diff changeset
44 needed on the ROSE assembler and linker also.)
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 This file must be compiled with gcc. */
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 /* Target machine header files require this define. */
kono
parents:
diff changeset
49 #define IN_LIBGCC2
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 /* FIXME: Including auto-host is incorrect, but until we have
kono
parents:
diff changeset
52 identified the set of defines that need to go into auto-target.h,
kono
parents:
diff changeset
53 this will have to do. */
kono
parents:
diff changeset
54 #include "auto-host.h"
kono
parents:
diff changeset
55 #undef caddr_t
kono
parents:
diff changeset
56 #undef pid_t
kono
parents:
diff changeset
57 #undef rlim_t
kono
parents:
diff changeset
58 #undef ssize_t
kono
parents:
diff changeset
59 #undef vfork
kono
parents:
diff changeset
60 #include "tconfig.h"
kono
parents:
diff changeset
61 #include "tsystem.h"
kono
parents:
diff changeset
62 #include "coretypes.h"
kono
parents:
diff changeset
63 #include "tm.h"
kono
parents:
diff changeset
64 #include "libgcc_tm.h"
kono
parents:
diff changeset
65 #include "unwind-dw2-fde.h"
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 #ifndef FORCE_CODE_SECTION_ALIGN
kono
parents:
diff changeset
68 # define FORCE_CODE_SECTION_ALIGN
kono
parents:
diff changeset
69 #endif
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 #ifndef CRT_CALL_STATIC_FUNCTION
kono
parents:
diff changeset
72 # define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \
kono
parents:
diff changeset
73 static void __attribute__((__used__)) \
kono
parents:
diff changeset
74 call_ ## FUNC (void) \
kono
parents:
diff changeset
75 { \
kono
parents:
diff changeset
76 asm (SECTION_OP); \
kono
parents:
diff changeset
77 FUNC (); \
kono
parents:
diff changeset
78 FORCE_CODE_SECTION_ALIGN \
kono
parents:
diff changeset
79 asm (__LIBGCC_TEXT_SECTION_ASM_OP__); \
kono
parents:
diff changeset
80 }
kono
parents:
diff changeset
81 #endif
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 #if defined(TARGET_DL_ITERATE_PHDR) && \
kono
parents:
diff changeset
84 (defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__))
kono
parents:
diff changeset
85 #define BSD_DL_ITERATE_PHDR_AVAILABLE
kono
parents:
diff changeset
86 #endif
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 #if defined(OBJECT_FORMAT_ELF) \
kono
parents:
diff changeset
89 && !defined(OBJECT_FORMAT_FLAT) \
kono
parents:
diff changeset
90 && defined(HAVE_LD_EH_FRAME_HDR) \
kono
parents:
diff changeset
91 && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
kono
parents:
diff changeset
92 && defined(BSD_DL_ITERATE_PHDR_AVAILABLE)
kono
parents:
diff changeset
93 #include <link.h>
kono
parents:
diff changeset
94 # define USE_PT_GNU_EH_FRAME
kono
parents:
diff changeset
95 #endif
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 #if defined(OBJECT_FORMAT_ELF) \
kono
parents:
diff changeset
98 && !defined(OBJECT_FORMAT_FLAT) \
kono
parents:
diff changeset
99 && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR) \
kono
parents:
diff changeset
100 && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
kono
parents:
diff changeset
101 && defined(__sun__) && defined(__svr4__)
kono
parents:
diff changeset
102 #include <link.h>
kono
parents:
diff changeset
103 # define USE_PT_GNU_EH_FRAME
kono
parents:
diff changeset
104 #endif
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 #if defined(OBJECT_FORMAT_ELF) \
kono
parents:
diff changeset
107 && !defined(OBJECT_FORMAT_FLAT) \
kono
parents:
diff changeset
108 && defined(HAVE_LD_EH_FRAME_HDR) \
kono
parents:
diff changeset
109 && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
kono
parents:
diff changeset
110 && defined(__GLIBC__) && __GLIBC__ >= 2
kono
parents:
diff changeset
111 #include <link.h>
kono
parents:
diff changeset
112 /* uClibc pretends to be glibc 2.2 and DT_CONFIG is defined in its link.h.
kono
parents:
diff changeset
113 But it doesn't use PT_GNU_EH_FRAME ELF segment currently. */
kono
parents:
diff changeset
114 # if !defined(__UCLIBC__) \
kono
parents:
diff changeset
115 && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
kono
parents:
diff changeset
116 || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
kono
parents:
diff changeset
117 # define USE_PT_GNU_EH_FRAME
kono
parents:
diff changeset
118 # endif
kono
parents:
diff changeset
119 #endif
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 #if defined(OBJECT_FORMAT_ELF) \
kono
parents:
diff changeset
122 && !defined(OBJECT_FORMAT_FLAT) \
kono
parents:
diff changeset
123 && defined(HAVE_LD_EH_FRAME_HDR) \
kono
parents:
diff changeset
124 && !defined(CRTSTUFFT_O) \
kono
parents:
diff changeset
125 && defined(inhibit_libc) \
kono
parents:
diff changeset
126 && (defined(__GLIBC__) || defined(__gnu_linux__) || defined(__GNU__))
kono
parents:
diff changeset
127 /* On systems using glibc, an inhibit_libc build of libgcc is only
kono
parents:
diff changeset
128 part of a bootstrap process. Build the same crt*.o as would be
kono
parents:
diff changeset
129 built with headers present, so that it is not necessary to build
kono
parents:
diff changeset
130 glibc more than once for the bootstrap to converge. */
kono
parents:
diff changeset
131 # define USE_PT_GNU_EH_FRAME
kono
parents:
diff changeset
132 #endif
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 #ifdef USE_EH_FRAME_REGISTRY_ALWAYS
kono
parents:
diff changeset
135 # ifndef __LIBGCC_EH_FRAME_SECTION_NAME__
kono
parents:
diff changeset
136 # error "Can't use explicit exception-frame-registration without __LIBGCC_EH_FRAME_SECTION_NAME__"
kono
parents:
diff changeset
137 # endif
kono
parents:
diff changeset
138 #endif
kono
parents:
diff changeset
139 #if defined(__LIBGCC_EH_FRAME_SECTION_NAME__) && (!defined(USE_PT_GNU_EH_FRAME) || defined(USE_EH_FRAME_REGISTRY_ALWAYS))
kono
parents:
diff changeset
140 # define USE_EH_FRAME_REGISTRY
kono
parents:
diff changeset
141 #endif
kono
parents:
diff changeset
142 #if defined(__LIBGCC_EH_FRAME_SECTION_NAME__) \
kono
parents:
diff changeset
143 && __LIBGCC_EH_TABLES_CAN_BE_READ_ONLY__
kono
parents:
diff changeset
144 # define EH_FRAME_SECTION_CONST const
kono
parents:
diff changeset
145 #else
kono
parents:
diff changeset
146 # define EH_FRAME_SECTION_CONST
kono
parents:
diff changeset
147 #endif
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 #if !defined(DTOR_LIST_END) && defined(OBJECT_FORMAT_ELF) \
kono
parents:
diff changeset
150 && defined(HAVE_GAS_HIDDEN) && !defined(FINI_ARRAY_SECTION_ASM_OP)
kono
parents:
diff changeset
151 # define HIDDEN_DTOR_LIST_END
kono
parents:
diff changeset
152 #endif
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 #if !defined(USE_TM_CLONE_REGISTRY) && defined(OBJECT_FORMAT_ELF)
kono
parents:
diff changeset
155 # define USE_TM_CLONE_REGISTRY 1
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
156 #elif !defined(USE_TM_CLONE_REGISTRY)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
157 # define USE_TM_CLONE_REGISTRY 0
111
kono
parents:
diff changeset
158 #endif
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 /* We do not want to add the weak attribute to the declarations of these
kono
parents:
diff changeset
161 routines in unwind-dw2-fde.h because that will cause the definition of
kono
parents:
diff changeset
162 these symbols to be weak as well.
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 This exposes a core issue, how to handle creating weak references vs
kono
parents:
diff changeset
165 how to create weak definitions. Either we have to have the definition
kono
parents:
diff changeset
166 of TARGET_WEAK_ATTRIBUTE be conditional in the shared header files or
kono
parents:
diff changeset
167 have a second declaration if we want a function's references to be weak,
kono
parents:
diff changeset
168 but not its definition.
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 Making TARGET_WEAK_ATTRIBUTE conditional seems like a good solution until
kono
parents:
diff changeset
171 one thinks about scaling to larger problems -- i.e., the condition under
kono
parents:
diff changeset
172 which TARGET_WEAK_ATTRIBUTE is active will eventually get far too
kono
parents:
diff changeset
173 complicated.
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 So, we take an approach similar to #pragma weak -- we have a second
kono
parents:
diff changeset
176 declaration for functions that we want to have weak references.
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 Neither way is particularly good. */
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 /* References to __register_frame_info and __deregister_frame_info should
kono
parents:
diff changeset
181 be weak in this file if at all possible. */
kono
parents:
diff changeset
182 extern void __register_frame_info (const void *, struct object *)
kono
parents:
diff changeset
183 TARGET_ATTRIBUTE_WEAK;
kono
parents:
diff changeset
184 extern void __register_frame_info_bases (const void *, struct object *,
kono
parents:
diff changeset
185 void *, void *)
kono
parents:
diff changeset
186 TARGET_ATTRIBUTE_WEAK;
kono
parents:
diff changeset
187 extern void *__deregister_frame_info (const void *)
kono
parents:
diff changeset
188 TARGET_ATTRIBUTE_WEAK;
kono
parents:
diff changeset
189 extern void *__deregister_frame_info_bases (const void *)
kono
parents:
diff changeset
190 TARGET_ATTRIBUTE_WEAK;
kono
parents:
diff changeset
191 extern void __do_global_ctors_1 (void);
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 /* Likewise for transactional memory clone tables. */
kono
parents:
diff changeset
194 extern void _ITM_registerTMCloneTable (void *, size_t) TARGET_ATTRIBUTE_WEAK;
kono
parents:
diff changeset
195 extern void _ITM_deregisterTMCloneTable (void *) TARGET_ATTRIBUTE_WEAK;
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 #ifdef OBJECT_FORMAT_ELF
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 /* Declare a pointer to void function type. */
kono
parents:
diff changeset
200 typedef void (*func_ptr) (void);
kono
parents:
diff changeset
201 #define STATIC static
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 #else /* OBJECT_FORMAT_ELF */
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 #include "gbl-ctors.h"
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 #define STATIC
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 #endif /* OBJECT_FORMAT_ELF */
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 #ifdef CRT_BEGIN
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 /* NOTE: In order to be able to support SVR4 shared libraries, we arrange
kono
parents:
diff changeset
214 to have one set of symbols { __CTOR_LIST__, __DTOR_LIST__, __CTOR_END__,
kono
parents:
diff changeset
215 __DTOR_END__ } per root executable and also one set of these symbols
kono
parents:
diff changeset
216 per shared library. So in any given whole process image, we may have
kono
parents:
diff changeset
217 multiple definitions of each of these symbols. In order to prevent
kono
parents:
diff changeset
218 these definitions from conflicting with one another, and in order to
kono
parents:
diff changeset
219 ensure that the proper lists are used for the initialization/finalization
kono
parents:
diff changeset
220 of each individual shared library (respectively), we give these symbols
kono
parents:
diff changeset
221 only internal (i.e. `static') linkage, and we also make it a point to
kono
parents:
diff changeset
222 refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
kono
parents:
diff changeset
223 symbol in crtbegin.o, where they are defined. */
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 /* No need for .ctors/.dtors section if linker can place them in
kono
parents:
diff changeset
226 .init_array/.fini_array section. */
kono
parents:
diff changeset
227 #ifndef USE_INITFINI_ARRAY
kono
parents:
diff changeset
228 /* The -1 is a flag to __do_global_[cd]tors indicating that this table
kono
parents:
diff changeset
229 does not start with a count of elements. */
kono
parents:
diff changeset
230 #ifdef CTOR_LIST_BEGIN
kono
parents:
diff changeset
231 CTOR_LIST_BEGIN;
kono
parents:
diff changeset
232 #elif defined(__LIBGCC_CTORS_SECTION_ASM_OP__)
kono
parents:
diff changeset
233 /* Hack: force cc1 to switch to .data section early, so that assembling
kono
parents:
diff changeset
234 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */
kono
parents:
diff changeset
235 static func_ptr force_to_data[1] __attribute__ ((__used__)) = { };
kono
parents:
diff changeset
236 asm (__LIBGCC_CTORS_SECTION_ASM_OP__);
kono
parents:
diff changeset
237 STATIC func_ptr __CTOR_LIST__[1]
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
238 __attribute__ ((__used__, aligned(__alignof__(func_ptr))))
111
kono
parents:
diff changeset
239 = { (func_ptr) (-1) };
kono
parents:
diff changeset
240 #else
kono
parents:
diff changeset
241 STATIC func_ptr __CTOR_LIST__[1]
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
242 __attribute__ ((__used__, section(".ctors"), aligned(__alignof__(func_ptr))))
111
kono
parents:
diff changeset
243 = { (func_ptr) (-1) };
kono
parents:
diff changeset
244 #endif /* __CTOR_LIST__ alternatives */
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 #ifdef DTOR_LIST_BEGIN
kono
parents:
diff changeset
247 DTOR_LIST_BEGIN;
kono
parents:
diff changeset
248 #elif defined(__LIBGCC_DTORS_SECTION_ASM_OP__)
kono
parents:
diff changeset
249 asm (__LIBGCC_DTORS_SECTION_ASM_OP__);
kono
parents:
diff changeset
250 STATIC func_ptr __DTOR_LIST__[1]
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
251 __attribute__ ((aligned(__alignof__(func_ptr))))
111
kono
parents:
diff changeset
252 = { (func_ptr) (-1) };
kono
parents:
diff changeset
253 #else
kono
parents:
diff changeset
254 STATIC func_ptr __DTOR_LIST__[1]
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
255 __attribute__((section(".dtors"), aligned(__alignof__(func_ptr))))
111
kono
parents:
diff changeset
256 = { (func_ptr) (-1) };
kono
parents:
diff changeset
257 #endif /* __DTOR_LIST__ alternatives */
kono
parents:
diff changeset
258 #endif /* USE_INITFINI_ARRAY */
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 #ifdef USE_EH_FRAME_REGISTRY
kono
parents:
diff changeset
261 /* Stick a label at the beginning of the frame unwind info so we can register
kono
parents:
diff changeset
262 and deregister it with the exception handling library code. */
kono
parents:
diff changeset
263 STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
kono
parents:
diff changeset
264 __attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4)))
kono
parents:
diff changeset
265 = { };
kono
parents:
diff changeset
266 #endif /* USE_EH_FRAME_REGISTRY */
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 #if USE_TM_CLONE_REGISTRY
kono
parents:
diff changeset
269 STATIC func_ptr __TMC_LIST__[]
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
270 __attribute__((used, section(".tm_clone_table"), aligned(__alignof__(void*))))
111
kono
parents:
diff changeset
271 = { };
kono
parents:
diff changeset
272 # ifdef HAVE_GAS_HIDDEN
kono
parents:
diff changeset
273 extern func_ptr __TMC_END__[] __attribute__((__visibility__ ("hidden")));
kono
parents:
diff changeset
274 # endif
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 static inline void
kono
parents:
diff changeset
277 deregister_tm_clones (void)
kono
parents:
diff changeset
278 {
kono
parents:
diff changeset
279 void (*fn) (void *);
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 #ifdef HAVE_GAS_HIDDEN
kono
parents:
diff changeset
282 func_ptr *end = __TMC_END__;
kono
parents:
diff changeset
283 // Do not optimize the comparison to false.
kono
parents:
diff changeset
284 __asm ("" : "+g" (end));
kono
parents:
diff changeset
285 if (__TMC_LIST__ == end)
kono
parents:
diff changeset
286 return;
kono
parents:
diff changeset
287 #else
kono
parents:
diff changeset
288 if (__TMC_LIST__[0] == NULL)
kono
parents:
diff changeset
289 return;
kono
parents:
diff changeset
290 #endif
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 fn = _ITM_deregisterTMCloneTable;
kono
parents:
diff changeset
293 __asm ("" : "+r" (fn));
kono
parents:
diff changeset
294 if (fn)
kono
parents:
diff changeset
295 fn (__TMC_LIST__);
kono
parents:
diff changeset
296 }
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 static inline void
kono
parents:
diff changeset
299 register_tm_clones (void)
kono
parents:
diff changeset
300 {
kono
parents:
diff changeset
301 void (*fn) (void *, size_t);
kono
parents:
diff changeset
302 size_t size;
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 #ifdef HAVE_GAS_HIDDEN
kono
parents:
diff changeset
305 func_ptr *end = __TMC_END__;
kono
parents:
diff changeset
306 // Do not optimize the comparison to false.
kono
parents:
diff changeset
307 __asm ("" : "+g" (end));
kono
parents:
diff changeset
308 size = (end - __TMC_LIST__) / 2;
kono
parents:
diff changeset
309 #else
kono
parents:
diff changeset
310 for (size = 0; __TMC_LIST__[size * 2] != NULL; size++)
kono
parents:
diff changeset
311 continue;
kono
parents:
diff changeset
312 #endif
kono
parents:
diff changeset
313 if (size == 0)
kono
parents:
diff changeset
314 return;
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 fn = _ITM_registerTMCloneTable;
kono
parents:
diff changeset
317 __asm ("" : "+r" (fn));
kono
parents:
diff changeset
318 if (fn)
kono
parents:
diff changeset
319 fn (__TMC_LIST__, size);
kono
parents:
diff changeset
320 }
kono
parents:
diff changeset
321 #endif /* USE_TM_CLONE_REGISTRY */
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 #if defined(__LIBGCC_INIT_SECTION_ASM_OP__) \
kono
parents:
diff changeset
324 || defined(__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__)
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 #ifdef OBJECT_FORMAT_ELF
kono
parents:
diff changeset
327
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
328 #if DEFAULT_USE_CXA_ATEXIT
111
kono
parents:
diff changeset
329 /* Declare the __dso_handle variable. It should have a unique value
kono
parents:
diff changeset
330 in every shared-object; in a main program its value is zero. The
kono
parents:
diff changeset
331 object should in any case be protected. This means the instance
kono
parents:
diff changeset
332 in one DSO or the main program is not used in another object. The
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
333 dynamic linker takes care of this.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
334 If __cxa_atexit is not being used, __dso_handle will not be used and
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
335 doesn't need to be defined. */
111
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 #ifdef TARGET_LIBGCC_SDATA_SECTION
kono
parents:
diff changeset
338 extern void *__dso_handle __attribute__ ((__section__ (TARGET_LIBGCC_SDATA_SECTION)));
kono
parents:
diff changeset
339 #endif
kono
parents:
diff changeset
340 #ifdef HAVE_GAS_HIDDEN
kono
parents:
diff changeset
341 extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
kono
parents:
diff changeset
342 #endif
kono
parents:
diff changeset
343 #ifdef CRTSTUFFS_O
kono
parents:
diff changeset
344 void *__dso_handle = &__dso_handle;
kono
parents:
diff changeset
345 #else
kono
parents:
diff changeset
346 void *__dso_handle = 0;
kono
parents:
diff changeset
347 #endif
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
348 #endif /* DEFAULT_USE_CXA_ATEXIT */
111
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 /* The __cxa_finalize function may not be available so we use only a
kono
parents:
diff changeset
351 weak declaration. */
kono
parents:
diff changeset
352 extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK;
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 /* Run all the global destructors on exit from the program. */
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 /* Some systems place the number of pointers in the first word of the
kono
parents:
diff changeset
357 table. On SVR4 however, that word is -1. In all cases, the table is
kono
parents:
diff changeset
358 null-terminated. On SVR4, we start from the beginning of the list and
kono
parents:
diff changeset
359 invoke each per-compilation-unit destructor routine in order
kono
parents:
diff changeset
360 until we find that null.
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 Note that this function MUST be static. There will be one of these
kono
parents:
diff changeset
363 functions in each root executable and one in each shared library, but
kono
parents:
diff changeset
364 although they all have the same code, each one is unique in that it
kono
parents:
diff changeset
365 refers to one particular associated `__DTOR_LIST__' which belongs to the
kono
parents:
diff changeset
366 same particular root executable or shared library file.
kono
parents:
diff changeset
367
kono
parents:
diff changeset
368 On some systems, this routine is run more than once from the .fini,
kono
parents:
diff changeset
369 when exit is called recursively, so we arrange to remember where in
kono
parents:
diff changeset
370 the list we left off processing, and we resume at that point,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
371 should we be re-invoked.
111
kono
parents:
diff changeset
372
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
373 This routine does not need to be run if none of the following clauses are
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
374 true, as it will not do anything, so can be removed. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
375 #if defined(CRTSTUFFS_O) || !defined(FINI_ARRAY_SECTION_ASM_OP) \
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
376 || USE_TM_CLONE_REGISTRY || defined(USE_EH_FRAME_REGISTRY)
111
kono
parents:
diff changeset
377 static void __attribute__((used))
kono
parents:
diff changeset
378 __do_global_dtors_aux (void)
kono
parents:
diff changeset
379 {
kono
parents:
diff changeset
380 static _Bool completed;
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 if (__builtin_expect (completed, 0))
kono
parents:
diff changeset
383 return;
kono
parents:
diff changeset
384
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
385 #if DEFAULT_USE_CXA_ATEXIT
111
kono
parents:
diff changeset
386 #ifdef CRTSTUFFS_O
kono
parents:
diff changeset
387 if (__cxa_finalize)
kono
parents:
diff changeset
388 __cxa_finalize (__dso_handle);
kono
parents:
diff changeset
389 #endif
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
390 #endif
111
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 #ifdef FINI_ARRAY_SECTION_ASM_OP
kono
parents:
diff changeset
393 /* If we are using .fini_array then destructors will be run via that
kono
parents:
diff changeset
394 mechanism. */
kono
parents:
diff changeset
395 #elif defined(HIDDEN_DTOR_LIST_END)
kono
parents:
diff changeset
396 {
kono
parents:
diff changeset
397 /* Safer version that makes sure only .dtors function pointers are
kono
parents:
diff changeset
398 called even if the static variable is maliciously changed. */
kono
parents:
diff changeset
399 extern func_ptr __DTOR_END__[] __attribute__((visibility ("hidden")));
kono
parents:
diff changeset
400 static size_t dtor_idx;
kono
parents:
diff changeset
401 const size_t max_idx = __DTOR_END__ - __DTOR_LIST__ - 1;
kono
parents:
diff changeset
402 func_ptr *dtor_list;
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 __asm ("" : "=g" (dtor_list) : "0" (__DTOR_LIST__));
kono
parents:
diff changeset
405 while (dtor_idx < max_idx)
kono
parents:
diff changeset
406 dtor_list[++dtor_idx] ();
kono
parents:
diff changeset
407 }
kono
parents:
diff changeset
408 #else /* !defined (FINI_ARRAY_SECTION_ASM_OP) */
kono
parents:
diff changeset
409 {
kono
parents:
diff changeset
410 static func_ptr *p = __DTOR_LIST__ + 1;
kono
parents:
diff changeset
411 func_ptr f;
kono
parents:
diff changeset
412
kono
parents:
diff changeset
413 while ((f = *p))
kono
parents:
diff changeset
414 {
kono
parents:
diff changeset
415 p++;
kono
parents:
diff changeset
416 f ();
kono
parents:
diff changeset
417 }
kono
parents:
diff changeset
418 }
kono
parents:
diff changeset
419 #endif /* !defined(FINI_ARRAY_SECTION_ASM_OP) */
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 #if USE_TM_CLONE_REGISTRY
kono
parents:
diff changeset
422 deregister_tm_clones ();
kono
parents:
diff changeset
423 #endif /* USE_TM_CLONE_REGISTRY */
kono
parents:
diff changeset
424
kono
parents:
diff changeset
425 #ifdef USE_EH_FRAME_REGISTRY
kono
parents:
diff changeset
426 #ifdef CRT_GET_RFIB_DATA
kono
parents:
diff changeset
427 /* If we used the new __register_frame_info_bases interface,
kono
parents:
diff changeset
428 make sure that we deregister from the same place. */
kono
parents:
diff changeset
429 if (__deregister_frame_info_bases)
kono
parents:
diff changeset
430 __deregister_frame_info_bases (__EH_FRAME_BEGIN__);
kono
parents:
diff changeset
431 #else
kono
parents:
diff changeset
432 if (__deregister_frame_info)
kono
parents:
diff changeset
433 __deregister_frame_info (__EH_FRAME_BEGIN__);
kono
parents:
diff changeset
434 #endif
kono
parents:
diff changeset
435 #endif
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 completed = 1;
kono
parents:
diff changeset
438 }
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 /* Stick a call to __do_global_dtors_aux into the .fini section. */
kono
parents:
diff changeset
441 #ifdef FINI_SECTION_ASM_OP
kono
parents:
diff changeset
442 CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)
kono
parents:
diff changeset
443 #elif defined (FINI_ARRAY_SECTION_ASM_OP)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
444 #if defined(__FDPIC__)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
445 __asm__("\t.equ\t__do_global_dtors_aux_alias, __do_global_dtors_aux\n");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
446 extern char __do_global_dtors_aux_alias;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
447 static void *__do_global_dtors_aux_fini_array_entry[]
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
448 __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(void *))))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
449 = { &__do_global_dtors_aux_alias };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
450 #else /* defined(__FDPIC__) */
111
kono
parents:
diff changeset
451 static func_ptr __do_global_dtors_aux_fini_array_entry[]
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
452 __attribute__ ((__used__, section(".fini_array"),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
453 aligned(__alignof__(func_ptr)))) = { __do_global_dtors_aux };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
454 #endif /* defined(__FDPIC__) */
111
kono
parents:
diff changeset
455 #else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */
kono
parents:
diff changeset
456 static void __attribute__((used))
kono
parents:
diff changeset
457 __do_global_dtors_aux_1 (void)
kono
parents:
diff changeset
458 {
kono
parents:
diff changeset
459 atexit (__do_global_dtors_aux);
kono
parents:
diff changeset
460 }
kono
parents:
diff changeset
461 CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__,
kono
parents:
diff changeset
462 __do_global_dtors_aux_1)
kono
parents:
diff changeset
463 #endif
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
464 #endif /* defined(CRTSTUFFS_O) || !defined(FINI_ARRAY_SECTION_ASM_OP)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
465 || USE_TM_CLONE_REGISTRY || defined(USE_EH_FRAME_REGISTRY) */
111
kono
parents:
diff changeset
466
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
467 #if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY
111
kono
parents:
diff changeset
468 /* Stick a call to __register_frame_info into the .init section. For some
kono
parents:
diff changeset
469 reason calls with no arguments work more reliably in .init, so stick the
kono
parents:
diff changeset
470 call in another function. */
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 static void __attribute__((used))
kono
parents:
diff changeset
473 frame_dummy (void)
kono
parents:
diff changeset
474 {
kono
parents:
diff changeset
475 #ifdef USE_EH_FRAME_REGISTRY
kono
parents:
diff changeset
476 static struct object object;
kono
parents:
diff changeset
477 #ifdef CRT_GET_RFIB_DATA
kono
parents:
diff changeset
478 void *tbase, *dbase;
kono
parents:
diff changeset
479 tbase = 0;
kono
parents:
diff changeset
480 CRT_GET_RFIB_DATA (dbase);
kono
parents:
diff changeset
481 if (__register_frame_info_bases)
kono
parents:
diff changeset
482 __register_frame_info_bases (__EH_FRAME_BEGIN__, &object, tbase, dbase);
kono
parents:
diff changeset
483 #else
kono
parents:
diff changeset
484 if (__register_frame_info)
kono
parents:
diff changeset
485 __register_frame_info (__EH_FRAME_BEGIN__, &object);
kono
parents:
diff changeset
486 #endif /* CRT_GET_RFIB_DATA */
kono
parents:
diff changeset
487 #endif /* USE_EH_FRAME_REGISTRY */
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 #if USE_TM_CLONE_REGISTRY
kono
parents:
diff changeset
490 register_tm_clones ();
kono
parents:
diff changeset
491 #endif /* USE_TM_CLONE_REGISTRY */
kono
parents:
diff changeset
492 }
kono
parents:
diff changeset
493
kono
parents:
diff changeset
494 #ifdef __LIBGCC_INIT_SECTION_ASM_OP__
kono
parents:
diff changeset
495 CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, frame_dummy)
kono
parents:
diff changeset
496 #else /* defined(__LIBGCC_INIT_SECTION_ASM_OP__) */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
497 #if defined(__FDPIC__)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
498 __asm__("\t.equ\t__frame_dummy_alias, frame_dummy\n");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
499 extern char __frame_dummy_alias;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
500 static void *__frame_dummy_init_array_entry[]
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
501 __attribute__ ((__used__, section(".init_array"), aligned(sizeof(void *))))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
502 = { &__frame_dummy_alias };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
503 #else /* defined(__FDPIC__) */
111
kono
parents:
diff changeset
504 static func_ptr __frame_dummy_init_array_entry[]
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
505 __attribute__ ((__used__, section(".init_array"),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
506 aligned(__alignof__(func_ptr)))) = { frame_dummy };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
507 #endif /* defined(__FDPIC__) */
111
kono
parents:
diff changeset
508 #endif /* !defined(__LIBGCC_INIT_SECTION_ASM_OP__) */
kono
parents:
diff changeset
509 #endif /* USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY */
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 #else /* OBJECT_FORMAT_ELF */
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 /* The function __do_global_ctors_aux is compiled twice (once in crtbegin.o
kono
parents:
diff changeset
514 and once in crtend.o). It must be declared static to avoid a link
kono
parents:
diff changeset
515 error. Here, we define __do_global_ctors as an externally callable
kono
parents:
diff changeset
516 function. It is externally callable so that __main can invoke it when
kono
parents:
diff changeset
517 INVOKE__main is defined. This has the additional effect of forcing cc1
kono
parents:
diff changeset
518 to switch to the .text section. */
kono
parents:
diff changeset
519
kono
parents:
diff changeset
520 static void __do_global_ctors_aux (void);
kono
parents:
diff changeset
521 void
kono
parents:
diff changeset
522 __do_global_ctors (void)
kono
parents:
diff changeset
523 {
kono
parents:
diff changeset
524 #ifdef INVOKE__main
kono
parents:
diff changeset
525 /* If __main won't actually call __do_global_ctors then it doesn't matter
kono
parents:
diff changeset
526 what's inside the function. The inside of __do_global_ctors_aux is
kono
parents:
diff changeset
527 called automatically in that case. And the Alliant fx2800 linker
kono
parents:
diff changeset
528 crashes on this reference. So prevent the crash. */
kono
parents:
diff changeset
529 __do_global_ctors_aux ();
kono
parents:
diff changeset
530 #endif
kono
parents:
diff changeset
531 }
kono
parents:
diff changeset
532
kono
parents:
diff changeset
533 asm (__LIBGCC_INIT_SECTION_ASM_OP__); /* cc1 doesn't know that we are switching! */
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 /* A routine to invoke all of the global constructors upon entry to the
kono
parents:
diff changeset
536 program. We put this into the .init section (for systems that have
kono
parents:
diff changeset
537 such a thing) so that we can properly perform the construction of
kono
parents:
diff changeset
538 file-scope static-storage C++ objects within shared libraries. */
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 static void __attribute__((used))
kono
parents:
diff changeset
541 __do_global_ctors_aux (void) /* prologue goes in .init section */
kono
parents:
diff changeset
542 {
kono
parents:
diff changeset
543 FORCE_CODE_SECTION_ALIGN /* explicit align before switch to .text */
kono
parents:
diff changeset
544 asm (__LIBGCC_TEXT_SECTION_ASM_OP__); /* don't put epilogue and body in .init */
kono
parents:
diff changeset
545 DO_GLOBAL_CTORS_BODY;
kono
parents:
diff changeset
546 atexit (__do_global_dtors);
kono
parents:
diff changeset
547 }
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 #endif /* OBJECT_FORMAT_ELF */
kono
parents:
diff changeset
550
kono
parents:
diff changeset
551 #elif defined(HAS_INIT_SECTION) /* ! __LIBGCC_INIT_SECTION_ASM_OP__ */
kono
parents:
diff changeset
552
kono
parents:
diff changeset
553 extern void __do_global_dtors (void);
kono
parents:
diff changeset
554
kono
parents:
diff changeset
555 /* This case is used by the Irix 6 port, which supports named sections but
kono
parents:
diff changeset
556 not an SVR4-style .fini section. __do_global_dtors can be non-static
kono
parents:
diff changeset
557 in this case because we protect it with -hidden_symbol. */
kono
parents:
diff changeset
558
kono
parents:
diff changeset
559 void
kono
parents:
diff changeset
560 __do_global_dtors (void)
kono
parents:
diff changeset
561 {
kono
parents:
diff changeset
562 func_ptr *p, f;
kono
parents:
diff changeset
563 for (p = __DTOR_LIST__ + 1; (f = *p); p++)
kono
parents:
diff changeset
564 f ();
kono
parents:
diff changeset
565
kono
parents:
diff changeset
566 #if USE_TM_CLONE_REGISTRY
kono
parents:
diff changeset
567 deregister_tm_clones ();
kono
parents:
diff changeset
568 #endif /* USE_TM_CLONE_REGISTRY */
kono
parents:
diff changeset
569
kono
parents:
diff changeset
570 #ifdef USE_EH_FRAME_REGISTRY
kono
parents:
diff changeset
571 if (__deregister_frame_info)
kono
parents:
diff changeset
572 __deregister_frame_info (__EH_FRAME_BEGIN__);
kono
parents:
diff changeset
573 #endif
kono
parents:
diff changeset
574 }
kono
parents:
diff changeset
575
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
576 #if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY
111
kono
parents:
diff changeset
577 /* A helper function for __do_global_ctors, which is in crtend.o. Here
kono
parents:
diff changeset
578 in crtbegin.o, we can reference a couple of symbols not visible there.
kono
parents:
diff changeset
579 Plus, since we're before libgcc.a, we have no problems referencing
kono
parents:
diff changeset
580 functions from there. */
kono
parents:
diff changeset
581 void
kono
parents:
diff changeset
582 __do_global_ctors_1(void)
kono
parents:
diff changeset
583 {
kono
parents:
diff changeset
584 #ifdef USE_EH_FRAME_REGISTRY
kono
parents:
diff changeset
585 static struct object object;
kono
parents:
diff changeset
586 if (__register_frame_info)
kono
parents:
diff changeset
587 __register_frame_info (__EH_FRAME_BEGIN__, &object);
kono
parents:
diff changeset
588 #endif
kono
parents:
diff changeset
589
kono
parents:
diff changeset
590 #if USE_TM_CLONE_REGISTRY
kono
parents:
diff changeset
591 register_tm_clones ();
kono
parents:
diff changeset
592 #endif /* USE_TM_CLONE_REGISTRY */
kono
parents:
diff changeset
593 }
kono
parents:
diff changeset
594 #endif /* USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY */
kono
parents:
diff changeset
595
kono
parents:
diff changeset
596 #else /* ! __LIBGCC_INIT_SECTION_ASM_OP__ && ! HAS_INIT_SECTION */
kono
parents:
diff changeset
597 #error "What are you doing with crtstuff.c, then?"
kono
parents:
diff changeset
598 #endif
kono
parents:
diff changeset
599
kono
parents:
diff changeset
600 #elif defined(CRT_END) /* ! CRT_BEGIN */
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 /* No need for .ctors/.dtors section if linker can place them in
kono
parents:
diff changeset
603 .init_array/.fini_array section. */
kono
parents:
diff changeset
604 #ifndef USE_INITFINI_ARRAY
kono
parents:
diff changeset
605 /* Put a word containing zero at the end of each of our two lists of function
kono
parents:
diff changeset
606 addresses. Note that the words defined here go into the .ctors and .dtors
kono
parents:
diff changeset
607 sections of the crtend.o file, and since that file is always linked in
kono
parents:
diff changeset
608 last, these words naturally end up at the very ends of the two lists
kono
parents:
diff changeset
609 contained in these two sections. */
kono
parents:
diff changeset
610
kono
parents:
diff changeset
611 #ifdef CTOR_LIST_END
kono
parents:
diff changeset
612 CTOR_LIST_END;
kono
parents:
diff changeset
613 #elif defined(__LIBGCC_CTORS_SECTION_ASM_OP__)
kono
parents:
diff changeset
614 /* Hack: force cc1 to switch to .data section early, so that assembling
kono
parents:
diff changeset
615 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */
kono
parents:
diff changeset
616 static func_ptr force_to_data[1] __attribute__ ((__used__)) = { };
kono
parents:
diff changeset
617 asm (__LIBGCC_CTORS_SECTION_ASM_OP__);
kono
parents:
diff changeset
618 STATIC func_ptr __CTOR_END__[1]
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
619 __attribute__((aligned(__alignof__(func_ptr))))
111
kono
parents:
diff changeset
620 = { (func_ptr) 0 };
kono
parents:
diff changeset
621 #else
kono
parents:
diff changeset
622 STATIC func_ptr __CTOR_END__[1]
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
623 __attribute__((section(".ctors"), aligned(__alignof__(func_ptr))))
111
kono
parents:
diff changeset
624 = { (func_ptr) 0 };
kono
parents:
diff changeset
625 #endif
kono
parents:
diff changeset
626
kono
parents:
diff changeset
627 #ifdef DTOR_LIST_END
kono
parents:
diff changeset
628 DTOR_LIST_END;
kono
parents:
diff changeset
629 #elif defined(HIDDEN_DTOR_LIST_END)
kono
parents:
diff changeset
630 #ifdef __LIBGCC_DTORS_SECTION_ASM_OP__
kono
parents:
diff changeset
631 asm (__LIBGCC_DTORS_SECTION_ASM_OP__);
kono
parents:
diff changeset
632 #endif
kono
parents:
diff changeset
633 func_ptr __DTOR_END__[1]
kono
parents:
diff changeset
634 __attribute__ ((used,
kono
parents:
diff changeset
635 #ifndef __LIBGCC_DTORS_SECTION_ASM_OP__
kono
parents:
diff changeset
636 section(".dtors"),
kono
parents:
diff changeset
637 #endif
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
638 aligned(__alignof__(func_ptr)), visibility ("hidden")))
111
kono
parents:
diff changeset
639 = { (func_ptr) 0 };
kono
parents:
diff changeset
640 #elif defined(__LIBGCC_DTORS_SECTION_ASM_OP__)
kono
parents:
diff changeset
641 asm (__LIBGCC_DTORS_SECTION_ASM_OP__);
kono
parents:
diff changeset
642 STATIC func_ptr __DTOR_END__[1]
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
643 __attribute__ ((used, aligned(__alignof__(func_ptr))))
111
kono
parents:
diff changeset
644 = { (func_ptr) 0 };
kono
parents:
diff changeset
645 #else
kono
parents:
diff changeset
646 STATIC func_ptr __DTOR_END__[1]
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
647 __attribute__((used, section(".dtors"), aligned(__alignof__(func_ptr))))
111
kono
parents:
diff changeset
648 = { (func_ptr) 0 };
kono
parents:
diff changeset
649 #endif
kono
parents:
diff changeset
650 #endif /* USE_INITFINI_ARRAY */
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 #ifdef __LIBGCC_EH_FRAME_SECTION_NAME__
kono
parents:
diff changeset
653 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
kono
parents:
diff changeset
654 this would be the 'length' field in a real FDE. */
kono
parents:
diff changeset
655 # if __INT_MAX__ == 2147483647
kono
parents:
diff changeset
656 typedef int int32;
kono
parents:
diff changeset
657 # elif __LONG_MAX__ == 2147483647
kono
parents:
diff changeset
658 typedef long int32;
kono
parents:
diff changeset
659 # elif __SHRT_MAX__ == 2147483647
kono
parents:
diff changeset
660 typedef short int32;
kono
parents:
diff changeset
661 # else
kono
parents:
diff changeset
662 # error "Missing a 4 byte integer"
kono
parents:
diff changeset
663 # endif
kono
parents:
diff changeset
664 STATIC EH_FRAME_SECTION_CONST int32 __FRAME_END__[]
kono
parents:
diff changeset
665 __attribute__ ((used, section(__LIBGCC_EH_FRAME_SECTION_NAME__),
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
666 aligned(__alignof__(int32))))
111
kono
parents:
diff changeset
667 = { 0 };
kono
parents:
diff changeset
668 #endif /* __LIBGCC_EH_FRAME_SECTION_NAME__ */
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 #if USE_TM_CLONE_REGISTRY
kono
parents:
diff changeset
671 # ifndef HAVE_GAS_HIDDEN
kono
parents:
diff changeset
672 static
kono
parents:
diff changeset
673 # endif
kono
parents:
diff changeset
674 func_ptr __TMC_END__[]
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
675 __attribute__((used, section(".tm_clone_table"),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
676 aligned(__alignof__(void *))))
111
kono
parents:
diff changeset
677 # ifdef HAVE_GAS_HIDDEN
kono
parents:
diff changeset
678 __attribute__((__visibility__ ("hidden"))) = { };
kono
parents:
diff changeset
679 # else
kono
parents:
diff changeset
680 = { 0, 0 };
kono
parents:
diff changeset
681 # endif
kono
parents:
diff changeset
682 #endif /* USE_TM_CLONE_REGISTRY */
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 #ifdef __LIBGCC_INIT_ARRAY_SECTION_ASM_OP__
kono
parents:
diff changeset
685
kono
parents:
diff changeset
686 /* If we are using .init_array, there is nothing to do. */
kono
parents:
diff changeset
687
kono
parents:
diff changeset
688 #elif defined(__LIBGCC_INIT_SECTION_ASM_OP__)
kono
parents:
diff changeset
689
kono
parents:
diff changeset
690 #ifdef OBJECT_FORMAT_ELF
kono
parents:
diff changeset
691 static void __attribute__((used))
kono
parents:
diff changeset
692 __do_global_ctors_aux (void)
kono
parents:
diff changeset
693 {
kono
parents:
diff changeset
694 func_ptr *p;
kono
parents:
diff changeset
695 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
kono
parents:
diff changeset
696 (*p) ();
kono
parents:
diff changeset
697 }
kono
parents:
diff changeset
698
kono
parents:
diff changeset
699 /* Stick a call to __do_global_ctors_aux into the .init section. */
kono
parents:
diff changeset
700 CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, __do_global_ctors_aux)
kono
parents:
diff changeset
701 #else /* OBJECT_FORMAT_ELF */
kono
parents:
diff changeset
702
kono
parents:
diff changeset
703 /* Stick the real initialization code, followed by a normal sort of
kono
parents:
diff changeset
704 function epilogue at the very end of the .init section for this
kono
parents:
diff changeset
705 entire root executable file or for this entire shared library file.
kono
parents:
diff changeset
706
kono
parents:
diff changeset
707 Note that we use some tricks here to get *just* the body and just
kono
parents:
diff changeset
708 a function epilogue (but no function prologue) into the .init
kono
parents:
diff changeset
709 section of the crtend.o file. Specifically, we switch to the .text
kono
parents:
diff changeset
710 section, start to define a function, and then we switch to the .init
kono
parents:
diff changeset
711 section just before the body code.
kono
parents:
diff changeset
712
kono
parents:
diff changeset
713 Earlier on, we put the corresponding function prologue into the .init
kono
parents:
diff changeset
714 section of the crtbegin.o file (which will be linked in first).
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 Note that we want to invoke all constructors for C++ file-scope static-
kono
parents:
diff changeset
717 storage objects AFTER any other possible initialization actions which
kono
parents:
diff changeset
718 may be performed by the code in the .init section contributions made by
kono
parents:
diff changeset
719 other libraries, etc. That's because those other initializations may
kono
parents:
diff changeset
720 include setup operations for very primitive things (e.g. initializing
kono
parents:
diff changeset
721 the state of the floating-point coprocessor, etc.) which should be done
kono
parents:
diff changeset
722 before we start to execute any of the user's code. */
kono
parents:
diff changeset
723
kono
parents:
diff changeset
724 static void
kono
parents:
diff changeset
725 __do_global_ctors_aux (void) /* prologue goes in .text section */
kono
parents:
diff changeset
726 {
kono
parents:
diff changeset
727 asm (__LIBGCC_INIT_SECTION_ASM_OP__);
kono
parents:
diff changeset
728 DO_GLOBAL_CTORS_BODY;
kono
parents:
diff changeset
729 atexit (__do_global_dtors);
kono
parents:
diff changeset
730 } /* epilogue and body go in .init section */
kono
parents:
diff changeset
731
kono
parents:
diff changeset
732 FORCE_CODE_SECTION_ALIGN
kono
parents:
diff changeset
733 asm (__LIBGCC_TEXT_SECTION_ASM_OP__);
kono
parents:
diff changeset
734
kono
parents:
diff changeset
735 #endif /* OBJECT_FORMAT_ELF */
kono
parents:
diff changeset
736
kono
parents:
diff changeset
737 #elif defined(HAS_INIT_SECTION) /* ! __LIBGCC_INIT_SECTION_ASM_OP__ */
kono
parents:
diff changeset
738
kono
parents:
diff changeset
739 extern void __do_global_ctors (void);
kono
parents:
diff changeset
740
kono
parents:
diff changeset
741 /* This case is used by the Irix 6 port, which supports named sections but
kono
parents:
diff changeset
742 not an SVR4-style .init section. __do_global_ctors can be non-static
kono
parents:
diff changeset
743 in this case because we protect it with -hidden_symbol. */
kono
parents:
diff changeset
744 void
kono
parents:
diff changeset
745 __do_global_ctors (void)
kono
parents:
diff changeset
746 {
kono
parents:
diff changeset
747 func_ptr *p;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
748 #if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY
111
kono
parents:
diff changeset
749 __do_global_ctors_1();
kono
parents:
diff changeset
750 #endif
kono
parents:
diff changeset
751 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
kono
parents:
diff changeset
752 (*p) ();
kono
parents:
diff changeset
753 }
kono
parents:
diff changeset
754
kono
parents:
diff changeset
755 #else /* ! __LIBGCC_INIT_SECTION_ASM_OP__ && ! HAS_INIT_SECTION */
kono
parents:
diff changeset
756 #error "What are you doing with crtstuff.c, then?"
kono
parents:
diff changeset
757 #endif
kono
parents:
diff changeset
758
kono
parents:
diff changeset
759 #else /* ! CRT_BEGIN && ! CRT_END */
kono
parents:
diff changeset
760 #error "One of CRT_BEGIN or CRT_END must be defined."
kono
parents:
diff changeset
761 #endif