]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/vxworks.c
Update copyright years.
[thirdparty/gcc.git] / gcc / config / vxworks.c
CommitLineData
b2f4bed8 1/* Common VxWorks target definitions for GNU compiler.
7adcbafe 2 Copyright (C) 2007-2022 Free Software Foundation, Inc.
b2f4bed8
MM
3 Contributed by CodeSourcery, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
2f83c7d6 9Software Foundation; either version 3, or (at your option) any later
b2f4bed8
MM
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
2f83c7d6
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
b2f4bed8
MM
20
21#include "config.h"
22#include "system.h"
23#include "coretypes.h"
ef672755 24#include "target.h"
e11c4407
AM
25#include "tree.h"
26#include "stringpool.h"
718f9c0f 27#include "diagnostic-core.h"
b2f4bed8 28#include "output.h"
40e23961 29#include "fold-const.h"
c05ece92
AO
30#include "rtl.h"
31#include "memmodel.h"
32#include "optabs.h"
00f34291 33#include "opts.h"
b2f4bed8 34
eae016fc 35#if !HAVE_INITFINI_ARRAY_SUPPORT
b2f4bed8
MM
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
43void
44vxworks_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
55void
56vxworks_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}
eae016fc 64#endif
ef672755 65
feb60f03
NS
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
71static tree
72vxworks_emutls_var_fields (tree type, tree *name)
73{
74 tree field, next_field;
75
76 *name = get_identifier ("__tls_var");
77
7703295f
RH
78 field = build_decl (BUILTINS_LOCATION, FIELD_DECL,
79 get_identifier ("size"), unsigned_type_node);
feb60f03
NS
80 DECL_CONTEXT (field) = type;
81 next_field = field;
82
7703295f
RH
83 field = build_decl (BUILTINS_LOCATION, FIELD_DECL,
84 get_identifier ("module_id"), unsigned_type_node);
feb60f03 85 DECL_CONTEXT (field) = type;
910ad8de 86 DECL_CHAIN (field) = next_field;
feb60f03
NS
87 next_field = field;
88
a93e7e14 89 /* The offset field is declared as an unsigned int with pointer mode. */
7703295f 90 field = build_decl (BUILTINS_LOCATION, FIELD_DECL,
a93e7e14
JL
91 get_identifier ("offset"), long_unsigned_type_node);
92
feb60f03 93 DECL_CONTEXT (field) = type;
910ad8de 94 DECL_CHAIN (field) = next_field;
feb60f03
NS
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
104static tree
105vxworks_emutls_var_init (tree var, tree decl, tree tmpl_addr)
106{
9771b263
DN
107 vec<constructor_elt, va_gc> *v;
108 vec_alloc (v, 3);
feb60f03
NS
109
110 tree type = TREE_TYPE (var);
111 tree field = TYPE_FIELDS (type);
112
fc1bc21b 113 constructor_elt elt = {field, fold_convert (TREE_TYPE (field), tmpl_addr)};
9771b263 114 v->quick_push (elt);
feb60f03 115
910ad8de 116 field = DECL_CHAIN (field);
fc1bc21b
DN
117 elt.index = field;
118 elt.value = build_int_cst (TREE_TYPE (field), 0);
9771b263 119 v->quick_push (elt);
feb60f03 120
910ad8de 121 field = DECL_CHAIN (field);
fc1bc21b
DN
122 elt.index = field;
123 elt.value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
9771b263 124 v->quick_push (elt);
feb60f03
NS
125
126 return build_constructor (type, v);
127}
128
c5387660 129/* Do VxWorks-specific parts of TARGET_OPTION_OVERRIDE. */
ef672755
RS
130
131void
132vxworks_override_options (void)
133{
931fae81
JL
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
7f37b31d
JL
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;
ef672755 160
c602426c
OH
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)
ef672755 165 error ("PIC is only supported for RTPs");
7a9cf7e9 166
824a2b3d
OH
167 /* VxWorks comes with non-gdb debuggers which only support strict
168 dwarf up to certain version. Default dwarf control to friendly
169 values for these. */
170
00f34291 171 if (!OPTION_SET_P (dwarf_strict))
7a9cf7e9
OH
172 dwarf_strict = 1;
173
00f34291 174 if (!OPTION_SET_P (dwarf_version))
824a2b3d 175 dwarf_version = VXWORKS_DWARF_VERSION_DEFAULT;
c05ece92
AO
176
177}
178
179/* We don't want to use library symbol __clear_cache on SR0640. Avoid
180 it and issue a direct call to cacheTextUpdate. It takes a size_t
181 length rather than the END address, so we have to compute it. */
182
183void
184vxworks_emit_call_builtin___clear_cache (rtx begin, rtx end)
185{
186 /* STATUS cacheTextUpdate (void *, size_t); */
187 rtx callee = gen_rtx_SYMBOL_REF (Pmode, "cacheTextUpdate");
188
189 enum machine_mode size_mode = TYPE_MODE (sizetype);
190
191 rtx len = simplify_gen_binary (MINUS, size_mode, end, begin);
192
193 emit_library_call (callee,
194 LCT_NORMAL, VOIDmode,
195 begin, ptr_mode,
196 len, size_mode);
ef672755 197}