]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/vxworks.c
Update copyright years.
[thirdparty/gcc.git] / gcc / config / vxworks.c
1 /* Common VxWorks target definitions for GNU compiler.
2 Copyright (C) 2007-2021 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
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. */
41
42 void
43 vxworks_asm_out_constructor (rtx symbol, int priority)
44 {
45 section *sec;
46
47 sec = get_cdtor_priority_section (priority,
48 /*constructor_p=*/true);
49 assemble_addr_to_section (symbol, sec);
50 }
51
52 /* See comment for vxworks_asm_out_constructor. */
53
54 void
55 vxworks_asm_out_destructor (rtx symbol, int priority)
56 {
57 section *sec;
58
59 sec = get_cdtor_priority_section (priority,
60 /*constructor_p=*/false);
61 assemble_addr_to_section (symbol, sec);
62 }
63 #endif
64
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
68 be used. */
69
70 static tree
71 vxworks_emutls_var_fields (tree type, tree *name)
72 {
73 tree field, next_field;
74
75 *name = get_identifier ("__tls_var");
76
77 field = build_decl (BUILTINS_LOCATION, FIELD_DECL,
78 get_identifier ("size"), unsigned_type_node);
79 DECL_CONTEXT (field) = type;
80 next_field = field;
81
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;
86 next_field = field;
87
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);
91
92 DECL_CONTEXT (field) = type;
93 DECL_CHAIN (field) = next_field;
94
95 return field;
96 }
97
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
101 that object. */
102
103 static tree
104 vxworks_emutls_var_init (tree var, tree decl, tree tmpl_addr)
105 {
106 vec<constructor_elt, va_gc> *v;
107 vec_alloc (v, 3);
108
109 tree type = TREE_TYPE (var);
110 tree field = TYPE_FIELDS (type);
111
112 constructor_elt elt = {field, fold_convert (TREE_TYPE (field), tmpl_addr)};
113 v->quick_push (elt);
114
115 field = DECL_CHAIN (field);
116 elt.index = field;
117 elt.value = build_int_cst (TREE_TYPE (field), 0);
118 v->quick_push (elt);
119
120 field = DECL_CHAIN (field);
121 elt.index = field;
122 elt.value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
123 v->quick_push (elt);
124
125 return build_constructor (type, v);
126 }
127
128 /* Do VxWorks-specific parts of TARGET_OPTION_OVERRIDE. */
129
130 void
131 vxworks_override_options (void)
132 {
133 /* Setup the tls emulation bits if the OS misses proper
134 tls support. */
135 targetm.have_tls = VXWORKS_HAVE_TLS;
136
137 if (!VXWORKS_HAVE_TLS)
138 {
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;
149 }
150
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. */
156
157 targetm.have_ctors_dtors =
158 TARGET_VXWORKS_HAVE_CTORS_DTORS || HAVE_INITFINI_ARRAY_SUPPORT;
159
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");
165
166 /* VxWorks comes with non-gdb debuggers which only support strict
167 dwarf up to certain version. Default dwarf control to friendly
168 values for these. */
169
170 if (!global_options_set.x_dwarf_strict)
171 dwarf_strict = 1;
172
173 if (!global_options_set.x_dwarf_version)
174 dwarf_version = VXWORKS_DWARF_VERSION_DEFAULT;
175
176 }
177
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. */
181
182 void
183 vxworks_emit_call_builtin___clear_cache (rtx begin, rtx end)
184 {
185 /* STATUS cacheTextUpdate (void *, size_t); */
186 rtx callee = gen_rtx_SYMBOL_REF (Pmode, "cacheTextUpdate");
187
188 enum machine_mode size_mode = TYPE_MODE (sizetype);
189
190 rtx len = simplify_gen_binary (MINUS, size_mode, end, begin);
191
192 emit_library_call (callee,
193 LCT_NORMAL, VOIDmode,
194 begin, ptr_mode,
195 len, size_mode);
196 }