1 /* Common VxWorks target definitions for GNU compiler.
2 Copyright (C) 2007-2021 Free Software Foundation, Inc.
3 Contributed by CodeSourcery, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
26 #include "stringpool.h"
27 #include "diagnostic-core.h"
29 #include "fold-const.h"
34 #if !HAVE_INITFINI_ARRAY_SUPPORT
35 /* Like default_named_section_asm_out_constructor, except that even
36 constructors with DEFAULT_INIT_PRIORITY must go in a numbered
37 section on VxWorks. The VxWorks runtime uses a clever trick to get
38 the sentinel entry (-1) inserted at the beginning of the .ctors
39 segment. This trick will not work if we ever generate any entries
40 in plain .ctors sections; we must always use .ctors.PRIORITY. */
43 vxworks_asm_out_constructor (rtx symbol
, int priority
)
47 sec
= get_cdtor_priority_section (priority
,
48 /*constructor_p=*/true);
49 assemble_addr_to_section (symbol
, sec
);
52 /* See comment for vxworks_asm_out_constructor. */
55 vxworks_asm_out_destructor (rtx symbol
, int priority
)
59 sec
= get_cdtor_priority_section (priority
,
60 /*constructor_p=*/false);
61 assemble_addr_to_section (symbol
, sec
);
65 /* Return the list of FIELD_DECLs that make up an emulated TLS
66 variable's control object. TYPE is the structure these are fields
67 of and *NAME will be filled in with the structure tag that should
71 vxworks_emutls_var_fields (tree type
, tree
*name
)
73 tree field
, next_field
;
75 *name
= get_identifier ("__tls_var");
77 field
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
,
78 get_identifier ("size"), unsigned_type_node
);
79 DECL_CONTEXT (field
) = type
;
82 field
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
,
83 get_identifier ("module_id"), unsigned_type_node
);
84 DECL_CONTEXT (field
) = type
;
85 DECL_CHAIN (field
) = next_field
;
88 /* The offset field is declared as an unsigned int with pointer mode. */
89 field
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
,
90 get_identifier ("offset"), long_unsigned_type_node
);
92 DECL_CONTEXT (field
) = type
;
93 DECL_CHAIN (field
) = next_field
;
98 /* Return the CONSTRUCTOR to initialize an emulated TLS control
99 object. VAR is the control object. DECL is the TLS object itself
100 and TMPL_ADDR is the address (an ADDR_EXPR) of the initializer for
104 vxworks_emutls_var_init (tree var
, tree decl
, tree tmpl_addr
)
106 vec
<constructor_elt
, va_gc
> *v
;
109 tree type
= TREE_TYPE (var
);
110 tree field
= TYPE_FIELDS (type
);
112 constructor_elt elt
= {field
, fold_convert (TREE_TYPE (field
), tmpl_addr
)};
115 field
= DECL_CHAIN (field
);
117 elt
.value
= build_int_cst (TREE_TYPE (field
), 0);
120 field
= DECL_CHAIN (field
);
122 elt
.value
= fold_convert (TREE_TYPE (field
), DECL_SIZE_UNIT (decl
));
125 return build_constructor (type
, v
);
128 /* Do VxWorks-specific parts of TARGET_OPTION_OVERRIDE. */
131 vxworks_override_options (void)
133 /* Setup the tls emulation bits if the OS misses proper
135 targetm
.have_tls
= VXWORKS_HAVE_TLS
;
137 if (!VXWORKS_HAVE_TLS
)
139 targetm
.emutls
.get_address
= "__builtin___tls_lookup";
140 targetm
.emutls
.register_common
= NULL
;
141 targetm
.emutls
.var_section
= ".tls_vars";
142 targetm
.emutls
.tmpl_section
= ".tls_data";
143 targetm
.emutls
.var_prefix
= "__tls__";
144 targetm
.emutls
.tmpl_prefix
= "";
145 targetm
.emutls
.var_fields
= vxworks_emutls_var_fields
;
146 targetm
.emutls
.var_init
= vxworks_emutls_var_init
;
147 targetm
.emutls
.var_align_fixed
= true;
148 targetm
.emutls
.debug_form_tls_address
= true;
151 /* Arrange to use .ctors/.dtors sections if the target VxWorks configuration
152 and mode supports it, or the init/fini_array sections if we were
153 configured with --enable-initfini-array explicitly. In the latter case,
154 the toolchain user is expected to provide whatever linker level glue is
155 required to get things to operate properly. */
157 targetm
.have_ctors_dtors
=
158 TARGET_VXWORKS_HAVE_CTORS_DTORS
|| HAVE_INITFINI_ARRAY_SUPPORT
;
160 /* PIC is only supported for RTPs. flags_pic might be < 0 here, in
161 contexts where the corresponding switches are not processed,
162 e.g. from --help. We are not generating code in such cases. */
163 if (flag_pic
> 0 && !TARGET_VXWORKS_RTP
)
164 error ("PIC is only supported for RTPs");
166 /* VxWorks comes with non-gdb debuggers which only support strict
167 dwarf up to certain version. Default dwarf control to friendly
170 if (!global_options_set
.x_dwarf_strict
)
173 if (!global_options_set
.x_dwarf_version
)
174 dwarf_version
= VXWORKS_DWARF_VERSION_DEFAULT
;
178 /* We don't want to use library symbol __clear_cache on SR0640. Avoid
179 it and issue a direct call to cacheTextUpdate. It takes a size_t
180 length rather than the END address, so we have to compute it. */
183 vxworks_emit_call_builtin___clear_cache (rtx begin
, rtx end
)
185 /* STATUS cacheTextUpdate (void *, size_t); */
186 rtx callee
= gen_rtx_SYMBOL_REF (Pmode
, "cacheTextUpdate");
188 enum machine_mode size_mode
= TYPE_MODE (sizetype
);
190 rtx len
= simplify_gen_binary (MINUS
, size_mode
, end
, begin
);
192 emit_library_call (callee
,
193 LCT_NORMAL
, VOIDmode
,