Implement TARGET_IRA_CHANGE_PSEUDO_ALLOCNO_CLASS hook.
[official-gcc.git] / gcc / config / sol2.c
blob9eb889aebb6f5cf825a52f67bb88868d65e237fe
1 /* General Solaris system support.
2 Copyright (C) 2004-2015 Free Software Foundation, Inc.
3 Contributed by CodeSourcery, LLC.
5 This file is part of GCC.
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.
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.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "input.h"
25 #include "alias.h"
26 #include "symtab.h"
27 #include "options.h"
28 #include "tree.h"
29 #include "stringpool.h"
30 #include "varasm.h"
31 #include "output.h"
32 #include "tm.h"
33 #include "rtl.h"
34 #include "target.h"
35 #include "tm_p.h"
36 #include "diagnostic-core.h"
38 tree solaris_pending_aligns, solaris_pending_inits, solaris_pending_finis;
40 /* Attach any pending attributes for DECL to the list in *ATTRIBUTES.
41 Pending attributes come from #pragma or _Pragma, so this code is
42 only useful in the C family front ends, but it is included in
43 all languages to avoid changing the target machine initializer
44 depending on the language. */
46 void
47 solaris_insert_attributes (tree decl, tree *attributes)
49 tree *x, next;
51 if (solaris_pending_aligns != NULL && TREE_CODE (decl) == VAR_DECL)
52 for (x = &solaris_pending_aligns; *x; x = &TREE_CHAIN (*x))
54 tree name = TREE_PURPOSE (*x);
55 tree value = TREE_VALUE (*x);
56 if (DECL_NAME (decl) == name)
58 if (lookup_attribute ("aligned", DECL_ATTRIBUTES (decl))
59 || lookup_attribute ("aligned", *attributes))
60 warning (0, "ignoring %<#pragma align%> for explicitly "
61 "aligned %q+D", decl);
62 else
63 *attributes = tree_cons (get_identifier ("aligned"), value,
64 *attributes);
65 next = TREE_CHAIN (*x);
66 ggc_free (*x);
67 *x = next;
68 break;
72 if (solaris_pending_inits != NULL && TREE_CODE (decl) == FUNCTION_DECL)
73 for (x = &solaris_pending_inits; *x; x = &TREE_CHAIN (*x))
75 tree name = TREE_PURPOSE (*x);
76 if (DECL_NAME (decl) == name)
78 *attributes = tree_cons (get_identifier ("init"), NULL,
79 *attributes);
80 TREE_USED (decl) = 1;
81 DECL_PRESERVE_P (decl) = 1;
82 next = TREE_CHAIN (*x);
83 ggc_free (*x);
84 *x = next;
85 break;
89 if (solaris_pending_finis != NULL && TREE_CODE (decl) == FUNCTION_DECL)
90 for (x = &solaris_pending_finis; *x; x = &TREE_CHAIN (*x))
92 tree name = TREE_PURPOSE (*x);
93 if (DECL_NAME (decl) == name)
95 *attributes = tree_cons (get_identifier ("fini"), NULL,
96 *attributes);
97 TREE_USED (decl) = 1;
98 DECL_PRESERVE_P (decl) = 1;
99 next = TREE_CHAIN (*x);
100 ggc_free (*x);
101 *x = next;
102 break;
107 /* Output initializer or finalizer entries for DECL to FILE. */
109 void
110 solaris_output_init_fini (FILE *file, tree decl)
112 if (lookup_attribute ("init", DECL_ATTRIBUTES (decl)))
114 fprintf (file, "\t.pushsection\t" SECTION_NAME_FORMAT "\n", ".init");
115 ASM_OUTPUT_CALL (file, decl);
116 fprintf (file, "\t.popsection\n");
119 if (lookup_attribute ("fini", DECL_ATTRIBUTES (decl)))
121 fprintf (file, "\t.pushsection\t" SECTION_NAME_FORMAT "\n", ".fini");
122 ASM_OUTPUT_CALL (file, decl);
123 fprintf (file, "\t.popsection\n");
127 /* Emit an assembler directive to set symbol for DECL visibility to
128 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
130 void
131 solaris_assemble_visibility (tree decl, int vis ATTRIBUTE_UNUSED)
133 #ifdef HAVE_GAS_HIDDEN
134 /* Sun as uses .symbolic for STV_PROTECTED. STV_INTERNAL is marked as
135 `currently reserved', but the linker treats it like STV_HIDDEN. Sun
136 Studio 12.1 cc emits .hidden instead.
138 There are 3 Sun extensions GCC doesn't yet know about: STV_EXPORTED,
139 STV_SINGLETON, and STV_ELIMINATE.
141 See Linker and Libraries Guide, Ch. 2, Link-Editor, Defining
142 Additional Symbols, and Ch. 7, Object-File Format, Symbol Table
143 Section. */
145 static const char * const visibility_types[] = {
146 NULL, "symbolic", "hidden", "hidden"
149 const char *name, *type;
151 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
152 type = visibility_types[vis];
154 fprintf (asm_out_file, "\t.%s\t", type);
155 assemble_name (asm_out_file, name);
156 fprintf (asm_out_file, "\n");
157 #else
158 if (!DECL_ARTIFICIAL (decl))
159 warning (OPT_Wattributes, "visibility attribute not supported "
160 "in this configuration; ignored");
161 #endif
164 /* Group section information entry stored in solaris_comdat_htab. */
166 typedef struct comdat_entry
168 const char *name;
169 unsigned int flags;
170 tree decl;
171 const char *sig;
172 } comdat_entry;
174 /* Helpers for maintaining solaris_comdat_htab. */
176 struct comdat_entry_hasher : typed_noop_remove <comdat_entry>
178 typedef comdat_entry *value_type;
179 typedef comdat_entry *compare_type;
180 static inline hashval_t hash (const comdat_entry *);
181 static inline bool equal (const comdat_entry *, const comdat_entry *);
182 static inline void remove (comdat_entry *);
185 inline hashval_t
186 comdat_entry_hasher::hash (const comdat_entry *entry)
188 return htab_hash_string (entry->sig);
191 inline bool
192 comdat_entry_hasher::equal (const comdat_entry *entry1,
193 const comdat_entry *entry2)
195 return strcmp (entry1->sig, entry2->sig) == 0;
198 /* Hash table of group signature symbols. */
200 static hash_table<comdat_entry_hasher> *solaris_comdat_htab;
202 /* Output assembly to switch to COMDAT group section NAME with attributes
203 FLAGS and group signature symbol DECL, using Sun as syntax. */
205 void
206 solaris_elf_asm_comdat_section (const char *name, unsigned int flags, tree decl)
208 const char *signature;
209 char *section;
210 comdat_entry entry, **slot;
212 if (TREE_CODE (decl) == IDENTIFIER_NODE)
213 signature = IDENTIFIER_POINTER (decl);
214 else
215 signature = IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl));
217 /* Sun as requires group sections to be fragmented, i.e. to have names of
218 the form <section>%<fragment>. Strictly speaking this is only
219 necessary to support cc -xF, but is enforced globally in violation of
220 the ELF gABI. We keep the section names generated by GCC (generally
221 of the form .text.<signature>) and append %<signature> to pacify as,
222 despite the redundancy. */
223 section = concat (name, "%", signature, NULL);
225 /* Clear SECTION_LINKONCE flag so targetm.asm_out.named_section only
226 emits this as a regular section. Emit section before .group
227 directive since Sun as treats undeclared sections as @progbits,
228 which conflicts with .bss* sections which are @nobits. */
229 targetm.asm_out.named_section (section, flags & ~SECTION_LINKONCE, decl);
231 /* Sun as separates declaration of a group section and of the group
232 itself, using the .group directive and the #comdat flag. */
233 fprintf (asm_out_file, "\t.group\t%s," SECTION_NAME_FORMAT ",#comdat\n",
234 signature, section);
236 /* Unlike GNU as, group signature symbols need to be defined explicitly
237 for Sun as. With a few exceptions, this is already the case. To
238 identify the missing ones without changing the affected frontents,
239 remember the signature symbols and emit those not marked
240 TREE_SYMBOL_REFERENCED in solaris_file_end. */
241 if (!solaris_comdat_htab)
242 solaris_comdat_htab = new hash_table<comdat_entry_hasher> (37);
244 entry.sig = signature;
245 slot = solaris_comdat_htab->find_slot (&entry, INSERT);
247 if (*slot == NULL)
249 *slot = XCNEW (comdat_entry);
250 /* Remember fragmented section name. */
251 (*slot)->name = section;
252 /* Emit as regular section, .group declaration has already been done. */
253 (*slot)->flags = flags & ~SECTION_LINKONCE;
254 (*slot)->decl = decl;
255 (*slot)->sig = signature;
259 /* Define unreferenced COMDAT group signature symbol corresponding to SLOT. */
262 solaris_define_comdat_signature (comdat_entry **slot,
263 void *aux ATTRIBUTE_UNUSED)
265 comdat_entry *entry = *slot;
266 tree decl = entry->decl;
268 if (TREE_CODE (decl) != IDENTIFIER_NODE)
269 decl = DECL_COMDAT_GROUP (decl);
271 if (!TREE_SYMBOL_REFERENCED (decl))
273 /* Switch to group section, otherwise Sun as complains
274 `Group Id symbol defined outside of group'. */
275 switch_to_section (get_section (entry->name, entry->flags, entry->decl));
277 ASM_OUTPUT_LABEL (asm_out_file, entry->sig);
280 /* Continue with scan. */
281 return 1;
284 /* Emit unreferenced COMDAT group signature symbols for Sun as. */
286 void
287 solaris_file_end (void)
289 if (!solaris_comdat_htab)
290 return;
292 solaris_comdat_htab->traverse <void *, solaris_define_comdat_signature>
293 (NULL);
296 void
297 solaris_override_options (void)
299 /* Older versions of Solaris ld cannot handle CIE version 3 in .eh_frame.
300 Don't emit DWARF3/4 unless specifically selected if so. */
301 if (!HAVE_LD_EH_FRAME_CIEV3 && !global_options_set.x_dwarf_version)
302 dwarf_version = 2;