Enable GCC to support Intel Key Locker ISA
[official-gcc.git] / libgcc / config / vxcrtstuff.c
blob87fadda9ac50edcd34ebc545ba5b7ed9769c256c
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 #include "auto-host.h"
30 #include "tconfig.h"
31 #include "tsystem.h"
32 #include "coretypes.h"
33 #include "tm.h"
34 #include "libgcc_tm.h"
35 #include "unwind-dw2-fde.h"
37 /* If we are entitled/requested to use init/fini arrays, we'll rely on that.
38 Otherwise, we may rely on ctors/dtors sections for RTPs or expect munch to
39 be involved for kernel modules. */
41 #if !defined(USE_INITFINI_ARRAY) && defined(__RTP__)
42 #define USE_CDTORS_SECTIONS
43 #endif
45 /* ------------------------------ crtbegin ------------------------------- */
47 #ifdef CRT_BEGIN
49 /* Stick a label at the beginning of the frame unwind info so we can register
50 and deregister it with the exception handling library code. */
51 static const char __EH_FRAME_BEGIN__[]
52 __attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4)))
53 = { };
55 /* Determine what names to use for the constructor/destructor functions. */
57 #if defined(USE_CDTORS_SECTIONS) || defined(USE_INITFINI_ARRAY)
59 #define EH_CTOR_NAME _crtbe_register_frame
60 #define EH_DTOR_NAME _ctrbe_deregister_frame
62 #else
64 /* No specific sections for constructors or destructors: we thus use a
65 symbol naming convention so that the constructors are then recognized
66 by munch or whatever tool is used for the final link phase. */
67 #define EH_CTOR_NAME _GLOBAL__I_00101_0__crtbe_register_frame
68 #define EH_DTOR_NAME _GLOBAL__D_00101_1__crtbe_deregister_frame
70 #endif
72 #ifdef USE_INITFINI_ARRAY
73 /* .init_array and .fini_array is supported starting VxWorks 7.2 in all
74 cases. The compiler is then configured to always support priorities in
75 constructors, so we can rely on the constructor and destructor attributes
76 to generate the proper sections. */
77 #define EH_CTOR_ATTRIBUTE __attribute__((constructor (101)))
78 #define EH_DTOR_ATTRIBUTE __attribute__((destructor (101)))
80 #else /* !USE_INITFINI_ARRAY */
82 /* Note: Even in case of .ctors/.dtors sections, we can't use the attribute
83 (constructor (15)) here as gcc may have been configured with constructors
84 priority disabled. We will instead craft an explicit section name for this
85 purpose. */
86 #define EH_CTOR_ATTRIBUTE
87 #define EH_DTOR_ATTRIBUTE
89 #endif /* USE_INITFINI_ARRAY */
91 void EH_CTOR_NAME (void);
92 void EH_DTOR_NAME (void);
94 EH_CTOR_ATTRIBUTE void EH_CTOR_NAME (void)
96 static struct object object;
97 __register_frame_info (__EH_FRAME_BEGIN__, &object);
100 EH_DTOR_ATTRIBUTE void EH_DTOR_NAME (void)
102 __deregister_frame_info (__EH_FRAME_BEGIN__);
105 #ifdef USE_CDTORS_SECTIONS
106 /* As explained above, we need to manually build the sections here as the
107 compiler may not have support for constructors priority enabled. */
108 static void (* volatile eh_registration_ctors[])()
109 __attribute__((section (".ctors.101")))
110 = { &EH_CTOR_NAME };
111 static void (* volatile eh_registration_dtors[])()
112 __attribute__((section (".dtors.65434")))
113 = { &EH_DTOR_NAME };
114 #endif
116 /* ------------------------------ crtend --------------------------------- */
118 #elif defined (CRT_END) /* ! CRT_BEGIN */
120 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
121 this would be the 'length' field in a real FDE. */
123 static const char __FRAME_END__[]
124 __attribute__ ((used, section(__LIBGCC_EH_FRAME_SECTION_NAME__),
125 aligned(4)))
126 = { 0, 0, 0, 0 };
128 #else /* ! CRT_BEGIN & ! CRT_END */
130 #error "One of CRT_BEGIN or CRT_END must be defined."
132 #endif