1 /* Common VxWorks target definitions for GNU compiler.
2    Copyright (C) 1999-2021 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 
40 /* Self-tests may be run in contexts where the VxWorks environment isn't
41    available.  Prevent attempts at designating the location of runtime header
42    files, libraries or startfiles, which would fail on unset environment
43    variables and aren't needed for such tests.  */
44 #if TARGET_VXWORKS7
45 
46 #undef VXWORKS_ADDITIONAL_CPP_SPEC
47 #define VXWORKS_ADDITIONAL_CPP_SPEC                     \
48  "%{!nostdinc:%{!fself-test=*:                          \
49     %{isystem*}                                         \
50     %{mrtp: -idirafter %:getenv(VSB_DIR /h)             \
51             -idirafter %:getenv(VSB_DIR /share/h)       \
52             -idirafter %:getenv(VSB_DIR /usr/h/public)  \
53             -idirafter %:getenv(VSB_DIR /usr/h)         \
54       ;:    -idirafter %:getenv(VSB_DIR /h)             \
55             -idirafter %:getenv(VSB_DIR /share/h)       \
56             -idirafter %:getenv(VSB_DIR /krnl/h/system) \
57             -idirafter %:getenv(VSB_DIR /krnl/h/public)}}}"
58 
59 #else /* TARGET_VXWORKS7 */
60 
61 #undef VXWORKS_ADDITIONAL_CPP_SPEC
62 #define VXWORKS_ADDITIONAL_CPP_SPEC		\
63  "%{!nostdinc:%{!fself-test=*:			\
64     %{isystem*}					\
65     %{mrtp: -idirafter %:getenv(WIND_USR /h)	\
66 	    -idirafter %:getenv(WIND_USR /h/wrn/coreip) \
67       ;:    -idirafter %:getenv(WIND_BASE /target/h) \
68 	    -idirafter %:getenv(WIND_BASE /target/h/wrn/coreip) \
69 }}}"
70 
71 #endif
72 
73 /* Our ports rely on gnu-user.h, which #defines _POSIX_SOURCE for
74    C++ by default.  VxWorks doesn't provide 100% of what this implies
75    (e.g. ::mkstemp), so, arrange to prevent that by falling back to
76    the default CPP spec for C++ as well.  */
77 #undef CPLUSPLUS_CPP_SPEC
78 
79 /* For VxWorks static rtps, the system provides libc_internal.a, a superset of
80    libgcc.a that we need to use e.g. to satisfy references to __init and
81    __fini.  We still want our libgcc to prevail for symbols it would provide
82    (e.g. register save entry points), so re-place it here between libraries
83    that might reference it and libc_internal.
84 
85    In addition, some versions of VxWorks rely on explicit extra libraries for
86    system calls and the set of base network libraries of common use varies
87    across architectures.  The default settings defined here might be redefined
88    by target specific port configuration files.  */
89 
90 #define VXWORKS_SYSCALL_LIBS_RTP
91 
92 #if TARGET_VXWORKS7
93 #define VXWORKS_NET_LIBS_RTP "-l%:if-exists-then-else(%:getenv(VSB_DIR /usr/h/public/rtnetStackLib.h) rtnet net)"
94 #else
95 #define VXWORKS_NET_LIBS_RTP "-lnet -ldsi"
96 #endif
97 
98 #define VXWORKS_BASE_LIBS_RTP "-lc -lgcc -lc_internal"
99 
100 #define VXWORKS_EXTRA_LIBS_RTP
101 
102 #define VXWORKS_LIBS_RTP \
103   VXWORKS_SYSCALL_LIBS_RTP " " VXWORKS_NET_LIBS_RTP " " \
104   VXWORKS_BASE_LIBS_RTP " " VXWORKS_EXTRA_LIBS_RTP
105 
106 /* TLS configuration.  VxWorks 7 now always has proper TLS support.
107    Earlier versions did not, not even for RTPS.  */
108 #define VXWORKS_HAVE_TLS TARGET_VXWORKS7
109 
110 /* On Vx6 and previous, the libraries to pick up depends on the architecture,
111    so cannot be defined for all archs at once.  On Vx7, a VSB is always needed
112    and its structure is fixed and does not depend on the arch.  We can thus
113    tell gcc where to look for when linking with RTP libraries.  Use
114    STARTFILE_PREFIX_SPEC for this, instead of explicit -L options in LIB_SPEC,
115    so they survive -nodefaultlibs.  */
116 
117 /* On Vx7 RTP, we need to drag the __tls__ symbol to trigger initialization of
118    tlsLib, responsible for TLS support by the OS.  */
119 
120 #if TARGET_VXWORKS7
121 #undef  STARTFILE_PREFIX_SPEC
122 #define STARTFILE_PREFIX_SPEC \
123   "%{!fself-test=*:%:getenv(VSB_DIR /usr/lib/common)}"
124 #define TLS_SYM "-u __tls__"
125 #else
126 #define TLS_SYM ""
127 #endif
128 
129 #undef VXWORKS_LIB_SPEC
130 #define	VXWORKS_LIB_SPEC						\
131 "%{mrtp:%{shared:-u " USER_LABEL_PREFIX "__init -u " USER_LABEL_PREFIX "__fini} \
132 	%{!shared:%{non-static:-u " USER_LABEL_PREFIX "_STI__6__rtld -ldl} \
133 		  " TLS_SYM " \
134 		  --start-group " VXWORKS_LIBS_RTP " --end-group}}"
135 
136 /* The no-op spec for "-shared" below is present because otherwise GCC
137    will treat it as an unrecognized option.  */
138 #undef VXWORKS_LINK_SPEC
139 #define VXWORKS_LINK_SPEC				\
140 "%{!mrtp:-r}						\
141  %{!shared:						\
142    %{mrtp:-q %{h*}					\
143           %{R*} %{!T*: %(link_start) }			\
144           %(link_target) %(link_os)}}			\
145  %{v:-v}						\
146  %{shared:-shared}					\
147  %{Bstatic:-Bstatic}					\
148  %{Bdynamic:-Bdynamic}					\
149  %{!Xbind-lazy:-z now}					\
150  %{Xbind-now:%{Xbind-lazy:				\
151    %e-Xbind-now and -Xbind-lazy are incompatible}}	\
152  %{mrtp:%{!shared:%{!non-static:-static}		\
153  		  %{non-static:--force-dynamic --export-dynamic}}}"
154 
155 #undef VXWORKS_LIBGCC_SPEC
156 #define VXWORKS_LIBGCC_SPEC "-lgcc"
157 
158 /* Setup the crtstuff begin/end we might need for dwarf EH registration.  */
159 
160 #if !defined(CONFIG_SJLJ_EXCEPTIONS) && DWARF2_UNWIND_INFO
161 #define VX_CRTBEGIN_SPEC "vx_crtbegin.o%s"
162 #define VX_CRTEND_SPEC "-l:vx_crtend.o"
163 #else
164 #define VX_CRTBEGIN_SPEC ""
165 #define VX_CRTEND_SPEC ""
166 #endif
167 
168 #undef VXWORKS_STARTFILE_SPEC
169 #define VXWORKS_STARTFILE_SPEC \
170   VX_CRTBEGIN_SPEC " %{mrtp:%{!shared:-l:crt0.o}}"
171 
172 #undef VXWORKS_ENDFILE_SPEC
173 #define VXWORKS_ENDFILE_SPEC VX_CRTEND_SPEC
174 
175 #undef  VXWORKS_CC1_SPEC
176 #if TARGET_VXWORKS7
177 #define VXWORKS_CC1_SPEC \
178   "%(cc1_cpu) %{!mrtp:%{!ftls-model=*:-ftls-model=local-exec}}"
179 #else
180 #define VXWORKS_CC1_SPEC ""
181 #endif
182 
183 /* Do VxWorks-specific parts of TARGET_OPTION_OVERRIDE.  */
184 #undef VXWORKS_OVERRIDE_OPTIONS
185 #define VXWORKS_OVERRIDE_OPTIONS vxworks_override_options ()
186 extern void vxworks_override_options (void);
187 
188 /* Whether the VxWorks variant and mode supports constructors/destructors
189    placed in .ctors/.dtors section or if we should generate proxy functions
190    for them, with special names which munch knows how to collect.  On most
191    versions of VxWorks, only the RTP loader supports .ctors/.dtors sections,
192    not the kernel module loader.  */
193 #define TARGET_VXWORKS_HAVE_CTORS_DTORS TARGET_VXWORKS_RTP
194 
195 /* Support for prioritized ctors/dtors is in sync with the support for sections
196    on the VxWorks front, and is assumed to be provided by whatever linker level
197    glue is required if we were configured with --enable-initfini-array.  */
198 #define SUPPORTS_INIT_PRIORITY \
199   (TARGET_VXWORKS_HAVE_CTORS_DTORS || HAVE_INITFINI_ARRAY_SUPPORT)
200 
201 #if !HAVE_INITFINI_ARRAY_SUPPORT
202 /* VxWorks requires special handling of constructors and destructors.
203    All VxWorks configurations must use these functions.  */
204 #undef TARGET_ASM_CONSTRUCTOR
205 #define TARGET_ASM_CONSTRUCTOR vxworks_asm_out_constructor
206 #undef TARGET_ASM_DESTRUCTOR
207 #define TARGET_ASM_DESTRUCTOR vxworks_asm_out_destructor
208 extern void vxworks_asm_out_constructor (rtx symbol, int priority);
209 extern void vxworks_asm_out_destructor (rtx symbol, int priority);
210 #endif
211 
212 /* Override the vxworks-dummy.h definitions.  TARGET_VXWORKS_RTP
213    is defined by vxworks.opt.  */
214 #undef VXWORKS_GOTT_BASE
215 #define VXWORKS_GOTT_BASE "__GOTT_BASE__"
216 #undef VXWORKS_GOTT_INDEX
217 #define VXWORKS_GOTT_INDEX "__GOTT_INDEX__"
218 
219 #undef PTRDIFF_TYPE
220 #define PTRDIFF_TYPE (TARGET_VXWORKS64 ? "long int" : "int")
221 
222 #undef SIZE_TYPE
223 #define SIZE_TYPE (TARGET_VXWORKS64 ? "long unsigned int" : "unsigned int")
224 
225 /* Assumptions on the target libc.  VxWorks 7, post SR600, provides a C11
226    runtime without sincos support.  */
227 #undef TARGET_LIBC_HAS_FUNCTION
228 #define TARGET_LIBC_HAS_FUNCTION \
229   (TARGET_VXWORKS7 ? default_libc_has_function : no_c99_libc_has_function)
230 
231 /* Both kernels and RTPs have the facilities required by this macro.  */
232 #define TARGET_POSIX_IO
233 
234 /* A VxWorks implementation of TARGET_OS_CPP_BUILTINS.  */
235 
236 /* The VxWorks personality we rely on, controlling which sections of system
237    headers files we trigger.  This might be redefined on targets where the
238    base VxWorks environment doesn't come with a GNU toolchain.  */
239 
240 #define VXWORKS_PERSONALITY "gnu"
241 
242 #define VXWORKS_OS_CPP_BUILTINS()					\
243   do									\
244     {									\
245       builtin_define ("__vxworks");					\
246       builtin_define ("__VXWORKS__");					\
247       builtin_assert ("system=unix");					\
248       if (TARGET_VXWORKS_RTP)						\
249 	builtin_define ("__RTP__");					\
250       else								\
251 	builtin_define ("_WRS_KERNEL");					\
252       builtin_define ("TOOL_FAMILY=" VXWORKS_PERSONALITY);		\
253       builtin_define ("TOOL=" VXWORKS_PERSONALITY);			\
254       if (TARGET_VXWORKS7)						\
255         {								\
256            builtin_define ("_VSB_CONFIG_FILE=<config/vsbConfig.h>");	\
257            								\
258 	   /* _ALLOW_KEYWORD_MACROS is needed on VxWorks 7 to		\
259 	      prevent compilation failures triggered by our		\
260 	      definition of "inline" in ansidecl when "inline"		\
261 	      is not a keyword.  */					\
262 	   if (!flag_isoc99 && !c_dialect_cxx())			\
263              builtin_define ("_ALLOW_KEYWORD_MACROS");			\
264         }								\
265     }									\
266   while (0)
267 
268 /* For specific CPU macro definitions expected by the system headers,
269    different versions of VxWorks expect different forms of macros,
270    such as "_VX_CPU=..." on Vx7 and some variants of Vx6, or "CPU=..."
271    on all Vx6 and earlier.  Setup a common prefix macro here, that
272    arch specific ports can reuse.  */
273 
274 #if TARGET_VXWORKS7
275 #define VX_CPU_PREFIX "_VX_"
276 #else
277 #define VX_CPU_PREFIX ""
278 #endif
279 
280 #define VXWORKS_KIND VXWORKS_KIND_NORMAL
281 
282 /* The diab linker does not handle .gnu_attribute sections.  */
283 #undef HAVE_AS_GNU_ATTRIBUTE
284 
285 /* We call vxworks's cacheTextUpdate instead of CLEAR_INSN_CACHE if
286    needed.  We don't want to force a call on targets that don't define
287    cache-clearing insns nor CLEAR_INSN_CACHE.  */
288 #undef TARGET_EMIT_CALL_BUILTIN___CLEAR_CACHE
289 #define TARGET_EMIT_CALL_BUILTIN___CLEAR_CACHE \
290   vxworks_emit_call_builtin___clear_cache
291 extern void vxworks_emit_call_builtin___clear_cache (rtx begin, rtx end);
292 
293 /* Default dwarf control values, for non-gdb debuggers that come with
294    VxWorks.  */
295 
296 #undef VXWORKS_DWARF_VERSION_DEFAULT
297 #define VXWORKS_DWARF_VERSION_DEFAULT (TARGET_VXWORKS7 ? 4 : 2)
298 
299 #undef DWARF_GNAT_ENCODINGS_DEFAULT
300 #define DWARF_GNAT_ENCODINGS_DEFAULT \
301   (TARGET_VXWORKS7 ? DWARF_GNAT_ENCODINGS_MINIMAL : DWARF_GNAT_ENCODINGS_ALL)
302 
303 /* The default configuration of incremental LTO linking (-flinker-output=rel)
304    warns if an object file included in the link does not contain LTO bytecode,
305    because in this case the output will not contain it either, thus preventing
306    further incremental LTO linking.  We do not do repeated incremental linking
307    so silence the warning (instead of passing -flinker-output=nolto-rel).  */
308 #undef LTO_PLUGIN_SPEC
309 #define LTO_PLUGIN_SPEC "%{!mrtp:-plugin-opt=-linker-output-auto-nolto-rel}"
310