ada: Fix internal error on 'Address of task component
[official-gcc.git] / libgcc / config / vxcrtstuff.c
blob5045acfc6da17a80f2889433f76869be48961679
1 /* This file is part of GCC.
3 GCC is free software; you can redistribute it and/or modify it under
4 the terms of the GNU General Public License as published by the Free
5 Software Foundation; either version 3, or (at your option) any later
6 version.
8 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
9 WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 for more details.
13 Under Section 7 of GPL version 3, you are granted additional
14 permissions described in the GCC Runtime Library Exception, version
15 3.1, as published by the Free Software Foundation.
17 You should have received a copy of the GNU General Public License and
18 a copy of the GCC Runtime Library Exception along with this program;
19 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
20 <http://www.gnu.org/licenses/>. */
22 /* The essential point of the crtbegin/crtend files on VxWorks is to handle
23 the eh frames registration thanks to dedicated constructors and
24 destructors. What needs to be done depends on the VxWorks version and the
25 kind of module (rtp, dkm, ...) one is building. */
27 #define IN_LIBGCC2
29 /* FIXME: Including auto-host is incorrect here (target library implementation
30 file), but we still need it for DEFAULT_USE_CXA_ATEXIT and most importantly
31 USE_INITFINI_ARRAY, guarded by HAVE_INITFINI_ARRAY_SUPPORT, not yet handled
32 by auto-target.h. Proceed as crtstuff.c, with the inclusion followed by a
33 few #undefs preventing build failures in configurations setup for Windows
34 hosts, including canadian builds. #define USED_FOR_TARGET would circumvent
35 this but would unfortunately also inhibit some of the definitions we
36 need. */
37 #include "auto-host.h"
38 #undef caddr_t
39 #undef pid_t
40 #undef rlim_t
41 #undef ssize_t
42 #undef vfork
44 #include "tconfig.h"
45 #include "tsystem.h"
46 #include "coretypes.h"
47 #include "tm.h"
48 #include "libgcc_tm.h"
49 #include "unwind-dw2-fde.h"
51 /* If we are entitled/requested to use init/fini arrays, we'll rely on that.
52 Otherwise, we may rely on ctors/dtors sections for RTPs or expect munch to
53 be involved for kernel modules. */
55 #if !defined(USE_INITFINI_ARRAY) && defined(__RTP__)
56 #define USE_CDTORS_SECTIONS
57 #endif
59 #if DWARF2_UNWIND_INFO && !defined(__USING_SJLJ_EXCEPTIONS__)
60 #define USE_EH_FRAME_REGISTRY
61 #endif
63 /* ------------------------------ crtbegin ------------------------------- */
65 #ifdef CRT_BEGIN
67 /* Provide __dso_handle in RTP objects, which might be included in contexts
68 involving shared objects. This mimics the crtstuff.c behavior: dso_handle
69 should be NULL for the main program (in vx_crtbegin.o) and a unique value
70 for the shared libraries (in vx_crtbeginS.o). */
72 #if DEFAULT_USE_CXA_ATEXIT && defined(__RTP__)
73 extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
74 #ifdef CRTSTUFFS_O
75 void *__dso_handle = &__dso_handle;
76 #else
77 void *__dso_handle = 0;
78 #endif
79 #endif
81 /* Determine what names to use for the constructor/destructor functions. */
83 #if defined(USE_CDTORS_SECTIONS) || defined(USE_INITFINI_ARRAY)
85 #define EH_CTOR_NAME _crtbe_register_frame
86 #define EH_DTOR_NAME _ctrbe_deregister_frame
87 #define EH_LINKAGE static
89 #else
91 /* No specific sections for constructors or destructors: we thus use a
92 symbol naming convention so that the constructors are then recognized
93 by munch or whatever tool is used for the final link phase. Since the
94 pointers to the constructor/destructor functions are not created in this
95 translation unit, they must have external linkage. */
96 #define EH_CTOR_NAME _GLOBAL__I_00101_0__crtbe_register_frame
97 #define EH_DTOR_NAME _GLOBAL__D_00101_1__crtbe_deregister_frame
98 #define EH_LINKAGE
100 #endif
102 #ifdef USE_INITFINI_ARRAY
103 /* .init_array and .fini_array is supported starting VxWorks 7.2 in all
104 cases. The compiler is then configured to always support priorities in
105 constructors, so we can rely on the constructor and destructor attributes
106 to generate the proper sections. */
107 #define EH_CTOR_ATTRIBUTE __attribute__((constructor (101)))
108 #define EH_DTOR_ATTRIBUTE __attribute__((destructor (101)))
110 /* Provide the init/fini array support functions for shared libraries,
111 where we don't want to drag libc_internal contents blindly and which
112 provides functions with a slightly different name anyway. */
114 #if defined(CRTSTUFFS_O)
116 /* Run through the .init_array, .fini_array sections. The linker script
117 *must* provide __init_array_start, __init_array_end, __fini_array_start,
118 __fini_array_end symbols. */
120 typedef void (*initfini_ptr) (void);
121 extern initfini_ptr __init_array_start[];
122 extern initfini_ptr __init_array_end[];
123 extern initfini_ptr __fini_array_start[];
124 extern initfini_ptr __fini_array_end[];
126 /* Provide the actual code through static functions, which don't need
127 to be exposed in the shared lib interface. */
129 static void __exec_init_array(void)
131 initfini_ptr *fn;
132 for (fn = __init_array_start; fn < __init_array_end; ++fn)
133 (*fn)();
136 static void __exec_fini_array(void)
138 initfini_ptr *fn;
139 for (fn = __fini_array_end - 1; fn >= __fini_array_start; --fn)
140 (*fn)();
143 /* Reference the two above functions as the init / fini function. */
145 void __attribute__ ((__section__ (".init"))) _init()
147 __exec_init_array();
150 void __attribute__ ((__section__ (".fini"))) _fini()
152 __exec_fini_array();
155 #endif /* __CRTSTUFFS_O__ */
157 #else /* !USE_INITFINI_ARRAY */
159 /* Note: Even in case of .ctors/.dtors sections, we can't use the attribute
160 (constructor (15)) here as gcc may have been configured with constructors
161 priority disabled. We will instead craft an explicit section name for this
162 purpose. */
163 #define EH_CTOR_ATTRIBUTE
164 #define EH_DTOR_ATTRIBUTE
166 #endif /* USE_INITFINI_ARRAY */
168 #ifdef USE_EH_FRAME_REGISTRY
169 /* Stick a label at the beginning of the frame unwind info so we can register
170 and deregister it with the exception handling library code. */
171 static const char __EH_FRAME_BEGIN__[]
172 __attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4)))
173 = { };
175 EH_LINKAGE EH_CTOR_ATTRIBUTE void EH_CTOR_NAME (void)
177 static struct object object;
178 __register_frame_info (__EH_FRAME_BEGIN__, &object);
181 EH_LINKAGE EH_DTOR_ATTRIBUTE void EH_DTOR_NAME (void)
183 __deregister_frame_info (__EH_FRAME_BEGIN__);
185 #endif /* USE_EH_FRAME_REGISTRY */
187 #ifdef USE_CDTORS_SECTIONS
188 /* As explained above, we need to manually build the sections here as the
189 compiler may not have support for constructors priority enabled. */
190 static void (* volatile eh_registration_ctors[])()
191 __attribute__((section (".ctors.101")))
192 = { &EH_CTOR_NAME };
193 static void (* volatile eh_registration_dtors[])()
194 __attribute__((section (".dtors.65434")))
195 = { &EH_DTOR_NAME };
196 #endif
198 /* ------------------------------ crtend --------------------------------- */
200 #elif defined (CRT_END) /* ! CRT_BEGIN */
202 #ifdef USE_EH_FRAME_REGISTRY
203 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
204 this would be the 'length' field in a real FDE. */
206 static const char __FRAME_END__[]
207 __attribute__ ((used, section(__LIBGCC_EH_FRAME_SECTION_NAME__),
208 aligned(4)))
209 = { 0, 0, 0, 0 };
210 #endif /* USE_EH_FRAME_REGISTRY */
212 #else /* ! CRT_BEGIN & ! CRT_END */
214 #error "One of CRT_BEGIN or CRT_END must be defined."
216 #endif