* configure: Regenerated.
[official-gcc.git] / gcc / config / sol2.c
blobb15b895c70feb191412ffe1ad406f02ae3dd1e9e
1 /* General Solaris system support.
2 Copyright (C) 2004, 2005 , 2007, 2010, 2011, 2012
3 Free Software Foundation, Inc.
4 Contributed by CodeSourcery, LLC.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tree.h"
26 #include "output.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "target.h"
30 #include "tm_p.h"
31 #include "diagnostic-core.h"
32 #include "ggc.h"
33 #include "hashtab.h"
35 tree solaris_pending_aligns, solaris_pending_inits, solaris_pending_finis;
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. */
43 void
44 solaris_insert_attributes (tree decl, tree *attributes)
46 tree *x, next;
48 if (solaris_pending_aligns != NULL && TREE_CODE (decl) == VAR_DECL)
49 for (x = &solaris_pending_aligns; *x; x = &TREE_CHAIN (*x))
51 tree name = TREE_PURPOSE (*x);
52 tree value = TREE_VALUE (*x);
53 if (DECL_NAME (decl) == name)
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;
69 if (solaris_pending_inits != NULL && TREE_CODE (decl) == FUNCTION_DECL)
70 for (x = &solaris_pending_inits; *x; x = &TREE_CHAIN (*x))
72 tree name = TREE_PURPOSE (*x);
73 if (DECL_NAME (decl) == name)
75 *attributes = tree_cons (get_identifier ("init"), NULL,
76 *attributes);
77 TREE_USED (decl) = 1;
78 DECL_PRESERVE_P (decl) = 1;
79 next = TREE_CHAIN (*x);
80 ggc_free (*x);
81 *x = next;
82 break;
86 if (solaris_pending_finis != NULL && TREE_CODE (decl) == FUNCTION_DECL)
87 for (x = &solaris_pending_finis; *x; x = &TREE_CHAIN (*x))
89 tree name = TREE_PURPOSE (*x);
90 if (DECL_NAME (decl) == name)
92 *attributes = tree_cons (get_identifier ("fini"), NULL,
93 *attributes);
94 TREE_USED (decl) = 1;
95 DECL_PRESERVE_P (decl) = 1;
96 next = TREE_CHAIN (*x);
97 ggc_free (*x);
98 *x = next;
99 break;
104 /* Output initializer or finalizer entries for DECL to FILE. */
106 void
107 solaris_output_init_fini (FILE *file, tree decl)
109 if (lookup_attribute ("init", DECL_ATTRIBUTES (decl)))
111 fprintf (file, "\t.pushsection\t" SECTION_NAME_FORMAT "\n", ".init");
112 ASM_OUTPUT_CALL (file, decl);
113 fprintf (file, "\t.popsection\n");
116 if (lookup_attribute ("fini", DECL_ATTRIBUTES (decl)))
118 fprintf (file, "\t.pushsection\t" SECTION_NAME_FORMAT "\n", ".fini");
119 ASM_OUTPUT_CALL (file, decl);
120 fprintf (file, "\t.popsection\n");
124 /* Emit an assembler directive to set symbol for DECL visibility to
125 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
127 void
128 solaris_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
129 int vis ATTRIBUTE_UNUSED)
131 #ifdef HAVE_GAS_HIDDEN
132 /* Sun as uses .symbolic for STV_PROTECTED. STV_INTERNAL is marked as
133 `currently reserved', but the linker treats it like STV_HIDDEN. Sun
134 Studio 12.1 cc emits .hidden instead.
136 There are 3 Sun extensions GCC doesn't yet know about: STV_EXPORTED,
137 STV_SINGLETON, and STV_ELIMINATE.
139 See Linker and Libraries Guide, Ch. 2, Link-Editor, Defining
140 Additional Symbols, and Ch. 7, Object-File Format, Symbol Table
141 Section. */
143 static const char * const visibility_types[] = {
144 NULL, "symbolic", "hidden", "hidden"
147 const char *name, *type;
149 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
150 type = visibility_types[vis];
152 fprintf (asm_out_file, "\t.%s\t", type);
153 assemble_name (asm_out_file, name);
154 fprintf (asm_out_file, "\n");
155 #else
156 warning (OPT_Wattributes, "visibility attribute not supported "
157 "in this configuration; ignored");
158 #endif
161 /* Hash table of group signature symbols. */
163 static htab_t solaris_comdat_htab;
165 /* Group section information entry stored in solaris_comdat_htab. */
167 typedef struct comdat_entry
169 const char *name;
170 unsigned int flags;
171 tree decl;
172 const char *sig;
173 } comdat_entry;
175 /* Helper routines for maintaining solaris_comdat_htab. */
177 static hashval_t
178 comdat_hash (const void *p)
180 const comdat_entry *entry = (const comdat_entry *) p;
182 return htab_hash_string (entry->sig);
185 static int
186 comdat_eq (const void *p1, const void *p2)
188 const comdat_entry *entry1 = (const comdat_entry *) p1;
189 const comdat_entry *entry2 = (const comdat_entry *) p2;
191 return strcmp (entry1->sig, entry2->sig) == 0;
194 /* Output assembly to switch to COMDAT group section NAME with attributes
195 FLAGS and group signature symbol DECL, using Sun as syntax. */
197 void
198 solaris_elf_asm_comdat_section (const char *name, unsigned int flags, tree decl)
200 const char *signature;
201 char *section;
202 comdat_entry entry, **slot;
204 if (TREE_CODE (decl) == IDENTIFIER_NODE)
205 signature = IDENTIFIER_POINTER (decl);
206 else
207 signature = IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl));
209 /* Sun as requires group sections to be fragmented, i.e. to have names of
210 the form <section>%<fragment>. Strictly speaking this is only
211 necessary to support cc -xF, but is enforced globally in violation of
212 the ELF gABI. We keep the section names generated by GCC (generally
213 of the form .text.<signature>) and append %<signature> to pacify as,
214 despite the redundancy. */
215 section = concat (name, "%", signature, NULL);
217 /* Clear SECTION_LINKONCE flag so targetm.asm_out.named_section only
218 emits this as a regular section. Emit section before .group
219 directive since Sun as treats undeclared sections as @progbits,
220 which conflicts with .bss* sections which are @nobits. */
221 targetm.asm_out.named_section (section, flags & ~SECTION_LINKONCE, decl);
223 /* Sun as separates declaration of a group section and of the group
224 itself, using the .group directive and the #comdat flag. */
225 fprintf (asm_out_file, "\t.group\t%s," SECTION_NAME_FORMAT ",#comdat\n",
226 signature, section);
228 /* Unlike GNU as, group signature symbols need to be defined explicitly
229 for Sun as. With a few exceptions, this is already the case. To
230 identify the missing ones without changing the affected frontents,
231 remember the signature symbols and emit those not marked
232 TREE_SYMBOL_REFERENCED in solaris_file_end. */
233 if (solaris_comdat_htab == NULL)
234 solaris_comdat_htab = htab_create_alloc (37, comdat_hash, comdat_eq, NULL,
235 xcalloc, free);
237 entry.sig = signature;
238 slot = (comdat_entry **) htab_find_slot (solaris_comdat_htab, &entry, INSERT);
240 if (*slot == NULL)
242 *slot = XCNEW (comdat_entry);
243 /* Remember fragmented section name. */
244 (*slot)->name = section;
245 /* Emit as regular section, .group declaration has already been done. */
246 (*slot)->flags = flags & ~SECTION_LINKONCE;
247 (*slot)->decl = decl;
248 (*slot)->sig = signature;
252 /* Define unreferenced COMDAT group signature symbol corresponding to SLOT. */
254 static int
255 solaris_define_comdat_signature (void **slot, void *aux ATTRIBUTE_UNUSED)
257 comdat_entry *entry = *(comdat_entry **) slot;
258 tree decl = entry->decl;
260 if (TREE_CODE (decl) != IDENTIFIER_NODE)
261 decl = DECL_COMDAT_GROUP (decl);
263 if (!TREE_SYMBOL_REFERENCED (decl))
265 /* Switch to group section, otherwise Sun as complains
266 `Group Id symbol defined outside of group'. */
267 switch_to_section (get_section (entry->name, entry->flags, entry->decl));
269 ASM_OUTPUT_LABEL (asm_out_file, entry->sig);
272 /* Continue with scan. */
273 return 1;
276 /* Emit unreferenced COMDAT group signature symbols for Sun as. */
278 void
279 solaris_file_end (void)
281 if (solaris_comdat_htab == NULL)
282 return;
284 htab_traverse (solaris_comdat_htab, solaris_define_comdat_signature, NULL);
287 void
288 solaris_override_options (void)
290 /* Don't emit DWARF3/4 unless specifically selected. Solaris ld cannot
291 handle CIE version 3 in .eh_frame. */
292 if (!global_options_set.x_dwarf_version)
293 dwarf_version = 2;