]>
Commit | Line | Data |
---|---|---|
b2f4bed8 | 1 | /* Common VxWorks target definitions for GNU compiler. |
8d9254fc | 2 | Copyright (C) 2007-2020 Free Software Foundation, Inc. |
b2f4bed8 MM |
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 | |
2f83c7d6 | 9 | Software Foundation; either version 3, or (at your option) any later |
b2f4bed8 MM |
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 | |
2f83c7d6 NC |
18 | along 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" |
b2f4bed8 | 30 | |
eae016fc | 31 | #if !HAVE_INITFINI_ARRAY_SUPPORT |
b2f4bed8 MM |
32 | /* Like default_named_section_asm_out_constructor, except that even |
33 | constructors with DEFAULT_INIT_PRIORITY must go in a numbered | |
34 | section on VxWorks. The VxWorks runtime uses a clever trick to get | |
35 | the sentinel entry (-1) inserted at the beginning of the .ctors | |
36 | segment. This trick will not work if we ever generate any entries | |
37 | in plain .ctors sections; we must always use .ctors.PRIORITY. */ | |
38 | ||
39 | void | |
40 | vxworks_asm_out_constructor (rtx symbol, int priority) | |
41 | { | |
42 | section *sec; | |
43 | ||
44 | sec = get_cdtor_priority_section (priority, | |
45 | /*constructor_p=*/true); | |
46 | assemble_addr_to_section (symbol, sec); | |
47 | } | |
48 | ||
49 | /* See comment for vxworks_asm_out_constructor. */ | |
50 | ||
51 | void | |
52 | vxworks_asm_out_destructor (rtx symbol, int priority) | |
53 | { | |
54 | section *sec; | |
55 | ||
56 | sec = get_cdtor_priority_section (priority, | |
57 | /*constructor_p=*/false); | |
58 | assemble_addr_to_section (symbol, sec); | |
59 | } | |
eae016fc | 60 | #endif |
ef672755 | 61 | |
feb60f03 NS |
62 | /* Return the list of FIELD_DECLs that make up an emulated TLS |
63 | variable's control object. TYPE is the structure these are fields | |
64 | of and *NAME will be filled in with the structure tag that should | |
65 | be used. */ | |
66 | ||
67 | static tree | |
68 | vxworks_emutls_var_fields (tree type, tree *name) | |
69 | { | |
70 | tree field, next_field; | |
71 | ||
72 | *name = get_identifier ("__tls_var"); | |
73 | ||
7703295f RH |
74 | field = build_decl (BUILTINS_LOCATION, FIELD_DECL, |
75 | get_identifier ("size"), unsigned_type_node); | |
feb60f03 NS |
76 | DECL_CONTEXT (field) = type; |
77 | next_field = field; | |
78 | ||
7703295f RH |
79 | field = build_decl (BUILTINS_LOCATION, FIELD_DECL, |
80 | get_identifier ("module_id"), unsigned_type_node); | |
feb60f03 | 81 | DECL_CONTEXT (field) = type; |
910ad8de | 82 | DECL_CHAIN (field) = next_field; |
feb60f03 NS |
83 | next_field = field; |
84 | ||
a93e7e14 | 85 | /* The offset field is declared as an unsigned int with pointer mode. */ |
7703295f | 86 | field = build_decl (BUILTINS_LOCATION, FIELD_DECL, |
a93e7e14 JL |
87 | get_identifier ("offset"), long_unsigned_type_node); |
88 | ||
feb60f03 | 89 | DECL_CONTEXT (field) = type; |
910ad8de | 90 | DECL_CHAIN (field) = next_field; |
feb60f03 NS |
91 | |
92 | return field; | |
93 | } | |
94 | ||
95 | /* Return the CONSTRUCTOR to initialize an emulated TLS control | |
96 | object. VAR is the control object. DECL is the TLS object itself | |
97 | and TMPL_ADDR is the address (an ADDR_EXPR) of the initializer for | |
98 | that object. */ | |
99 | ||
100 | static tree | |
101 | vxworks_emutls_var_init (tree var, tree decl, tree tmpl_addr) | |
102 | { | |
9771b263 DN |
103 | vec<constructor_elt, va_gc> *v; |
104 | vec_alloc (v, 3); | |
feb60f03 NS |
105 | |
106 | tree type = TREE_TYPE (var); | |
107 | tree field = TYPE_FIELDS (type); | |
108 | ||
fc1bc21b | 109 | constructor_elt elt = {field, fold_convert (TREE_TYPE (field), tmpl_addr)}; |
9771b263 | 110 | v->quick_push (elt); |
feb60f03 | 111 | |
910ad8de | 112 | field = DECL_CHAIN (field); |
fc1bc21b DN |
113 | elt.index = field; |
114 | elt.value = build_int_cst (TREE_TYPE (field), 0); | |
9771b263 | 115 | v->quick_push (elt); |
feb60f03 | 116 | |
910ad8de | 117 | field = DECL_CHAIN (field); |
fc1bc21b DN |
118 | elt.index = field; |
119 | elt.value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl)); | |
9771b263 | 120 | v->quick_push (elt); |
feb60f03 NS |
121 | |
122 | return build_constructor (type, v); | |
123 | } | |
124 | ||
c5387660 | 125 | /* Do VxWorks-specific parts of TARGET_OPTION_OVERRIDE. */ |
ef672755 RS |
126 | |
127 | void | |
128 | vxworks_override_options (void) | |
129 | { | |
931fae81 JL |
130 | /* Setup the tls emulation bits if the OS misses proper |
131 | tls support. */ | |
132 | targetm.have_tls = VXWORKS_HAVE_TLS; | |
133 | ||
134 | if (!VXWORKS_HAVE_TLS) | |
135 | { | |
136 | targetm.emutls.get_address = "__builtin___tls_lookup"; | |
137 | targetm.emutls.register_common = NULL; | |
138 | targetm.emutls.var_section = ".tls_vars"; | |
139 | targetm.emutls.tmpl_section = ".tls_data"; | |
140 | targetm.emutls.var_prefix = "__tls__"; | |
141 | targetm.emutls.tmpl_prefix = ""; | |
142 | targetm.emutls.var_fields = vxworks_emutls_var_fields; | |
143 | targetm.emutls.var_init = vxworks_emutls_var_init; | |
144 | targetm.emutls.var_align_fixed = true; | |
145 | targetm.emutls.debug_form_tls_address = true; | |
146 | } | |
147 | ||
7f37b31d JL |
148 | /* Arrange to use .ctors/.dtors sections if the target VxWorks configuration |
149 | and mode supports it, or the init/fini_array sections if we were | |
150 | configured with --enable-initfini-array explicitly. In the latter case, | |
151 | the toolchain user is expected to provide whatever linker level glue is | |
152 | required to get things to operate properly. */ | |
153 | ||
154 | targetm.have_ctors_dtors = | |
155 | TARGET_VXWORKS_HAVE_CTORS_DTORS || HAVE_INITFINI_ARRAY_SUPPORT; | |
ef672755 RS |
156 | |
157 | /* PIC is only supported for RTPs. */ | |
158 | if (flag_pic && !TARGET_VXWORKS_RTP) | |
159 | error ("PIC is only supported for RTPs"); | |
7a9cf7e9 | 160 | |
824a2b3d OH |
161 | /* VxWorks comes with non-gdb debuggers which only support strict |
162 | dwarf up to certain version. Default dwarf control to friendly | |
163 | values for these. */ | |
164 | ||
98095aa3 | 165 | if (!global_options_set.x_dwarf_strict) |
7a9cf7e9 OH |
166 | dwarf_strict = 1; |
167 | ||
98095aa3 | 168 | if (!global_options_set.x_dwarf_version) |
824a2b3d | 169 | dwarf_version = VXWORKS_DWARF_VERSION_DEFAULT; |
ef672755 | 170 | } |