110d565efSmrg /* Common VxWorks target definitions for GNU compiler.
2*ec02198aSmrg    Copyright (C) 1999-2020 Free Software Foundation, Inc.
310d565efSmrg    Contributed by Wind River Systems.
410d565efSmrg    Rewritten by CodeSourcery, LLC.
510d565efSmrg 
610d565efSmrg This file is part of GCC.
710d565efSmrg 
810d565efSmrg GCC is free software; you can redistribute it and/or modify it under
910d565efSmrg the terms of the GNU General Public License as published by the Free
1010d565efSmrg Software Foundation; either version 3, or (at your option) any later
1110d565efSmrg version.
1210d565efSmrg 
1310d565efSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
1410d565efSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
1510d565efSmrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1610d565efSmrg for more details.
1710d565efSmrg 
1810d565efSmrg You should have received a copy of the GNU General Public License
1910d565efSmrg along with GCC; see the file COPYING3.  If not see
2010d565efSmrg <http://www.gnu.org/licenses/>.  */
2110d565efSmrg 
2210d565efSmrg /* Assert that we are targeting VxWorks.  */
2310d565efSmrg #undef TARGET_VXWORKS
2410d565efSmrg #define TARGET_VXWORKS 1
2510d565efSmrg 
2610d565efSmrg /* In kernel mode, VxWorks provides all the libraries itself, as well as
2710d565efSmrg    the functionality of startup files, etc.  In RTP mode, it behaves more
2810d565efSmrg    like a traditional Unix, with more external files.  Most of our specs
2910d565efSmrg    must be aware of the difference.  */
3010d565efSmrg 
3110d565efSmrg /* We look for the VxWorks header files using the environment
3210d565efSmrg    variables that are set in VxWorks to indicate the location of the
3310d565efSmrg    system header files.  We use -idirafter so that the GCC's own
3410d565efSmrg    header-file directories (containing <stddef.h>, etc.) come before
3510d565efSmrg    the VxWorks system header directories.  */
3610d565efSmrg 
3710d565efSmrg /* Since we provide a default -isystem, expand -isystem on the command
3810d565efSmrg    line early.  */
39c7a68eb7Smrg #if TARGET_VXWORKS7
40c7a68eb7Smrg 
41c7a68eb7Smrg #undef VXWORKS_ADDITIONAL_CPP_SPEC
42c7a68eb7Smrg #define VXWORKS_ADDITIONAL_CPP_SPEC                     \
43c7a68eb7Smrg  "%{!nostdinc:                                          \
44c7a68eb7Smrg     %{isystem*}                                         \
45c7a68eb7Smrg     %{mrtp: -idirafter %:getenv(VSB_DIR /h)             \
46c7a68eb7Smrg             -idirafter %:getenv(VSB_DIR /share/h)       \
47c7a68eb7Smrg             -idirafter %:getenv(VSB_DIR /usr/h/public)  \
48c7a68eb7Smrg             -idirafter %:getenv(VSB_DIR /usr/h)         \
49c7a68eb7Smrg       ;:    -idirafter %:getenv(VSB_DIR /h)             \
50c7a68eb7Smrg             -idirafter %:getenv(VSB_DIR /share/h)       \
51c7a68eb7Smrg             -idirafter %:getenv(VSB_DIR /krnl/h/system) \
52c7a68eb7Smrg             -idirafter %:getenv(VSB_DIR /krnl/h/public)}}"
53c7a68eb7Smrg 
54c7a68eb7Smrg #else /* TARGET_VXWORKS7 */
55c7a68eb7Smrg 
5610d565efSmrg #undef VXWORKS_ADDITIONAL_CPP_SPEC
5710d565efSmrg #define VXWORKS_ADDITIONAL_CPP_SPEC		\
5810d565efSmrg  "%{!nostdinc:					\
590fc04c29Smrg     %{isystem*}					\
600fc04c29Smrg     %{mrtp: -idirafter %:getenv(WIND_USR /h)	\
610fc04c29Smrg 	    -idirafter %:getenv(WIND_USR /h/wrn/coreip) \
620fc04c29Smrg       ;:    -idirafter %:getenv(WIND_BASE /target/h) \
630fc04c29Smrg 	    -idirafter %:getenv(WIND_BASE /target/h/wrn/coreip) \
640fc04c29Smrg }}"
6510d565efSmrg 
66c7a68eb7Smrg #endif
67c7a68eb7Smrg 
680fc04c29Smrg /* For VxWorks static rtps, the system provides libc_internal.a, a superset of
690fc04c29Smrg    libgcc.a that we need to use e.g. to satisfy references to __init and
700fc04c29Smrg    __fini.  We still want our libgcc to prevail for symbols it would provide
710fc04c29Smrg    (e.g. register save entry points), so re-place it here between libraries
720fc04c29Smrg    that might reference it and libc_internal.
730fc04c29Smrg 
740fc04c29Smrg    In addition, some versions of VxWorks rely on explicit extra libraries for
750fc04c29Smrg    system calls and the set of base network libraries of common use varies
760fc04c29Smrg    across architectures.  The default settings defined here might be redefined
770fc04c29Smrg    by target specific port configuration files.  */
78c7a68eb7Smrg 
79c7a68eb7Smrg #define VXWORKS_SYSCALL_LIBS_RTP
80c7a68eb7Smrg 
81*ec02198aSmrg #if TARGET_VXWORKS7
82*ec02198aSmrg #define VXWORKS_NET_LIBS_RTP "-lnet"
83*ec02198aSmrg #else
840fc04c29Smrg #define VXWORKS_NET_LIBS_RTP "-lnet -ldsi"
85*ec02198aSmrg #endif
86*ec02198aSmrg 
87*ec02198aSmrg #define VXWORKS_BASE_LIBS_RTP "-lc -lgcc -lc_internal"
88*ec02198aSmrg 
89*ec02198aSmrg #define VXWORKS_EXTRA_LIBS_RTP
900fc04c29Smrg 
91c7a68eb7Smrg #define VXWORKS_LIBS_RTP \
92*ec02198aSmrg   VXWORKS_SYSCALL_LIBS_RTP " " VXWORKS_NET_LIBS_RTP " " \
93*ec02198aSmrg   VXWORKS_BASE_LIBS_RTP " " VXWORKS_EXTRA_LIBS_RTP
94*ec02198aSmrg 
95*ec02198aSmrg /* TLS configuration.  VxWorks 7 now always has proper TLS support.
96*ec02198aSmrg    Earlier versions did not, not even for RTPS.  */
97*ec02198aSmrg #define VXWORKS_HAVE_TLS TARGET_VXWORKS7
98c7a68eb7Smrg 
99c7a68eb7Smrg /* On Vx6 and previous, the libraries to pick up depends on the architecture,
100c7a68eb7Smrg    so cannot be defined for all archs at once.  On Vx7, a VSB is always needed
101c7a68eb7Smrg    and its structure is fixed and does not depend on the arch.  We can thus
1020fc04c29Smrg    tell gcc where to look for when linking with RTP libraries.  Use
1030fc04c29Smrg    STARTFILE_PREFIX_SPEC for this, instead of explicit -L options in LIB_SPEC,
1040fc04c29Smrg    so they survive -nodefaultlibs.  */
105c7a68eb7Smrg 
106c7a68eb7Smrg /* On Vx7 RTP, we need to drag the __tls__ symbol to trigger initialization of
107c7a68eb7Smrg    tlsLib, responsible for TLS support by the OS.  */
108c7a68eb7Smrg 
109c7a68eb7Smrg #if TARGET_VXWORKS7
1100fc04c29Smrg #undef  STARTFILE_PREFIX_SPEC
1110fc04c29Smrg #define STARTFILE_PREFIX_SPEC "%:getenv(VSB_DIR /usr/lib/common)"
112c7a68eb7Smrg #define TLS_SYM "-u __tls__"
113c7a68eb7Smrg #else
114c7a68eb7Smrg #define TLS_SYM ""
115c7a68eb7Smrg #endif
116c7a68eb7Smrg 
11710d565efSmrg #undef VXWORKS_LIB_SPEC
11810d565efSmrg #define	VXWORKS_LIB_SPEC						\
11910d565efSmrg "%{mrtp:%{shared:-u " USER_LABEL_PREFIX "__init -u " USER_LABEL_PREFIX "__fini} \
12010d565efSmrg 	%{!shared:%{non-static:-u " USER_LABEL_PREFIX "_STI__6__rtld -ldl} \
121c7a68eb7Smrg 		  " TLS_SYM " \
1220fc04c29Smrg 		  --start-group " VXWORKS_LIBS_RTP " --end-group}}"
12310d565efSmrg 
12410d565efSmrg /* The no-op spec for "-shared" below is present because otherwise GCC
12510d565efSmrg    will treat it as an unrecognized option.  */
12610d565efSmrg #undef VXWORKS_LINK_SPEC
12710d565efSmrg #define VXWORKS_LINK_SPEC				\
12810d565efSmrg "%{!mrtp:-r}						\
12910d565efSmrg  %{!shared:						\
13010d565efSmrg    %{mrtp:-q %{h*}					\
13110d565efSmrg           %{R*} %{!T*: %(link_start) }			\
13210d565efSmrg           %(link_target) %(link_os)}}			\
13310d565efSmrg  %{v:-v}						\
13410d565efSmrg  %{shared:-shared}					\
13510d565efSmrg  %{Bstatic:-Bstatic}					\
13610d565efSmrg  %{Bdynamic:-Bdynamic}					\
13710d565efSmrg  %{!Xbind-lazy:-z now}					\
13810d565efSmrg  %{Xbind-now:%{Xbind-lazy:				\
13910d565efSmrg    %e-Xbind-now and -Xbind-lazy are incompatible}}	\
14010d565efSmrg  %{mrtp:%{!shared:%{!non-static:-static}		\
14110d565efSmrg  		  %{non-static:--force-dynamic --export-dynamic}}}"
14210d565efSmrg 
14310d565efSmrg #undef VXWORKS_LIBGCC_SPEC
1440fc04c29Smrg #define VXWORKS_LIBGCC_SPEC "-lgcc"
14510d565efSmrg 
146*ec02198aSmrg /* Setup the crtstuff begin/end we might need for dwarf EH registration.  */
147*ec02198aSmrg 
148*ec02198aSmrg #if !defined(CONFIG_SJLJ_EXCEPTIONS) && DWARF2_UNWIND_INFO
149*ec02198aSmrg #define VX_CRTBEGIN_SPEC \
150*ec02198aSmrg  "%{!mrtp:vx_crtbegin-kernel.o%s} %{mrtp:vx_crtbegin-rtp.o%s}"
151*ec02198aSmrg #define VX_CRTEND_SPEC "-l:vx_crtend.o"
152*ec02198aSmrg #else
153*ec02198aSmrg #define VX_CRTBEGIN_SPEC ""
154*ec02198aSmrg #define VX_CRTEND_SPEC ""
155*ec02198aSmrg #endif
156*ec02198aSmrg 
15710d565efSmrg #undef VXWORKS_STARTFILE_SPEC
158*ec02198aSmrg #define VXWORKS_STARTFILE_SPEC \
159*ec02198aSmrg   VX_CRTBEGIN_SPEC " %{mrtp:%{!shared:-l:crt0.o}}"
160*ec02198aSmrg 
161*ec02198aSmrg #undef VXWORKS_ENDFILE_SPEC
162*ec02198aSmrg #define VXWORKS_ENDFILE_SPEC VX_CRTEND_SPEC
163*ec02198aSmrg 
164*ec02198aSmrg #undef  VXWORKS_CC1_SPEC
165*ec02198aSmrg #if TARGET_VXWORKS7
166*ec02198aSmrg #define VXWORKS_CC1_SPEC \
167*ec02198aSmrg   "%(cc1_cpu) %{!mrtp:%{!ftls-model=*:-ftls-model=local-exec}}"
168*ec02198aSmrg #else
169*ec02198aSmrg #define VXWORKS_CC1_SPEC ""
170*ec02198aSmrg #endif
17110d565efSmrg 
17210d565efSmrg /* Do VxWorks-specific parts of TARGET_OPTION_OVERRIDE.  */
17310d565efSmrg #undef VXWORKS_OVERRIDE_OPTIONS
17410d565efSmrg #define VXWORKS_OVERRIDE_OPTIONS vxworks_override_options ()
17510d565efSmrg extern void vxworks_override_options (void);
17610d565efSmrg 
1770fc04c29Smrg /* Whether the VxWorks variant and mode supports constructors/destructors
1780fc04c29Smrg    placed in .ctors/.dtors section or if we should generate proxy functions
1790fc04c29Smrg    for them, with special names which munch knows how to collect.  On most
1800fc04c29Smrg    versions of VxWorks, only the RTP loader supports .ctors/.dtors sections,
1810fc04c29Smrg    not the kernel module loader.  */
1820fc04c29Smrg #define TARGET_VXWORKS_HAVE_CTORS_DTORS TARGET_VXWORKS_RTP
18310d565efSmrg 
1840fc04c29Smrg /* Support for prioritized ctors/dtors is in sync with the support for sections
1850fc04c29Smrg    on the VxWorks front, and is assumed to be provided by whatever linker level
1860fc04c29Smrg    glue is required if we were configured with --enable-initfini-array.  */
1870fc04c29Smrg #define SUPPORTS_INIT_PRIORITY \
1880fc04c29Smrg   (TARGET_VXWORKS_HAVE_CTORS_DTORS || HAVE_INITFINI_ARRAY_SUPPORT)
1890fc04c29Smrg 
1900fc04c29Smrg #if !HAVE_INITFINI_ARRAY_SUPPORT
19110d565efSmrg /* VxWorks requires special handling of constructors and destructors.
19210d565efSmrg    All VxWorks configurations must use these functions.  */
19310d565efSmrg #undef TARGET_ASM_CONSTRUCTOR
19410d565efSmrg #define TARGET_ASM_CONSTRUCTOR vxworks_asm_out_constructor
19510d565efSmrg #undef TARGET_ASM_DESTRUCTOR
19610d565efSmrg #define TARGET_ASM_DESTRUCTOR vxworks_asm_out_destructor
19710d565efSmrg extern void vxworks_asm_out_constructor (rtx symbol, int priority);
19810d565efSmrg extern void vxworks_asm_out_destructor (rtx symbol, int priority);
1990fc04c29Smrg #endif
20010d565efSmrg 
20110d565efSmrg /* Override the vxworks-dummy.h definitions.  TARGET_VXWORKS_RTP
20210d565efSmrg    is defined by vxworks.opt.  */
20310d565efSmrg #undef VXWORKS_GOTT_BASE
20410d565efSmrg #define VXWORKS_GOTT_BASE "__GOTT_BASE__"
20510d565efSmrg #undef VXWORKS_GOTT_INDEX
20610d565efSmrg #define VXWORKS_GOTT_INDEX "__GOTT_INDEX__"
20710d565efSmrg 
20810d565efSmrg #undef PTRDIFF_TYPE
2090fc04c29Smrg #define PTRDIFF_TYPE (TARGET_VXWORKS64 ? "long int" : "int")
21010d565efSmrg 
21110d565efSmrg #undef SIZE_TYPE
2120fc04c29Smrg #define SIZE_TYPE (TARGET_VXWORKS64 ? "long unsigned int" : "unsigned int")
21310d565efSmrg 
214*ec02198aSmrg /* Assumptions on the target libc.  VxWorks 7, post SR600, provides a C11
215*ec02198aSmrg    runtime without sincos support.  */
21610d565efSmrg #undef TARGET_LIBC_HAS_FUNCTION
217*ec02198aSmrg #define TARGET_LIBC_HAS_FUNCTION \
218*ec02198aSmrg   (TARGET_VXWORKS7 ? default_libc_has_function : no_c99_libc_has_function)
21910d565efSmrg 
22010d565efSmrg /* Both kernels and RTPs have the facilities required by this macro.  */
22110d565efSmrg #define TARGET_POSIX_IO
22210d565efSmrg 
22310d565efSmrg /* A VxWorks implementation of TARGET_OS_CPP_BUILTINS.  */
2240fc04c29Smrg 
2250fc04c29Smrg /* The VxWorks personality we rely on, controlling which sections of system
2260fc04c29Smrg    headers files we trigger.  This might be redefined on targets where the
2270fc04c29Smrg    base VxWorks environment doesn't come with a GNU toolchain.  */
2280fc04c29Smrg 
2290fc04c29Smrg #define VXWORKS_PERSONALITY "gnu"
2300fc04c29Smrg 
23110d565efSmrg #define VXWORKS_OS_CPP_BUILTINS()					\
23210d565efSmrg   do									\
23310d565efSmrg     {									\
23410d565efSmrg       builtin_define ("__vxworks");					\
23510d565efSmrg       builtin_define ("__VXWORKS__");					\
23610d565efSmrg       builtin_assert ("system=unix");					\
23710d565efSmrg       if (TARGET_VXWORKS_RTP)						\
23810d565efSmrg 	builtin_define ("__RTP__");					\
23910d565efSmrg       else								\
24010d565efSmrg 	builtin_define ("_WRS_KERNEL");					\
2410fc04c29Smrg       builtin_define ("TOOL_FAMILY=" VXWORKS_PERSONALITY);		\
2420fc04c29Smrg       builtin_define ("TOOL=" VXWORKS_PERSONALITY);			\
243c7a68eb7Smrg       if (TARGET_VXWORKS7)						\
244c7a68eb7Smrg         {								\
245c7a68eb7Smrg            builtin_define ("_VSB_CONFIG_FILE=<config/vsbConfig.h>");	\
246c7a68eb7Smrg            								\
247c7a68eb7Smrg 	   /* _ALLOW_KEYWORD_MACROS is needed on VxWorks 7 to		\
248c7a68eb7Smrg 	      prevent compilation failures triggered by our		\
249c7a68eb7Smrg 	      definition of "inline" in ansidecl when "inline"		\
250c7a68eb7Smrg 	      is not a keyword.  */					\
251c7a68eb7Smrg 	   if (!flag_isoc99 && !c_dialect_cxx())			\
252c7a68eb7Smrg              builtin_define ("_ALLOW_KEYWORD_MACROS");			\
253c7a68eb7Smrg         }								\
25410d565efSmrg     }									\
25510d565efSmrg   while (0)
25610d565efSmrg 
25710d565efSmrg #define VXWORKS_KIND VXWORKS_KIND_NORMAL
25810d565efSmrg 
25910d565efSmrg /* The diab linker does not handle .gnu_attribute sections.  */
26010d565efSmrg #undef HAVE_AS_GNU_ATTRIBUTE
261c7a68eb7Smrg 
2620fc04c29Smrg /* We provide our own version of __clear_cache in libgcc, using a separate C
2630fc04c29Smrg    file to facilitate #inclusion of VxWorks header files.  */
2640fc04c29Smrg #undef CLEAR_INSN_CACHE
2650fc04c29Smrg #define CLEAR_INSN_CACHE 1
2660fc04c29Smrg 
267c7a68eb7Smrg /* Default dwarf control values, for non-gdb debuggers that come with
268c7a68eb7Smrg    VxWorks.  */
269c7a68eb7Smrg 
270c7a68eb7Smrg #undef VXWORKS_DWARF_VERSION_DEFAULT
271c7a68eb7Smrg #define VXWORKS_DWARF_VERSION_DEFAULT (TARGET_VXWORKS7 ? 4 : 2)
272c7a68eb7Smrg 
273c7a68eb7Smrg #undef DWARF_GNAT_ENCODINGS_DEFAULT
274c7a68eb7Smrg #define DWARF_GNAT_ENCODINGS_DEFAULT \
275c7a68eb7Smrg   (TARGET_VXWORKS7 ? DWARF_GNAT_ENCODINGS_MINIMAL : DWARF_GNAT_ENCODINGS_ALL)
276