xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/config/vxworks.h (revision 8e33eff89e26cf71871ead62f0d5063e1313c33a)
1 /* Common VxWorks target definitions for GNU compiler.
2    Copyright (C) 1999-2020 Free Software Foundation, Inc.
3    Contributed by Wind River Systems.
4    Rewritten by CodeSourcery, LLC.
5 
6 This file is part of GCC.
7 
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12 
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21 
22 /* Assert that we are targeting VxWorks.  */
23 #undef TARGET_VXWORKS
24 #define TARGET_VXWORKS 1
25 
26 /* In kernel mode, VxWorks provides all the libraries itself, as well as
27    the functionality of startup files, etc.  In RTP mode, it behaves more
28    like a traditional Unix, with more external files.  Most of our specs
29    must be aware of the difference.  */
30 
31 /* We look for the VxWorks header files using the environment
32    variables that are set in VxWorks to indicate the location of the
33    system header files.  We use -idirafter so that the GCC's own
34    header-file directories (containing <stddef.h>, etc.) come before
35    the VxWorks system header directories.  */
36 
37 /* Since we provide a default -isystem, expand -isystem on the command
38    line early.  */
39 #if TARGET_VXWORKS7
40 
41 #undef VXWORKS_ADDITIONAL_CPP_SPEC
42 #define VXWORKS_ADDITIONAL_CPP_SPEC                     \
43  "%{!nostdinc:                                          \
44     %{isystem*}                                         \
45     %{mrtp: -idirafter %:getenv(VSB_DIR /h)             \
46             -idirafter %:getenv(VSB_DIR /share/h)       \
47             -idirafter %:getenv(VSB_DIR /usr/h/public)  \
48             -idirafter %:getenv(VSB_DIR /usr/h)         \
49       ;:    -idirafter %:getenv(VSB_DIR /h)             \
50             -idirafter %:getenv(VSB_DIR /share/h)       \
51             -idirafter %:getenv(VSB_DIR /krnl/h/system) \
52             -idirafter %:getenv(VSB_DIR /krnl/h/public)}}"
53 
54 #else /* TARGET_VXWORKS7 */
55 
56 #undef VXWORKS_ADDITIONAL_CPP_SPEC
57 #define VXWORKS_ADDITIONAL_CPP_SPEC		\
58  "%{!nostdinc:					\
59     %{isystem*}					\
60     %{mrtp: -idirafter %:getenv(WIND_USR /h)	\
61 	    -idirafter %:getenv(WIND_USR /h/wrn/coreip) \
62       ;:    -idirafter %:getenv(WIND_BASE /target/h) \
63 	    -idirafter %:getenv(WIND_BASE /target/h/wrn/coreip) \
64 }}"
65 
66 #endif
67 
68 /* For VxWorks static rtps, the system provides libc_internal.a, a superset of
69    libgcc.a that we need to use e.g. to satisfy references to __init and
70    __fini.  We still want our libgcc to prevail for symbols it would provide
71    (e.g. register save entry points), so re-place it here between libraries
72    that might reference it and libc_internal.
73 
74    In addition, some versions of VxWorks rely on explicit extra libraries for
75    system calls and the set of base network libraries of common use varies
76    across architectures.  The default settings defined here might be redefined
77    by target specific port configuration files.  */
78 
79 #define VXWORKS_SYSCALL_LIBS_RTP
80 
81 #if TARGET_VXWORKS7
82 #define VXWORKS_NET_LIBS_RTP "-lnet"
83 #else
84 #define VXWORKS_NET_LIBS_RTP "-lnet -ldsi"
85 #endif
86 
87 #define VXWORKS_BASE_LIBS_RTP "-lc -lgcc -lc_internal"
88 
89 #define VXWORKS_EXTRA_LIBS_RTP
90 
91 #define VXWORKS_LIBS_RTP \
92   VXWORKS_SYSCALL_LIBS_RTP " " VXWORKS_NET_LIBS_RTP " " \
93   VXWORKS_BASE_LIBS_RTP " " VXWORKS_EXTRA_LIBS_RTP
94 
95 /* TLS configuration.  VxWorks 7 now always has proper TLS support.
96    Earlier versions did not, not even for RTPS.  */
97 #define VXWORKS_HAVE_TLS TARGET_VXWORKS7
98 
99 /* On Vx6 and previous, the libraries to pick up depends on the architecture,
100    so cannot be defined for all archs at once.  On Vx7, a VSB is always needed
101    and its structure is fixed and does not depend on the arch.  We can thus
102    tell gcc where to look for when linking with RTP libraries.  Use
103    STARTFILE_PREFIX_SPEC for this, instead of explicit -L options in LIB_SPEC,
104    so they survive -nodefaultlibs.  */
105 
106 /* On Vx7 RTP, we need to drag the __tls__ symbol to trigger initialization of
107    tlsLib, responsible for TLS support by the OS.  */
108 
109 #if TARGET_VXWORKS7
110 #undef  STARTFILE_PREFIX_SPEC
111 #define STARTFILE_PREFIX_SPEC "%:getenv(VSB_DIR /usr/lib/common)"
112 #define TLS_SYM "-u __tls__"
113 #else
114 #define TLS_SYM ""
115 #endif
116 
117 #undef VXWORKS_LIB_SPEC
118 #define	VXWORKS_LIB_SPEC						\
119 "%{mrtp:%{shared:-u " USER_LABEL_PREFIX "__init -u " USER_LABEL_PREFIX "__fini} \
120 	%{!shared:%{non-static:-u " USER_LABEL_PREFIX "_STI__6__rtld -ldl} \
121 		  " TLS_SYM " \
122 		  --start-group " VXWORKS_LIBS_RTP " --end-group}}"
123 
124 /* The no-op spec for "-shared" below is present because otherwise GCC
125    will treat it as an unrecognized option.  */
126 #undef VXWORKS_LINK_SPEC
127 #define VXWORKS_LINK_SPEC				\
128 "%{!mrtp:-r}						\
129  %{!shared:						\
130    %{mrtp:-q %{h*}					\
131           %{R*} %{!T*: %(link_start) }			\
132           %(link_target) %(link_os)}}			\
133  %{v:-v}						\
134  %{shared:-shared}					\
135  %{Bstatic:-Bstatic}					\
136  %{Bdynamic:-Bdynamic}					\
137  %{!Xbind-lazy:-z now}					\
138  %{Xbind-now:%{Xbind-lazy:				\
139    %e-Xbind-now and -Xbind-lazy are incompatible}}	\
140  %{mrtp:%{!shared:%{!non-static:-static}		\
141  		  %{non-static:--force-dynamic --export-dynamic}}}"
142 
143 #undef VXWORKS_LIBGCC_SPEC
144 #define VXWORKS_LIBGCC_SPEC "-lgcc"
145 
146 /* Setup the crtstuff begin/end we might need for dwarf EH registration.  */
147 
148 #if !defined(CONFIG_SJLJ_EXCEPTIONS) && DWARF2_UNWIND_INFO
149 #define VX_CRTBEGIN_SPEC \
150  "%{!mrtp:vx_crtbegin-kernel.o%s} %{mrtp:vx_crtbegin-rtp.o%s}"
151 #define VX_CRTEND_SPEC "-l:vx_crtend.o"
152 #else
153 #define VX_CRTBEGIN_SPEC ""
154 #define VX_CRTEND_SPEC ""
155 #endif
156 
157 #undef VXWORKS_STARTFILE_SPEC
158 #define VXWORKS_STARTFILE_SPEC \
159   VX_CRTBEGIN_SPEC " %{mrtp:%{!shared:-l:crt0.o}}"
160 
161 #undef VXWORKS_ENDFILE_SPEC
162 #define VXWORKS_ENDFILE_SPEC VX_CRTEND_SPEC
163 
164 #undef  VXWORKS_CC1_SPEC
165 #if TARGET_VXWORKS7
166 #define VXWORKS_CC1_SPEC \
167   "%(cc1_cpu) %{!mrtp:%{!ftls-model=*:-ftls-model=local-exec}}"
168 #else
169 #define VXWORKS_CC1_SPEC ""
170 #endif
171 
172 /* Do VxWorks-specific parts of TARGET_OPTION_OVERRIDE.  */
173 #undef VXWORKS_OVERRIDE_OPTIONS
174 #define VXWORKS_OVERRIDE_OPTIONS vxworks_override_options ()
175 extern void vxworks_override_options (void);
176 
177 /* Whether the VxWorks variant and mode supports constructors/destructors
178    placed in .ctors/.dtors section or if we should generate proxy functions
179    for them, with special names which munch knows how to collect.  On most
180    versions of VxWorks, only the RTP loader supports .ctors/.dtors sections,
181    not the kernel module loader.  */
182 #define TARGET_VXWORKS_HAVE_CTORS_DTORS TARGET_VXWORKS_RTP
183 
184 /* Support for prioritized ctors/dtors is in sync with the support for sections
185    on the VxWorks front, and is assumed to be provided by whatever linker level
186    glue is required if we were configured with --enable-initfini-array.  */
187 #define SUPPORTS_INIT_PRIORITY \
188   (TARGET_VXWORKS_HAVE_CTORS_DTORS || HAVE_INITFINI_ARRAY_SUPPORT)
189 
190 #if !HAVE_INITFINI_ARRAY_SUPPORT
191 /* VxWorks requires special handling of constructors and destructors.
192    All VxWorks configurations must use these functions.  */
193 #undef TARGET_ASM_CONSTRUCTOR
194 #define TARGET_ASM_CONSTRUCTOR vxworks_asm_out_constructor
195 #undef TARGET_ASM_DESTRUCTOR
196 #define TARGET_ASM_DESTRUCTOR vxworks_asm_out_destructor
197 extern void vxworks_asm_out_constructor (rtx symbol, int priority);
198 extern void vxworks_asm_out_destructor (rtx symbol, int priority);
199 #endif
200 
201 /* Override the vxworks-dummy.h definitions.  TARGET_VXWORKS_RTP
202    is defined by vxworks.opt.  */
203 #undef VXWORKS_GOTT_BASE
204 #define VXWORKS_GOTT_BASE "__GOTT_BASE__"
205 #undef VXWORKS_GOTT_INDEX
206 #define VXWORKS_GOTT_INDEX "__GOTT_INDEX__"
207 
208 #undef PTRDIFF_TYPE
209 #define PTRDIFF_TYPE (TARGET_VXWORKS64 ? "long int" : "int")
210 
211 #undef SIZE_TYPE
212 #define SIZE_TYPE (TARGET_VXWORKS64 ? "long unsigned int" : "unsigned int")
213 
214 /* Assumptions on the target libc.  VxWorks 7, post SR600, provides a C11
215    runtime without sincos support.  */
216 #undef TARGET_LIBC_HAS_FUNCTION
217 #define TARGET_LIBC_HAS_FUNCTION \
218   (TARGET_VXWORKS7 ? default_libc_has_function : no_c99_libc_has_function)
219 
220 /* Both kernels and RTPs have the facilities required by this macro.  */
221 #define TARGET_POSIX_IO
222 
223 /* A VxWorks implementation of TARGET_OS_CPP_BUILTINS.  */
224 
225 /* The VxWorks personality we rely on, controlling which sections of system
226    headers files we trigger.  This might be redefined on targets where the
227    base VxWorks environment doesn't come with a GNU toolchain.  */
228 
229 #define VXWORKS_PERSONALITY "gnu"
230 
231 #define VXWORKS_OS_CPP_BUILTINS()					\
232   do									\
233     {									\
234       builtin_define ("__vxworks");					\
235       builtin_define ("__VXWORKS__");					\
236       builtin_assert ("system=unix");					\
237       if (TARGET_VXWORKS_RTP)						\
238 	builtin_define ("__RTP__");					\
239       else								\
240 	builtin_define ("_WRS_KERNEL");					\
241       builtin_define ("TOOL_FAMILY=" VXWORKS_PERSONALITY);		\
242       builtin_define ("TOOL=" VXWORKS_PERSONALITY);			\
243       if (TARGET_VXWORKS7)						\
244         {								\
245            builtin_define ("_VSB_CONFIG_FILE=<config/vsbConfig.h>");	\
246            								\
247 	   /* _ALLOW_KEYWORD_MACROS is needed on VxWorks 7 to		\
248 	      prevent compilation failures triggered by our		\
249 	      definition of "inline" in ansidecl when "inline"		\
250 	      is not a keyword.  */					\
251 	   if (!flag_isoc99 && !c_dialect_cxx())			\
252              builtin_define ("_ALLOW_KEYWORD_MACROS");			\
253         }								\
254     }									\
255   while (0)
256 
257 #define VXWORKS_KIND VXWORKS_KIND_NORMAL
258 
259 /* The diab linker does not handle .gnu_attribute sections.  */
260 #undef HAVE_AS_GNU_ATTRIBUTE
261 
262 /* We provide our own version of __clear_cache in libgcc, using a separate C
263    file to facilitate #inclusion of VxWorks header files.  */
264 #undef CLEAR_INSN_CACHE
265 #define CLEAR_INSN_CACHE 1
266 
267 /* Default dwarf control values, for non-gdb debuggers that come with
268    VxWorks.  */
269 
270 #undef VXWORKS_DWARF_VERSION_DEFAULT
271 #define VXWORKS_DWARF_VERSION_DEFAULT (TARGET_VXWORKS7 ? 4 : 2)
272 
273 #undef DWARF_GNAT_ENCODINGS_DEFAULT
274 #define DWARF_GNAT_ENCODINGS_DEFAULT \
275   (TARGET_VXWORKS7 ? DWARF_GNAT_ENCODINGS_MINIMAL : DWARF_GNAT_ENCODINGS_ALL)
276