| 1 |
/* Common VxWorks target definitions for GNU compiler. |
| 2 |
Copyright (C) 2007-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by CodeSourcery, Inc. |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 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 |
| 10 |
version. |
| 11 |
|
| 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 |
| 15 |
for more details. |
| 16 |
|
| 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/>. */ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
#include "system.h" |
| 23 |
#include "coretypes.h" |
| 24 |
#include "target.h" |
| 25 |
#include "tree.h" |
| 26 |
#include "stringpool.h" |
| 27 |
#include "diagnostic-core.h" |
| 28 |
#include "output.h" |
| 29 |
#include "fold-const.h" |
| 30 |
#include "rtl.h" |
| 31 |
#include "memmodel.h" |
| 32 |
#include "optabs.h" |
| 33 |
#include "opts.h" |
| 34 |
|
| 35 |
#if !HAVE_INITFINI_ARRAY_SUPPORT |
| 36 |
/* Like default_named_section_asm_out_constructor, except that even |
| 37 |
constructors with DEFAULT_INIT_PRIORITY must go in a numbered |
| 38 |
section on VxWorks. The VxWorks runtime uses a clever trick to get |
| 39 |
the sentinel entry (-1) inserted at the beginning of the .ctors |
| 40 |
segment. This trick will not work if we ever generate any entries |
| 41 |
in plain .ctors sections; we must always use .ctors.PRIORITY. */ |
| 42 |
|
| 43 |
void |
| 44 |
vxworks_asm_out_constructor (rtx symbol, int priority) |
| 45 |
{ |
| 46 |
section *sec; |
| 47 |
|
| 48 |
sec = get_cdtor_priority_section (priority, |
| 49 |
/*constructor_p=*/true); |
| 50 |
assemble_addr_to_section (symbol, sec); |
| 51 |
} |
| 52 |
|
| 53 |
/* See comment for vxworks_asm_out_constructor. */ |
| 54 |
|
| 55 |
void |
| 56 |
vxworks_asm_out_destructor (rtx symbol, int priority) |
| 57 |
{ |
| 58 |
section *sec; |
| 59 |
|
| 60 |
sec = get_cdtor_priority_section (priority, |
| 61 |
/*constructor_p=*/false); |
| 62 |
assemble_addr_to_section (symbol, sec); |
| 63 |
} |
| 64 |
#endif |
| 65 |
|
| 66 |
/* Return the list of FIELD_DECLs that make up an emulated TLS |
| 67 |
variable's control object. TYPE is the structure these are fields |
| 68 |
of and *NAME will be filled in with the structure tag that should |
| 69 |
be used. */ |
| 70 |
|
| 71 |
static tree |
| 72 |
vxworks_emutls_var_fields (tree type, tree *name) |
| 73 |
{ |
| 74 |
tree field, next_field; |
| 75 |
|
| 76 |
*name = get_identifier ("__tls_var"); |
| 77 |
|
| 78 |
field = build_decl (BUILTINS_LOCATION, FIELD_DECL, |
| 79 |
get_identifier ("size"), unsigned_type_node); |
| 80 |
DECL_CONTEXT (field) = type; |
| 81 |
next_field = field; |
| 82 |
|
| 83 |
field = build_decl (BUILTINS_LOCATION, FIELD_DECL, |
| 84 |
get_identifier ("module_id"), unsigned_type_node); |
| 85 |
DECL_CONTEXT (field) = type; |
| 86 |
DECL_CHAIN (field) = next_field; |
| 87 |
next_field = field; |
| 88 |
|
| 89 |
/* The offset field is declared as an unsigned int with pointer mode. */ |
| 90 |
field = build_decl (BUILTINS_LOCATION, FIELD_DECL, |
| 91 |
get_identifier ("offset"), long_unsigned_type_node); |
| 92 |
|
| 93 |
DECL_CONTEXT (field) = type; |
| 94 |
DECL_CHAIN (field) = next_field; |
| 95 |
|
| 96 |
return field; |
| 97 |
} |
| 98 |
|
| 99 |
/* Return the CONSTRUCTOR to initialize an emulated TLS control |
| 100 |
object. VAR is the control object. DECL is the TLS object itself |
| 101 |
and TMPL_ADDR is the address (an ADDR_EXPR) of the initializer for |
| 102 |
that object. */ |
| 103 |
|
| 104 |
static tree |
| 105 |
vxworks_emutls_var_init (tree var, tree decl, tree tmpl_addr) |
| 106 |
{ |
| 107 |
vec<constructor_elt, va_gc> *v; |
| 108 |
vec_alloc (v, 3); |
| 109 |
|
| 110 |
tree type = TREE_TYPE (var); |
| 111 |
tree field = TYPE_FIELDS (type); |
| 112 |
|
| 113 |
constructor_elt elt = {field, fold_convert (TREE_TYPE (field), tmpl_addr)}; |
| 114 |
v->quick_push (elt); |
| 115 |
|
| 116 |
field = DECL_CHAIN (field); |
| 117 |
elt.index = field; |
| 118 |
elt.value = build_int_cst (TREE_TYPE (field), 0); |
| 119 |
v->quick_push (elt); |
| 120 |
|
| 121 |
field = DECL_CHAIN (field); |
| 122 |
elt.index = field; |
| 123 |
elt.value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl)); |
| 124 |
v->quick_push (elt); |
| 125 |
|
| 126 |
return build_constructor (type, v); |
| 127 |
} |
| 128 |
|
| 129 |
/* Do VxWorks-specific parts of TARGET_OPTION_OVERRIDE. */ |
| 130 |
|
| 131 |
void |
| 132 |
vxworks_override_options (void) |
| 133 |
{ |
| 134 |
/* Setup the tls emulation bits if the OS misses proper |
| 135 |
tls support. */ |
| 136 |
targetm.have_tls = VXWORKS_HAVE_TLS; |
| 137 |
|
| 138 |
if (!VXWORKS_HAVE_TLS) |
| 139 |
{ |
| 140 |
targetm.emutls.get_address = "__builtin___tls_lookup"; |
| 141 |
targetm.emutls.register_common = NULL; |
| 142 |
targetm.emutls.var_section = ".tls_vars"; |
| 143 |
targetm.emutls.tmpl_section = ".tls_data"; |
| 144 |
targetm.emutls.var_prefix = "__tls__"; |
| 145 |
targetm.emutls.tmpl_prefix = ""; |
| 146 |
targetm.emutls.var_fields = vxworks_emutls_var_fields; |
| 147 |
targetm.emutls.var_init = vxworks_emutls_var_init; |
| 148 |
targetm.emutls.var_align_fixed = true; |
| 149 |
targetm.emutls.debug_form_tls_address = true; |
| 150 |
} |
| 151 |
|
| 152 |
/* Arrange to use .ctors/.dtors sections if the target VxWorks configuration |
| 153 |
and mode supports it, or the init/fini_array sections if we were |
| 154 |
configured with --enable-initfini-array explicitly. In the latter case, |
| 155 |
the toolchain user is expected to provide whatever linker level glue is |
| 156 |
required to get things to operate properly. */ |
| 157 |
|
| 158 |
targetm.have_ctors_dtors = |
| 159 |
TARGET_VXWORKS_HAVE_CTORS_DTORS || HAVE_INITFINI_ARRAY_SUPPORT; |
| 160 |
|
| 161 |
/* PIC is only supported for RTPs. flags_pic might be < 0 here, in |
| 162 |
contexts where the corresponding switches are not processed, |
| 163 |
e.g. from --help. We are not generating code in such cases. */ |
| 164 |
if (flag_pic > 0 && !TARGET_VXWORKS_RTP) |
| 165 |
error ("PIC is only supported for RTPs"); |
| 166 |
|
| 167 |
/* VxWorks comes with non-gdb debuggers which only support strict dwarf |
| 168 |
up to certain versions, as controlled by DWARF_VERSION_DEFAULT. */ |
| 169 |
if (!OPTION_SET_P (dwarf_strict)) |
| 170 |
dwarf_strict = 1; |
| 171 |
} |
| 172 |
|
| 173 |
/* We don't want to use library symbol __clear_cache on SR0640. Avoid |
| 174 |
it and issue a direct call to cacheTextUpdate. It takes a size_t |
| 175 |
length rather than the END address, so we have to compute it. */ |
| 176 |
|
| 177 |
void |
| 178 |
vxworks_emit_call_builtin___clear_cache (rtx begin, rtx end) |
| 179 |
{ |
| 180 |
/* STATUS cacheTextUpdate (void *, size_t); */ |
| 181 |
rtx callee = gen_rtx_SYMBOL_REF (Pmode, "cacheTextUpdate"); |
| 182 |
|
| 183 |
enum machine_mode size_mode = TYPE_MODE (sizetype); |
| 184 |
|
| 185 |
rtx len = simplify_gen_binary (MINUS, size_mode, end, begin); |
| 186 |
|
| 187 |
emit_library_call (callee, |
| 188 |
LCT_NORMAL, VOIDmode, |
| 189 |
begin, ptr_mode, |
| 190 |
len, size_mode); |
| 191 |
} |