xref: /netbsd-src/external/gpl3/gcc.old/dist/libgcc/config/vxcrtstuff.c (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1*4c3eb207Smrg /* This file is part of GCC.
2*4c3eb207Smrg 
3*4c3eb207Smrg GCC is free software; you can redistribute it and/or modify it under
4*4c3eb207Smrg the terms of the GNU General Public License as published by the Free
5*4c3eb207Smrg Software Foundation; either version 3, or (at your option) any later
6*4c3eb207Smrg version.
7*4c3eb207Smrg 
8*4c3eb207Smrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
9*4c3eb207Smrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
10*4c3eb207Smrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11*4c3eb207Smrg for more details.
12*4c3eb207Smrg 
13*4c3eb207Smrg Under Section 7 of GPL version 3, you are granted additional
14*4c3eb207Smrg permissions described in the GCC Runtime Library Exception, version
15*4c3eb207Smrg 3.1, as published by the Free Software Foundation.
16*4c3eb207Smrg 
17*4c3eb207Smrg You should have received a copy of the GNU General Public License and
18*4c3eb207Smrg a copy of the GCC Runtime Library Exception along with this program;
19*4c3eb207Smrg see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
20*4c3eb207Smrg <http://www.gnu.org/licenses/>.  */
21*4c3eb207Smrg 
22*4c3eb207Smrg /* The essential point of the crtbegin/crtend files on VxWorks is to handle
23*4c3eb207Smrg    the eh frames registration thanks to dedicated constructors and
24*4c3eb207Smrg    destructors.  What needs to be done depends on the VxWorks version and the
25*4c3eb207Smrg    kind of module (rtp, dkm, ...) one is building.  */
26*4c3eb207Smrg 
27*4c3eb207Smrg #define IN_LIBGCC2
28*4c3eb207Smrg 
29*4c3eb207Smrg #include "auto-host.h"
30*4c3eb207Smrg #include "tconfig.h"
31*4c3eb207Smrg #include "tsystem.h"
32*4c3eb207Smrg #include "coretypes.h"
33*4c3eb207Smrg #include "tm.h"
34*4c3eb207Smrg #include "libgcc_tm.h"
35*4c3eb207Smrg #include "unwind-dw2-fde.h"
36*4c3eb207Smrg 
37*4c3eb207Smrg /* If we are entitled/requested to use init/fini arrays, we'll rely on that.
38*4c3eb207Smrg    Otherwise, we may rely on ctors/dtors sections for RTPs or expect munch to
39*4c3eb207Smrg    be involved for kernel modules.  */
40*4c3eb207Smrg 
41*4c3eb207Smrg #if !defined(USE_INITFINI_ARRAY) && defined(__RTP__)
42*4c3eb207Smrg #define USE_CDTORS_SECTIONS
43*4c3eb207Smrg #endif
44*4c3eb207Smrg 
45*4c3eb207Smrg /*  ------------------------------ crtbegin -------------------------------  */
46*4c3eb207Smrg 
47*4c3eb207Smrg #ifdef CRT_BEGIN
48*4c3eb207Smrg 
49*4c3eb207Smrg /* Stick a label at the beginning of the frame unwind info so we can register
50*4c3eb207Smrg    and deregister it with the exception handling library code.  */
51*4c3eb207Smrg static const char __EH_FRAME_BEGIN__[]
52*4c3eb207Smrg __attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4)))
53*4c3eb207Smrg   = { };
54*4c3eb207Smrg 
55*4c3eb207Smrg /* Determine what names to use for the constructor/destructor functions.  */
56*4c3eb207Smrg 
57*4c3eb207Smrg #if defined(USE_CDTORS_SECTIONS) || defined(USE_INITFINI_ARRAY)
58*4c3eb207Smrg 
59*4c3eb207Smrg #define EH_CTOR_NAME _crtbe_register_frame
60*4c3eb207Smrg #define EH_DTOR_NAME _ctrbe_deregister_frame
61*4c3eb207Smrg 
62*4c3eb207Smrg #else
63*4c3eb207Smrg 
64*4c3eb207Smrg /* No specific sections for constructors or destructors: we thus use a
65*4c3eb207Smrg    symbol naming convention so that the constructors are then recognized
66*4c3eb207Smrg    by munch or whatever tool is used for the final link phase.  */
67*4c3eb207Smrg #define EH_CTOR_NAME _GLOBAL__I_00101_0__crtbe_register_frame
68*4c3eb207Smrg #define EH_DTOR_NAME _GLOBAL__D_00101_1__crtbe_deregister_frame
69*4c3eb207Smrg 
70*4c3eb207Smrg #endif
71*4c3eb207Smrg 
72*4c3eb207Smrg #ifdef USE_INITFINI_ARRAY
73*4c3eb207Smrg /* .init_array and .fini_array is supported starting VxWorks 7.2 in all
74*4c3eb207Smrg    cases. The compiler is then configured to always support priorities in
75*4c3eb207Smrg    constructors, so we can rely on the constructor and destructor attributes
76*4c3eb207Smrg    to generate the proper sections.  */
77*4c3eb207Smrg #define EH_CTOR_ATTRIBUTE __attribute__((constructor (101)))
78*4c3eb207Smrg #define EH_DTOR_ATTRIBUTE __attribute__((destructor (101)))
79*4c3eb207Smrg 
80*4c3eb207Smrg #else /* !USE_INITFINI_ARRAY  */
81*4c3eb207Smrg 
82*4c3eb207Smrg /* Note: Even in case of .ctors/.dtors sections, we can't use the attribute
83*4c3eb207Smrg    (constructor (15)) here as gcc may have been configured with constructors
84*4c3eb207Smrg    priority disabled.  We will instead craft an explicit section name for this
85*4c3eb207Smrg    purpose.  */
86*4c3eb207Smrg #define EH_CTOR_ATTRIBUTE
87*4c3eb207Smrg #define EH_DTOR_ATTRIBUTE
88*4c3eb207Smrg 
89*4c3eb207Smrg #endif /* USE_INITFINI_ARRAY  */
90*4c3eb207Smrg 
91*4c3eb207Smrg void EH_CTOR_NAME (void);
92*4c3eb207Smrg void EH_DTOR_NAME (void);
93*4c3eb207Smrg 
EH_CTOR_NAME(void)94*4c3eb207Smrg EH_CTOR_ATTRIBUTE void EH_CTOR_NAME (void)
95*4c3eb207Smrg {
96*4c3eb207Smrg   static struct object object;
97*4c3eb207Smrg   __register_frame_info (__EH_FRAME_BEGIN__, &object);
98*4c3eb207Smrg }
99*4c3eb207Smrg 
EH_DTOR_NAME(void)100*4c3eb207Smrg EH_DTOR_ATTRIBUTE void EH_DTOR_NAME (void)
101*4c3eb207Smrg {
102*4c3eb207Smrg   __deregister_frame_info (__EH_FRAME_BEGIN__);
103*4c3eb207Smrg }
104*4c3eb207Smrg 
105*4c3eb207Smrg #ifdef USE_CDTORS_SECTIONS
106*4c3eb207Smrg /* As explained above, we need to manually build the sections here as the
107*4c3eb207Smrg    compiler may not have support for constructors priority enabled.  */
108*4c3eb207Smrg static void (* volatile eh_registration_ctors[])()
109*4c3eb207Smrg   __attribute__((section (".ctors.101")))
110*4c3eb207Smrg = { &EH_CTOR_NAME };
111*4c3eb207Smrg static void (* volatile eh_registration_dtors[])()
112*4c3eb207Smrg   __attribute__((section (".dtors.65434")))
113*4c3eb207Smrg = { &EH_DTOR_NAME };
114*4c3eb207Smrg #endif
115*4c3eb207Smrg 
116*4c3eb207Smrg /*  ------------------------------ crtend ---------------------------------  */
117*4c3eb207Smrg 
118*4c3eb207Smrg #elif defined (CRT_END) /* ! CRT_BEGIN */
119*4c3eb207Smrg 
120*4c3eb207Smrg /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
121*4c3eb207Smrg    this would be the 'length' field in a real FDE.  */
122*4c3eb207Smrg 
123*4c3eb207Smrg static const char __FRAME_END__[]
124*4c3eb207Smrg      __attribute__ ((used, section(__LIBGCC_EH_FRAME_SECTION_NAME__),
125*4c3eb207Smrg 		     aligned(4)))
126*4c3eb207Smrg   = { 0, 0, 0, 0 };
127*4c3eb207Smrg 
128*4c3eb207Smrg #else /* ! CRT_BEGIN & ! CRT_END */
129*4c3eb207Smrg 
130*4c3eb207Smrg #error "One of CRT_BEGIN or CRT_END must be defined."
131*4c3eb207Smrg 
132*4c3eb207Smrg #endif
133