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)
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/>. */
23 #include "coretypes.h"
27 #include "double-int.h"
35 #include "stringpool.h"
42 #include "diagnostic-core.h"
44 #include "hash-table.h"
46 tree solaris_pending_aligns
, solaris_pending_inits
, solaris_pending_finis
;
48 /* Attach any pending attributes for DECL to the list in *ATTRIBUTES.
49 Pending attributes come from #pragma or _Pragma, so this code is
50 only useful in the C family front ends, but it is included in
51 all languages to avoid changing the target machine initializer
52 depending on the language. */
55 solaris_insert_attributes (tree decl
, tree
*attributes
)
59 if (solaris_pending_aligns
!= NULL
&& TREE_CODE (decl
) == VAR_DECL
)
60 for (x
= &solaris_pending_aligns
; *x
; x
= &TREE_CHAIN (*x
))
62 tree name
= TREE_PURPOSE (*x
);
63 tree value
= TREE_VALUE (*x
);
64 if (DECL_NAME (decl
) == name
)
66 if (lookup_attribute ("aligned", DECL_ATTRIBUTES (decl
))
67 || lookup_attribute ("aligned", *attributes
))
68 warning (0, "ignoring %<#pragma align%> for explicitly "
69 "aligned %q+D", decl
);
71 *attributes
= tree_cons (get_identifier ("aligned"), value
,
73 next
= TREE_CHAIN (*x
);
80 if (solaris_pending_inits
!= NULL
&& TREE_CODE (decl
) == FUNCTION_DECL
)
81 for (x
= &solaris_pending_inits
; *x
; x
= &TREE_CHAIN (*x
))
83 tree name
= TREE_PURPOSE (*x
);
84 if (DECL_NAME (decl
) == name
)
86 *attributes
= tree_cons (get_identifier ("init"), NULL
,
89 DECL_PRESERVE_P (decl
) = 1;
90 next
= TREE_CHAIN (*x
);
97 if (solaris_pending_finis
!= NULL
&& TREE_CODE (decl
) == FUNCTION_DECL
)
98 for (x
= &solaris_pending_finis
; *x
; x
= &TREE_CHAIN (*x
))
100 tree name
= TREE_PURPOSE (*x
);
101 if (DECL_NAME (decl
) == name
)
103 *attributes
= tree_cons (get_identifier ("fini"), NULL
,
105 TREE_USED (decl
) = 1;
106 DECL_PRESERVE_P (decl
) = 1;
107 next
= TREE_CHAIN (*x
);
115 /* Output initializer or finalizer entries for DECL to FILE. */
118 solaris_output_init_fini (FILE *file
, tree decl
)
120 if (lookup_attribute ("init", DECL_ATTRIBUTES (decl
)))
122 fprintf (file
, "\t.pushsection\t" SECTION_NAME_FORMAT
"\n", ".init");
123 ASM_OUTPUT_CALL (file
, decl
);
124 fprintf (file
, "\t.popsection\n");
127 if (lookup_attribute ("fini", DECL_ATTRIBUTES (decl
)))
129 fprintf (file
, "\t.pushsection\t" SECTION_NAME_FORMAT
"\n", ".fini");
130 ASM_OUTPUT_CALL (file
, decl
);
131 fprintf (file
, "\t.popsection\n");
135 /* Emit an assembler directive to set symbol for DECL visibility to
136 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
139 solaris_assemble_visibility (tree decl
, int vis ATTRIBUTE_UNUSED
)
141 #ifdef HAVE_GAS_HIDDEN
142 /* Sun as uses .symbolic for STV_PROTECTED. STV_INTERNAL is marked as
143 `currently reserved', but the linker treats it like STV_HIDDEN. Sun
144 Studio 12.1 cc emits .hidden instead.
146 There are 3 Sun extensions GCC doesn't yet know about: STV_EXPORTED,
147 STV_SINGLETON, and STV_ELIMINATE.
149 See Linker and Libraries Guide, Ch. 2, Link-Editor, Defining
150 Additional Symbols, and Ch. 7, Object-File Format, Symbol Table
153 static const char * const visibility_types
[] = {
154 NULL
, "symbolic", "hidden", "hidden"
157 const char *name
, *type
;
159 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
160 type
= visibility_types
[vis
];
162 fprintf (asm_out_file
, "\t.%s\t", type
);
163 assemble_name (asm_out_file
, name
);
164 fprintf (asm_out_file
, "\n");
166 if (!DECL_ARTIFICIAL (decl
))
167 warning (OPT_Wattributes
, "visibility attribute not supported "
168 "in this configuration; ignored");
172 /* Group section information entry stored in solaris_comdat_htab. */
174 typedef struct comdat_entry
182 /* Helpers for maintaining solaris_comdat_htab. */
184 struct comdat_entry_hasher
: typed_noop_remove
<comdat_entry
>
186 typedef comdat_entry
*value_type
;
187 typedef comdat_entry
*compare_type
;
188 static inline hashval_t
hash (const comdat_entry
*);
189 static inline bool equal (const comdat_entry
*, const comdat_entry
*);
190 static inline void remove (comdat_entry
*);
194 comdat_entry_hasher::hash (const comdat_entry
*entry
)
196 return htab_hash_string (entry
->sig
);
200 comdat_entry_hasher::equal (const comdat_entry
*entry1
,
201 const comdat_entry
*entry2
)
203 return strcmp (entry1
->sig
, entry2
->sig
) == 0;
206 /* Hash table of group signature symbols. */
208 static hash_table
<comdat_entry_hasher
> *solaris_comdat_htab
;
210 /* Output assembly to switch to COMDAT group section NAME with attributes
211 FLAGS and group signature symbol DECL, using Sun as syntax. */
214 solaris_elf_asm_comdat_section (const char *name
, unsigned int flags
, tree decl
)
216 const char *signature
;
218 comdat_entry entry
, **slot
;
220 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
221 signature
= IDENTIFIER_POINTER (decl
);
223 signature
= IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
));
225 /* Sun as requires group sections to be fragmented, i.e. to have names of
226 the form <section>%<fragment>. Strictly speaking this is only
227 necessary to support cc -xF, but is enforced globally in violation of
228 the ELF gABI. We keep the section names generated by GCC (generally
229 of the form .text.<signature>) and append %<signature> to pacify as,
230 despite the redundancy. */
231 section
= concat (name
, "%", signature
, NULL
);
233 /* Clear SECTION_LINKONCE flag so targetm.asm_out.named_section only
234 emits this as a regular section. Emit section before .group
235 directive since Sun as treats undeclared sections as @progbits,
236 which conflicts with .bss* sections which are @nobits. */
237 targetm
.asm_out
.named_section (section
, flags
& ~SECTION_LINKONCE
, decl
);
239 /* Sun as separates declaration of a group section and of the group
240 itself, using the .group directive and the #comdat flag. */
241 fprintf (asm_out_file
, "\t.group\t%s," SECTION_NAME_FORMAT
",#comdat\n",
244 /* Unlike GNU as, group signature symbols need to be defined explicitly
245 for Sun as. With a few exceptions, this is already the case. To
246 identify the missing ones without changing the affected frontents,
247 remember the signature symbols and emit those not marked
248 TREE_SYMBOL_REFERENCED in solaris_file_end. */
249 if (!solaris_comdat_htab
)
250 solaris_comdat_htab
= new hash_table
<comdat_entry_hasher
> (37);
252 entry
.sig
= signature
;
253 slot
= solaris_comdat_htab
->find_slot (&entry
, INSERT
);
257 *slot
= XCNEW (comdat_entry
);
258 /* Remember fragmented section name. */
259 (*slot
)->name
= section
;
260 /* Emit as regular section, .group declaration has already been done. */
261 (*slot
)->flags
= flags
& ~SECTION_LINKONCE
;
262 (*slot
)->decl
= decl
;
263 (*slot
)->sig
= signature
;
267 /* Define unreferenced COMDAT group signature symbol corresponding to SLOT. */
270 solaris_define_comdat_signature (comdat_entry
**slot
,
271 void *aux ATTRIBUTE_UNUSED
)
273 comdat_entry
*entry
= *slot
;
274 tree decl
= entry
->decl
;
276 if (TREE_CODE (decl
) != IDENTIFIER_NODE
)
277 decl
= DECL_COMDAT_GROUP (decl
);
279 if (!TREE_SYMBOL_REFERENCED (decl
))
281 /* Switch to group section, otherwise Sun as complains
282 `Group Id symbol defined outside of group'. */
283 switch_to_section (get_section (entry
->name
, entry
->flags
, entry
->decl
));
285 ASM_OUTPUT_LABEL (asm_out_file
, entry
->sig
);
288 /* Continue with scan. */
292 /* Emit unreferenced COMDAT group signature symbols for Sun as. */
295 solaris_file_end (void)
297 if (!solaris_comdat_htab
)
300 solaris_comdat_htab
->traverse
<void *, solaris_define_comdat_signature
>
305 solaris_override_options (void)
307 /* Older versions of Solaris ld cannot handle CIE version 3 in .eh_frame.
308 Don't emit DWARF3/4 unless specifically selected if so. */
309 if (!HAVE_LD_EH_FRAME_CIEV3
&& !global_options_set
.x_dwarf_version
)