]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/vxworks.h
Update copyright years.
[thirdparty/gcc.git] / gcc / config / vxworks.h
1 /* Common VxWorks target definitions for GNU compiler.
2 Copyright (C) 1999-2023 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 /* ??? We use HAVE_INITFINI_ARRAY_SUPPORT in preprocessor guards in this
23 header, which is conveyed by auto-host.h despite being a target property.
24 #include auto-host.h here would trigger lots of conflicts so we rely on
25 compiler .c files doing this before target configuration headers. */
26
27 /* Assert that we are targeting VxWorks. */
28 #undef TARGET_VXWORKS
29 #define TARGET_VXWORKS 1
30
31 /* ??? Even though assigned to a HOST driver hook, this function
32 operates for all vxworks targets regardless of the current host.
33 We will get warnings at build time if the macro happens to be
34 redefined one way or another for a host. */
35 struct cl_decoded_option;
36 extern void vxworks_driver_init (unsigned int *, struct cl_decoded_option **);
37
38 #define GCC_DRIVER_HOST_INITIALIZATION \
39 vxworks_driver_init (&decoded_options_count, &decoded_options)
40
41 /* In kernel mode, VxWorks provides all the libraries itself, as well as
42 the functionality of startup files, etc. In RTP mode, it behaves more
43 like a traditional Unix, with more external files. Most of our specs
44 must be aware of the difference. */
45
46 /* Help locate system headers, assuming $sysroot set to $VSB_DIR on vx7 and
47 $WIND_BASE/target prior to that. Specs allow tailoring for RTP vs kernel,
48 and -idirafter allows putting system directories after GCC's own directories
49 for standard headers such as <stddef.h> or fixed include.
50
51 Regarding fixed includes, note the effect of sysroot_headers_suffix_spec:
52
53 For the case of VxWorks prior to 7 below, we have:
54
55 #define SYSROOT_HEADERS_SUFFIX_SPEC "%{mrtp:/usr/h;:/h}"
56
57 This results in
58
59 $build_sysroot/h ---> $prefix/include-fixed
60 $build_sysroot/usr/h ---> $prefix/include-fixed/mrtp for -mrtp
61
62 This is very different from what we'd get without a headers_suffix,
63 which would be:
64
65 $build_sysroot ---> $prefix/include-fixed/h
66 /usr/h
67
68 From (say) #include <assert.h>, we would find the fixed version
69 in the first case, not in the second. */
70
71 /* Since we provide a default -isystem, expand -isystem on the command
72 line early. Then restrict the amount of references we add when compiling
73 self-tests, as these may be run in contexts where the VxWorks environment
74 isn't available. */
75
76 #if TARGET_VXWORKS7
77
78 /* We arrange not rely on fixed includes for vx7 and the headers spread over
79 common kernel/rtp directories in addition to specific ones for each mode.
80 Setup sysroot_headers_suffix_spec to deal with kernel/rtp distinction. */
81
82 #undef SYSROOT_HEADERS_SUFFIX_SPEC
83 #define SYSROOT_HEADERS_SUFFIX_SPEC "%{mrtp:/usr/h;:/krnl/h}"
84
85 #undef VXWORKS_ADDITIONAL_CPP_SPEC
86 #define VXWORKS_ADDITIONAL_CPP_SPEC \
87 "%{!nostdinc:%{!fself-test=*: \
88 %{isystem*} \
89 -idirafter %:getenv(VSB_DIR /h) \
90 -idirafter %:getenv(VSB_DIR /share/h) \
91 -idirafter =/system \
92 -idirafter =/public \
93 }}"
94
95 #else /* TARGET_VXWORKS7 */
96
97 /* Prior to vx7, rtp and kernel headers are fairly segregated and fixincludes
98 is needed on each set of headers to cope with expectations of not so old
99 libstdc++. A perfect use case for sysroot_headers_suffix. */
100
101 #undef SYSROOT_HEADERS_SUFFIX_SPEC
102 #define SYSROOT_HEADERS_SUFFIX_SPEC "%{mrtp:/usr/h;:/h}"
103
104 #undef VXWORKS_ADDITIONAL_CPP_SPEC
105 #define VXWORKS_ADDITIONAL_CPP_SPEC \
106 "%{!nostdinc:%{!fself-test=*: \
107 %{isystem*} \
108 -idirafter =/wrn/coreip \
109 }}"
110
111 #endif
112
113 /* Our ports rely on gnu-user.h, which #defines _POSIX_SOURCE for
114 C++ by default. VxWorks doesn't provide 100% of what this implies
115 (e.g. ::mkstemp), so, arrange to prevent that by falling back to
116 the default CPP spec for C++ as well. */
117 #undef CPLUSPLUS_CPP_SPEC
118
119 /* For VxWorks static rtps, the system provides libc_internal.a for a variety
120 of purposes. Care is needed to include it appropriately.
121
122 - In some configurations, libc_internal fills in possible references from
123 the static libc that we don't wouldn't satisfy ourselves, say, with
124 libgcc. An example is the __aeabi_memcpy family of functions on arm,
125 which have very specific ABI allowances.
126
127 - OTOH, in some configurations the library provides typical libgcc
128 services, for example register save/restore entry points on powerpc. We
129 want our libgcc to prevail for symbols it would provide, so place
130 -lc_internal after -lc -lgcc.
131
132 - libc_internal also contains __init/__fini functions for
133 INITFINI_ARRAY support. However, the system expects these in
134 every shared lib as well, with slightly different names, and it is
135 simpler for us to provide our own versions through vxcrtstuff.
136
137 In addition, some versions of VxWorks rely on explicit extra libraries for
138 system calls and the set of base network libraries of common use varies
139 across architectures. The default settings defined here might be redefined
140 by target specific port configuration files. */
141
142 #define VXWORKS_SYSCALL_LIBS_RTP
143
144 #if TARGET_VXWORKS7
145 #define VXWORKS_NET_LIBS_RTP "-l%:if-exists-then-else(%:getenv(VSB_DIR /usr/h/public/rtnetStackLib.h) rtnet net)"
146 #else
147 #define VXWORKS_NET_LIBS_RTP "-lnet -ldsi"
148 #endif
149
150 #define VXWORKS_BASE_LIBS_RTP "-lc -lgcc %{!shared:-lc_internal}"
151
152 #define VXWORKS_EXTRA_LIBS_RTP
153
154 #define VXWORKS_LIBS_RTP \
155 VXWORKS_SYSCALL_LIBS_RTP " " VXWORKS_NET_LIBS_RTP " " \
156 VXWORKS_BASE_LIBS_RTP " " VXWORKS_EXTRA_LIBS_RTP
157
158 /* TLS configuration. VxWorks 7 now always has proper TLS support.
159 Earlier versions did not, not even for RTPS. */
160 #define VXWORKS_HAVE_TLS TARGET_VXWORKS7
161
162 /* On Vx6 and previous, the libraries to pick up depends on the architecture,
163 so cannot be defined for all archs at once. On Vx7, a VSB is always needed
164 and its structure is fixed and does not depend on the arch. We can thus
165 tell gcc where to look for when linking with RTP libraries. Use
166 STARTFILE_PREFIX_SPEC for this, instead of explicit -L options in LIB_SPEC,
167 so they survive -nodefaultlibs. */
168
169 /* On Vx7 RTP, we need to drag the __tls__ symbol to trigger initialization of
170 tlsLib, responsible for TLS support by the OS. */
171
172 #if TARGET_VXWORKS7
173
174 /* For static links, /usr/lib/common has everything. For dynamic links,
175 /usr/lib/common/PIC has the static libs and objects that might be needed
176 in the closure (e.g. crt0.o), while the shared version of standard deps
177 (e.g. libc.so) are still in /usr/lib/common. */
178 #undef STARTFILE_PREFIX_SPEC
179 #define STARTFILE_PREFIX_SPEC \
180 "%{shared|non-static:/usr/lib/common/PIC} /usr/lib/common"
181
182 #define TLS_SYM "-u __tls__"
183
184 #else
185
186 #define TLS_SYM ""
187
188 #endif
189
190 #undef VXWORKS_LIB_SPEC
191 #define VXWORKS_LIB_SPEC \
192 "%{mrtp:%{!shared:%{non-static:-u " USER_LABEL_PREFIX "_STI__6__rtld -ldl} \
193 " TLS_SYM " \
194 --start-group " VXWORKS_LIBS_RTP " --end-group}}"
195
196 #if TARGET_VXWORKS7
197 #define VXWORKS_EXTRA_LINK_SPEC ""
198 #else
199 /* Older VxWorks RTPs can only link with shared libs, and
200 need special switches --force-dynamic --export-dynamic. */
201 #define VXWORKS_EXTRA_LINK_SPEC \
202 "%{mrtp:%{!shared:%{non-static:--force-dynamic --export-dynamic}}}"
203 #endif
204
205 /* A default link_os expansion for RTPs, that cpu ports may override. */
206 #undef VXWORKS_LINK_OS_SPEC
207 #define VXWORKS_LINK_OS_SPEC "%(link_os)"
208
209 /* The -B and -X switches are for DIAB based linking. */
210 #undef VXWORKS_BASE_LINK_SPEC
211 #define VXWORKS_BASE_LINK_SPEC \
212 "%{!mrtp:-r} \
213 %{v:-V} \
214 %{shared:-shared} \
215 %{Bstatic:-Bstatic} \
216 %{Bdynamic:-Bdynamic} \
217 %{!Xbind-lazy:-z now} \
218 %{Xbind-now:%{Xbind-lazy: \
219 %e-Xbind-now and -Xbind-lazy are incompatible}} \
220 %{mrtp:-q %{!shared:%{!non-static:-static}} \
221 %{h*} %{R*} %{!T*: %(link_start)}" \
222 VXWORKS_LINK_OS_SPEC "}"
223
224 #undef VXWORKS_LINK_SPEC
225 #define VXWORKS_LINK_SPEC VXWORKS_BASE_LINK_SPEC " " VXWORKS_EXTRA_LINK_SPEC
226
227 /* Control how to include libgcc in the link closure, handling both "shared"
228 and "non-static" in addition to "static-libgcc" when shared lib support is
229 enabled. */
230
231 #undef VXWORKS_LIBGCC_SPEC
232
233 /* libgcc_eh control; libgcc_eh.a is available either together with libgcc_s
234 (mrtp and mcmodel!=large when configured with --enable-shared) or when the
235 compiler is specially setup to support dual sjlj/table-based eh. */
236
237 /* VX_LGCC_EH_SO1: The "-lgcc_eh" part we need in situations where we know a
238 shared libgcc is available (ENABLE_SHARED_LIBGCC + mrtp multilib). */
239
240 #define VX_LGCC_EH_SO1 " -lgcc_eh -lgcc"
241 /* Extra -lgcc to handle functions from libgcc_eh that refer to symbols
242 exposed by libgcc and not guaranteed to be dragged in before -lgcc_eh
243 appears. */
244
245 /* VX_LGCC_EH_SO0: The "-lgcc_eh" part we need in situations where we know a
246 shared libgcc is not available (!ENABLE_SHARED_LIBGCC or !mrtp multlib). */
247
248 #if !defined(CONFIG_DUAL_EXCEPTIONS)
249
250 /* No shared lib && !DUAL_EH -> no libgcc_eh available at all. */
251 #define VX_LGCC_EH_SO0
252
253 #else /* CONFIG_DUAL_EXCEPTIONS */
254
255 /* No shared lib but DUAL_EH -> libgcc_eh around and spec handled by the driver
256 depending on ENABLE_SHARED_LIBGCC. If defined, the driver expects a regular
257 sequence. Otherwise, the driver is expected to turn -lgcc into -lgcc_eh on
258 its own and just add an instance to address possible cross refs. */
259
260 #if defined(ENABLE_SHARED_LIBGCC)
261 #define VX_LGCC_EH_SO0 " -lgcc_eh -lgcc"
262 #else
263 #define VX_LGCC_EH_SO0 " -lgcc"
264 #endif
265
266 #endif /* CONFIG_DUAL_EXCEPTIONS */
267
268 #if defined(ENABLE_SHARED_LIBGCC)
269 #define VXWORKS_LIBGCC_SPEC \
270 "%{!mrtp|mcmodel=large:-lgcc" VX_LGCC_EH_SO0 ";" \
271 " :%{!static-libgcc:%{shared|non-static:-lgcc_s;:-lgcc" VX_LGCC_EH_SO1 "}} \
272 %{static-libgcc:-lgcc" VX_LGCC_EH_SO1 "}}"
273 #else
274 #define VXWORKS_LIBGCC_SPEC "-lgcc" VX_LGCC_EH_SO0
275 #endif
276
277 /* Setup the crtstuff begin/end we might need for dwarf EH registration
278 and/or INITFINI_ARRAY support. */
279 #if (HAVE_INITFINI_ARRAY_SUPPORT \
280 || (DWARF2_UNWIND_INFO && !defined(CONFIG_SJLJ_EXCEPTIONS)))
281 #define VX_CRTBEGIN_SPEC "%{!shared:vx_crtbegin.o%s;:vx_crtbeginS.o%s}"
282 #define VX_CRTEND_SPEC "%{!shared:vx_crtend.o%s;:vx_crtendS.o%s}"
283 #else
284 #define VX_CRTBEGIN_SPEC ""
285 #define VX_CRTEND_SPEC ""
286 #endif
287
288 #undef VXWORKS_STARTFILE_SPEC
289 #define VXWORKS_STARTFILE_SPEC \
290 VX_CRTBEGIN_SPEC " %{mrtp:%{!shared:-l:crt0.o}}"
291
292 #undef VXWORKS_ENDFILE_SPEC
293 #define VXWORKS_ENDFILE_SPEC VX_CRTEND_SPEC
294
295 #undef VXWORKS_CC1_SPEC
296 #if TARGET_VXWORKS7
297 #define VXWORKS_CC1_SPEC \
298 "%(cc1_cpu) %{!mrtp:%{!ftls-model=*:-ftls-model=local-exec}}"
299 #else
300 #define VXWORKS_CC1_SPEC ""
301 #endif
302
303 /* Do VxWorks-specific parts of TARGET_OPTION_OVERRIDE. */
304 #undef VXWORKS_OVERRIDE_OPTIONS
305 #define VXWORKS_OVERRIDE_OPTIONS vxworks_override_options ()
306 extern void vxworks_override_options (void);
307
308 /* Whether the VxWorks variant and mode supports constructors/destructors
309 placed in .ctors/.dtors section or if we should generate proxy functions
310 for them, with special names which munch knows how to collect. On most
311 versions of VxWorks, only the RTP loader supports .ctors/.dtors sections,
312 not the kernel module loader. */
313 #define TARGET_VXWORKS_HAVE_CTORS_DTORS TARGET_VXWORKS_RTP
314
315 /* Support for prioritized ctors/dtors is in sync with the support for sections
316 on the VxWorks front, and is assumed to be provided by whatever linker level
317 glue is required if we were configured with --enable-initfini-array. */
318 #define SUPPORTS_INIT_PRIORITY \
319 (TARGET_VXWORKS_HAVE_CTORS_DTORS || HAVE_INITFINI_ARRAY_SUPPORT)
320
321 #if !HAVE_INITFINI_ARRAY_SUPPORT
322 /* VxWorks requires special handling of constructors and destructors.
323 All VxWorks configurations must use these functions. */
324 #undef TARGET_ASM_CONSTRUCTOR
325 #define TARGET_ASM_CONSTRUCTOR vxworks_asm_out_constructor
326 #undef TARGET_ASM_DESTRUCTOR
327 #define TARGET_ASM_DESTRUCTOR vxworks_asm_out_destructor
328 extern void vxworks_asm_out_constructor (rtx symbol, int priority);
329 extern void vxworks_asm_out_destructor (rtx symbol, int priority);
330 #endif
331
332 /* Override the vxworks-dummy.h definitions. TARGET_VXWORKS_RTP
333 is defined by vxworks.opt. */
334 #undef VXWORKS_GOTT_BASE
335 #define VXWORKS_GOTT_BASE "__GOTT_BASE__"
336 #undef VXWORKS_GOTT_INDEX
337 #define VXWORKS_GOTT_INDEX "__GOTT_INDEX__"
338
339 #undef PTRDIFF_TYPE
340 #define PTRDIFF_TYPE (TARGET_VXWORKS64 ? "long int" : "int")
341
342 #undef SIZE_TYPE
343 #define SIZE_TYPE (TARGET_VXWORKS64 ? "long unsigned int" : "unsigned int")
344
345 /* Assumptions on the target libc. VxWorks 7, post SR600, provides a C11
346 runtime without sincos support. */
347 #undef TARGET_LIBC_HAS_FUNCTION
348 #define TARGET_LIBC_HAS_FUNCTION \
349 (TARGET_VXWORKS7 ? default_libc_has_function : no_c99_libc_has_function)
350
351 /* Both kernels and RTPs have the facilities required by this macro. */
352 #define TARGET_POSIX_IO
353
354 /* A VxWorks implementation of TARGET_OS_CPP_BUILTINS. */
355
356 /* The VxWorks personality we rely on, controlling which sections of system
357 headers files we trigger. This might be redefined on targets where the
358 base VxWorks environment doesn't come with a GNU toolchain. */
359
360 #define VXWORKS_PERSONALITY "gnu"
361
362 #define VXWORKS_OS_CPP_BUILTINS() \
363 do \
364 { \
365 builtin_define ("__vxworks"); \
366 builtin_define ("__VXWORKS__"); \
367 builtin_assert ("system=unix"); \
368 if (TARGET_VXWORKS_RTP) \
369 builtin_define ("__RTP__"); \
370 else \
371 builtin_define ("_WRS_KERNEL"); \
372 builtin_define ("TOOL_FAMILY=" VXWORKS_PERSONALITY); \
373 builtin_define ("TOOL=" VXWORKS_PERSONALITY); \
374 if (TARGET_VXWORKS7) \
375 { \
376 builtin_define ("_VSB_CONFIG_FILE=<config/vsbConfig.h>"); \
377 \
378 /* _ALLOW_KEYWORD_MACROS is needed on VxWorks 7 to \
379 prevent compilation failures triggered by our \
380 definition of "inline" in ansidecl when "inline" \
381 is not a keyword. */ \
382 if (!flag_isoc99 && !c_dialect_cxx()) \
383 builtin_define ("_ALLOW_KEYWORD_MACROS"); \
384 } \
385 /* C++ support relies on C99 features from C++11, even C++98 \
386 for listdc++ in particular, with corresponding checks at \
387 configure time. Make sure C99 features are exposed by the \
388 system headers. */ \
389 if (c_dialect_cxx()) \
390 builtin_define("_C99"); \
391 } \
392 while (0)
393
394 /* For specific CPU macro definitions expected by the system headers,
395 different versions of VxWorks expect different forms of macros,
396 such as "_VX_CPU=..." on Vx7 and some variants of Vx6, or "CPU=..."
397 on all Vx6 and earlier. Setup a common prefix macro here, that
398 arch specific ports can reuse. */
399
400 #if TARGET_VXWORKS7
401 #define VX_CPU_PREFIX "_VX_"
402 #else
403 #define VX_CPU_PREFIX ""
404 #endif
405
406 #define VXWORKS_KIND VXWORKS_KIND_NORMAL
407
408 /* The diab linker does not handle .gnu_attribute sections. */
409 #undef HAVE_AS_GNU_ATTRIBUTE
410
411 /* We call vxworks's cacheTextUpdate instead of CLEAR_INSN_CACHE if
412 needed. We don't want to force a call on targets that don't define
413 cache-clearing insns nor CLEAR_INSN_CACHE. */
414 #undef TARGET_EMIT_CALL_BUILTIN___CLEAR_CACHE
415 #define TARGET_EMIT_CALL_BUILTIN___CLEAR_CACHE \
416 vxworks_emit_call_builtin___clear_cache
417 extern void vxworks_emit_call_builtin___clear_cache (rtx begin, rtx end);
418
419 /* Default dwarf control values, accounting for non-gdb debuggers that come
420 with VxWorks. */
421
422 #undef DWARF_VERSION_DEFAULT
423 #define DWARF_VERSION_DEFAULT (TARGET_VXWORKS7 ? 3 : 2)
424
425 #undef DWARF_GNAT_ENCODINGS_DEFAULT
426 #define DWARF_GNAT_ENCODINGS_DEFAULT \
427 (TARGET_VXWORKS7 ? DWARF_GNAT_ENCODINGS_MINIMAL : DWARF_GNAT_ENCODINGS_ALL)
428
429 /* The default configuration of incremental LTO linking (-flinker-output=rel)
430 warns if an object file included in the link does not contain LTO bytecode,
431 because in this case the output will not contain it either, thus preventing
432 further incremental LTO linking. We do not do repeated incremental linking
433 so silence the warning (instead of passing -flinker-output=nolto-rel). */
434 #undef LTO_PLUGIN_SPEC
435 #define LTO_PLUGIN_SPEC "%{!mrtp:-plugin-opt=-linker-output-auto-nolto-rel}"