Mercurial > hg > CbC > CbC_gcc
annotate gcc/config/sol2.c @ 158:494b0b89df80 default tip
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 18:13:55 +0900 |
parents | 1830386684a0 |
children |
rev | line source |
---|---|
0 | 1 /* General Solaris system support. |
145 | 2 Copyright (C) 2004-2020 Free Software Foundation, Inc. |
0 | 3 Contributed by CodeSourcery, LLC. |
4 | |
5 This file is part of GCC. | |
6 | |
7 GCC is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation; either version 3, or (at your option) | |
10 any later version. | |
11 | |
12 GCC is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License 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" | |
111 | 24 #include "target.h" |
0 | 25 #include "rtl.h" |
111 | 26 #include "tree.h" |
27 #include "memmodel.h" | |
0 | 28 #include "tm_p.h" |
111 | 29 #include "stringpool.h" |
30 #include "attribs.h" | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
31 #include "diagnostic-core.h" |
111 | 32 #include "varasm.h" |
33 #include "output.h" | |
0 | 34 |
35 tree solaris_pending_aligns, solaris_pending_inits, solaris_pending_finis; | |
36 | |
37 /* Attach any pending attributes for DECL to the list in *ATTRIBUTES. | |
38 Pending attributes come from #pragma or _Pragma, so this code is | |
39 only useful in the C family front ends, but it is included in | |
40 all languages to avoid changing the target machine initializer | |
41 depending on the language. */ | |
42 | |
43 void | |
44 solaris_insert_attributes (tree decl, tree *attributes) | |
45 { | |
46 tree *x, next; | |
47 | |
48 if (solaris_pending_aligns != NULL && TREE_CODE (decl) == VAR_DECL) | |
49 for (x = &solaris_pending_aligns; *x; x = &TREE_CHAIN (*x)) | |
50 { | |
51 tree name = TREE_PURPOSE (*x); | |
52 tree value = TREE_VALUE (*x); | |
53 if (DECL_NAME (decl) == name) | |
54 { | |
55 if (lookup_attribute ("aligned", DECL_ATTRIBUTES (decl)) | |
56 || lookup_attribute ("aligned", *attributes)) | |
57 warning (0, "ignoring %<#pragma align%> for explicitly " | |
58 "aligned %q+D", decl); | |
59 else | |
60 *attributes = tree_cons (get_identifier ("aligned"), value, | |
61 *attributes); | |
62 next = TREE_CHAIN (*x); | |
63 ggc_free (*x); | |
64 *x = next; | |
65 break; | |
66 } | |
67 } | |
68 | |
69 if (solaris_pending_inits != NULL && TREE_CODE (decl) == FUNCTION_DECL) | |
70 for (x = &solaris_pending_inits; *x; x = &TREE_CHAIN (*x)) | |
71 { | |
72 tree name = TREE_PURPOSE (*x); | |
73 if (DECL_NAME (decl) == name) | |
74 { | |
75 *attributes = tree_cons (get_identifier ("init"), NULL, | |
76 *attributes); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
77 TREE_USED (decl) = 1; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
78 DECL_PRESERVE_P (decl) = 1; |
0 | 79 next = TREE_CHAIN (*x); |
80 ggc_free (*x); | |
81 *x = next; | |
82 break; | |
83 } | |
84 } | |
85 | |
86 if (solaris_pending_finis != NULL && TREE_CODE (decl) == FUNCTION_DECL) | |
87 for (x = &solaris_pending_finis; *x; x = &TREE_CHAIN (*x)) | |
88 { | |
89 tree name = TREE_PURPOSE (*x); | |
90 if (DECL_NAME (decl) == name) | |
91 { | |
92 *attributes = tree_cons (get_identifier ("fini"), NULL, | |
93 *attributes); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
94 TREE_USED (decl) = 1; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
95 DECL_PRESERVE_P (decl) = 1; |
0 | 96 next = TREE_CHAIN (*x); |
97 ggc_free (*x); | |
98 *x = next; | |
99 break; | |
100 } | |
101 } | |
102 } | |
103 | |
104 /* Output initializer or finalizer entries for DECL to FILE. */ | |
105 | |
106 void | |
107 solaris_output_init_fini (FILE *file, tree decl) | |
108 { | |
109 if (lookup_attribute ("init", DECL_ATTRIBUTES (decl))) | |
110 { | |
111 | 111 fprintf (file, "\t.pushsection\t" SECTION_NAME_FORMAT "\n", ".init"); |
0 | 112 ASM_OUTPUT_CALL (file, decl); |
113 fprintf (file, "\t.popsection\n"); | |
114 } | |
115 | |
116 if (lookup_attribute ("fini", DECL_ATTRIBUTES (decl))) | |
117 { | |
111 | 118 fprintf (file, "\t.pushsection\t" SECTION_NAME_FORMAT "\n", ".fini"); |
0 | 119 ASM_OUTPUT_CALL (file, decl); |
120 fprintf (file, "\t.popsection\n"); | |
121 } | |
122 } | |
123 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
124 /* Emit an assembler directive to set symbol for DECL visibility to |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
125 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
126 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
127 void |
111 | 128 solaris_assemble_visibility (tree decl, int vis ATTRIBUTE_UNUSED) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
129 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
130 #ifdef HAVE_GAS_HIDDEN |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
131 /* Sun as uses .symbolic for STV_PROTECTED. STV_INTERNAL is marked as |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
132 `currently reserved', but the linker treats it like STV_HIDDEN. Sun |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
133 Studio 12.1 cc emits .hidden instead. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
134 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
135 There are 3 Sun extensions GCC doesn't yet know about: STV_EXPORTED, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
136 STV_SINGLETON, and STV_ELIMINATE. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
137 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
138 See Linker and Libraries Guide, Ch. 2, Link-Editor, Defining |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
139 Additional Symbols, and Ch. 7, Object-File Format, Symbol Table |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
140 Section. */ |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
141 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
142 static const char * const visibility_types[] = { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
143 NULL, "symbolic", "hidden", "hidden" |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
144 }; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
145 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
146 const char *name, *type; |
111 | 147 tree id = DECL_ASSEMBLER_NAME (decl); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
148 |
111 | 149 while (IDENTIFIER_TRANSPARENT_ALIAS (id)) |
150 id = TREE_CHAIN (id); | |
151 name = IDENTIFIER_POINTER (id); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
152 type = visibility_types[vis]; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
153 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
154 fprintf (asm_out_file, "\t.%s\t", type); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
155 assemble_name (asm_out_file, name); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
156 fprintf (asm_out_file, "\n"); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
157 #else |
111 | 158 if (!DECL_ARTIFICIAL (decl)) |
159 warning (OPT_Wattributes, "visibility attribute not supported " | |
160 "in this configuration; ignored"); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
161 #endif |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
162 } |
111 | 163 |
164 /* Group section information entry stored in solaris_comdat_htab. */ | |
165 | |
166 typedef struct comdat_entry | |
167 { | |
168 const char *name; | |
169 unsigned int flags; | |
170 tree decl; | |
171 const char *sig; | |
172 } comdat_entry; | |
173 | |
174 /* Helpers for maintaining solaris_comdat_htab. */ | |
175 | |
176 struct comdat_entry_hasher : nofree_ptr_hash <comdat_entry> | |
177 { | |
178 static inline hashval_t hash (const comdat_entry *); | |
179 static inline bool equal (const comdat_entry *, const comdat_entry *); | |
180 static inline void remove (comdat_entry *); | |
181 }; | |
182 | |
183 inline hashval_t | |
184 comdat_entry_hasher::hash (const comdat_entry *entry) | |
185 { | |
186 return htab_hash_string (entry->sig); | |
187 } | |
188 | |
189 inline bool | |
190 comdat_entry_hasher::equal (const comdat_entry *entry1, | |
191 const comdat_entry *entry2) | |
192 { | |
193 return strcmp (entry1->sig, entry2->sig) == 0; | |
194 } | |
195 | |
196 /* Hash table of group signature symbols. */ | |
197 | |
198 static hash_table<comdat_entry_hasher> *solaris_comdat_htab; | |
199 | |
200 /* Output assembly to switch to COMDAT group section NAME with attributes | |
201 FLAGS and group signature symbol DECL, using Sun as syntax. */ | |
202 | |
203 void | |
204 solaris_elf_asm_comdat_section (const char *name, unsigned int flags, tree decl) | |
205 { | |
206 const char *signature; | |
207 char *section; | |
208 comdat_entry entry, **slot; | |
209 | |
210 if (TREE_CODE (decl) == IDENTIFIER_NODE) | |
211 signature = IDENTIFIER_POINTER (decl); | |
212 else | |
213 signature = IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)); | |
214 | |
215 /* Sun as requires group sections to be fragmented, i.e. to have names of | |
216 the form <section>%<fragment>. Strictly speaking this is only | |
217 necessary to support cc -xF, but is enforced globally in violation of | |
218 the ELF gABI. We keep the section names generated by GCC (generally | |
219 of the form .text.<signature>) and append %<signature> to pacify as, | |
220 despite the redundancy. */ | |
221 section = concat (name, "%", signature, NULL); | |
222 | |
223 /* Clear SECTION_LINKONCE flag so targetm.asm_out.named_section only | |
224 emits this as a regular section. Emit section before .group | |
225 directive since Sun as treats undeclared sections as @progbits, | |
226 which conflicts with .bss* sections which are @nobits. */ | |
227 targetm.asm_out.named_section (section, flags & ~SECTION_LINKONCE, decl); | |
228 | |
229 /* Sun as separates declaration of a group section and of the group | |
230 itself, using the .group directive and the #comdat flag. */ | |
231 fprintf (asm_out_file, "\t.group\t%s," SECTION_NAME_FORMAT ",#comdat\n", | |
232 signature, section); | |
233 | |
234 /* Unlike GNU as, group signature symbols need to be defined explicitly | |
235 for Sun as. With a few exceptions, this is already the case. To | |
236 identify the missing ones without changing the affected frontents, | |
237 remember the signature symbols and emit those not marked | |
238 TREE_SYMBOL_REFERENCED in solaris_file_end. */ | |
239 if (!solaris_comdat_htab) | |
240 solaris_comdat_htab = new hash_table<comdat_entry_hasher> (37); | |
241 | |
242 entry.sig = signature; | |
243 slot = solaris_comdat_htab->find_slot (&entry, INSERT); | |
244 | |
245 if (*slot == NULL) | |
246 { | |
247 *slot = XCNEW (comdat_entry); | |
248 /* Remember fragmented section name. */ | |
249 (*slot)->name = section; | |
250 /* Emit as regular section, .group declaration has already been done. */ | |
251 (*slot)->flags = flags & ~SECTION_LINKONCE; | |
252 (*slot)->decl = decl; | |
253 (*slot)->sig = signature; | |
254 } | |
255 } | |
256 | |
257 /* Define unreferenced COMDAT group signature symbol corresponding to SLOT. */ | |
258 | |
259 int | |
260 solaris_define_comdat_signature (comdat_entry **slot, | |
261 void *aux ATTRIBUTE_UNUSED) | |
262 { | |
263 comdat_entry *entry = *slot; | |
264 tree decl = entry->decl; | |
265 | |
266 if (TREE_CODE (decl) != IDENTIFIER_NODE) | |
267 decl = DECL_COMDAT_GROUP (decl); | |
268 | |
269 if (!TREE_SYMBOL_REFERENCED (decl)) | |
270 { | |
271 /* Switch to group section, otherwise Sun as complains | |
272 `Group Id symbol defined outside of group'. */ | |
273 switch_to_section (get_section (entry->name, entry->flags, entry->decl)); | |
274 | |
275 ASM_OUTPUT_LABEL (asm_out_file, entry->sig); | |
276 } | |
277 | |
278 /* Continue with scan. */ | |
279 return 1; | |
280 } | |
281 | |
282 /* Emit unreferenced COMDAT group signature symbols for Sun as. */ | |
283 | |
284 void | |
285 solaris_file_end (void) | |
286 { | |
287 if (!solaris_comdat_htab) | |
288 return; | |
289 | |
290 solaris_comdat_htab->traverse <void *, solaris_define_comdat_signature> | |
291 (NULL); | |
292 } | |
293 | |
294 void | |
295 solaris_override_options (void) | |
296 { | |
297 /* Older versions of Solaris ld cannot handle CIE version 3 in .eh_frame. | |
298 Don't emit DWARF3/4 unless specifically selected if so. */ | |
299 if (!HAVE_LD_EH_FRAME_CIEV3 && !global_options_set.x_dwarf_version) | |
300 dwarf_version = 2; | |
301 } |