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"
28 #include "stringpool.h"
29 #include "diagnostic-core.h"
33 tree solaris_pending_aligns
, solaris_pending_inits
, solaris_pending_finis
;
35 /* Attach any pending attributes for DECL to the list in *ATTRIBUTES.
36 Pending attributes come from #pragma or _Pragma, so this code is
37 only useful in the C family front ends, but it is included in
38 all languages to avoid changing the target machine initializer
39 depending on the language. */
42 solaris_insert_attributes (tree decl
, tree
*attributes
)
46 if (solaris_pending_aligns
!= NULL
&& TREE_CODE (decl
) == VAR_DECL
)
47 for (x
= &solaris_pending_aligns
; *x
; x
= &TREE_CHAIN (*x
))
49 tree name
= TREE_PURPOSE (*x
);
50 tree value
= TREE_VALUE (*x
);
51 if (DECL_NAME (decl
) == name
)
53 if (lookup_attribute ("aligned", DECL_ATTRIBUTES (decl
))
54 || lookup_attribute ("aligned", *attributes
))
55 warning (0, "ignoring %<#pragma align%> for explicitly "
56 "aligned %q+D", decl
);
58 *attributes
= tree_cons (get_identifier ("aligned"), value
,
60 next
= TREE_CHAIN (*x
);
67 if (solaris_pending_inits
!= NULL
&& TREE_CODE (decl
) == FUNCTION_DECL
)
68 for (x
= &solaris_pending_inits
; *x
; x
= &TREE_CHAIN (*x
))
70 tree name
= TREE_PURPOSE (*x
);
71 if (DECL_NAME (decl
) == name
)
73 *attributes
= tree_cons (get_identifier ("init"), NULL
,
76 DECL_PRESERVE_P (decl
) = 1;
77 next
= TREE_CHAIN (*x
);
84 if (solaris_pending_finis
!= NULL
&& TREE_CODE (decl
) == FUNCTION_DECL
)
85 for (x
= &solaris_pending_finis
; *x
; x
= &TREE_CHAIN (*x
))
87 tree name
= TREE_PURPOSE (*x
);
88 if (DECL_NAME (decl
) == name
)
90 *attributes
= tree_cons (get_identifier ("fini"), NULL
,
93 DECL_PRESERVE_P (decl
) = 1;
94 next
= TREE_CHAIN (*x
);
102 /* Output initializer or finalizer entries for DECL to FILE. */
105 solaris_output_init_fini (FILE *file
, tree decl
)
107 if (lookup_attribute ("init", DECL_ATTRIBUTES (decl
)))
109 fprintf (file
, "\t.pushsection\t" SECTION_NAME_FORMAT
"\n", ".init");
110 ASM_OUTPUT_CALL (file
, decl
);
111 fprintf (file
, "\t.popsection\n");
114 if (lookup_attribute ("fini", DECL_ATTRIBUTES (decl
)))
116 fprintf (file
, "\t.pushsection\t" SECTION_NAME_FORMAT
"\n", ".fini");
117 ASM_OUTPUT_CALL (file
, decl
);
118 fprintf (file
, "\t.popsection\n");
122 /* Emit an assembler directive to set symbol for DECL visibility to
123 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
126 solaris_assemble_visibility (tree decl
, int vis ATTRIBUTE_UNUSED
)
128 #ifdef HAVE_GAS_HIDDEN
129 /* Sun as uses .symbolic for STV_PROTECTED. STV_INTERNAL is marked as
130 `currently reserved', but the linker treats it like STV_HIDDEN. Sun
131 Studio 12.1 cc emits .hidden instead.
133 There are 3 Sun extensions GCC doesn't yet know about: STV_EXPORTED,
134 STV_SINGLETON, and STV_ELIMINATE.
136 See Linker and Libraries Guide, Ch. 2, Link-Editor, Defining
137 Additional Symbols, and Ch. 7, Object-File Format, Symbol Table
140 static const char * const visibility_types
[] = {
141 NULL
, "symbolic", "hidden", "hidden"
144 const char *name
, *type
;
146 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
147 type
= visibility_types
[vis
];
149 fprintf (asm_out_file
, "\t.%s\t", type
);
150 assemble_name (asm_out_file
, name
);
151 fprintf (asm_out_file
, "\n");
153 if (!DECL_ARTIFICIAL (decl
))
154 warning (OPT_Wattributes
, "visibility attribute not supported "
155 "in this configuration; ignored");
159 /* Group section information entry stored in solaris_comdat_htab. */
161 typedef struct comdat_entry
169 /* Helpers for maintaining solaris_comdat_htab. */
171 struct comdat_entry_hasher
: nofree_ptr_hash
<comdat_entry
>
173 static inline hashval_t
hash (const comdat_entry
*);
174 static inline bool equal (const comdat_entry
*, const comdat_entry
*);
175 static inline void remove (comdat_entry
*);
179 comdat_entry_hasher::hash (const comdat_entry
*entry
)
181 return htab_hash_string (entry
->sig
);
185 comdat_entry_hasher::equal (const comdat_entry
*entry1
,
186 const comdat_entry
*entry2
)
188 return strcmp (entry1
->sig
, entry2
->sig
) == 0;
191 /* Hash table of group signature symbols. */
193 static hash_table
<comdat_entry_hasher
> *solaris_comdat_htab
;
195 /* Output assembly to switch to COMDAT group section NAME with attributes
196 FLAGS and group signature symbol DECL, using Sun as syntax. */
199 solaris_elf_asm_comdat_section (const char *name
, unsigned int flags
, tree decl
)
201 const char *signature
;
203 comdat_entry entry
, **slot
;
205 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
206 signature
= IDENTIFIER_POINTER (decl
);
208 signature
= IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
));
210 /* Sun as requires group sections to be fragmented, i.e. to have names of
211 the form <section>%<fragment>. Strictly speaking this is only
212 necessary to support cc -xF, but is enforced globally in violation of
213 the ELF gABI. We keep the section names generated by GCC (generally
214 of the form .text.<signature>) and append %<signature> to pacify as,
215 despite the redundancy. */
216 section
= concat (name
, "%", signature
, NULL
);
218 /* Clear SECTION_LINKONCE flag so targetm.asm_out.named_section only
219 emits this as a regular section. Emit section before .group
220 directive since Sun as treats undeclared sections as @progbits,
221 which conflicts with .bss* sections which are @nobits. */
222 targetm
.asm_out
.named_section (section
, flags
& ~SECTION_LINKONCE
, decl
);
224 /* Sun as separates declaration of a group section and of the group
225 itself, using the .group directive and the #comdat flag. */
226 fprintf (asm_out_file
, "\t.group\t%s," SECTION_NAME_FORMAT
",#comdat\n",
229 /* Unlike GNU as, group signature symbols need to be defined explicitly
230 for Sun as. With a few exceptions, this is already the case. To
231 identify the missing ones without changing the affected frontents,
232 remember the signature symbols and emit those not marked
233 TREE_SYMBOL_REFERENCED in solaris_file_end. */
234 if (!solaris_comdat_htab
)
235 solaris_comdat_htab
= new hash_table
<comdat_entry_hasher
> (37);
237 entry
.sig
= signature
;
238 slot
= solaris_comdat_htab
->find_slot (&entry
, INSERT
);
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. */
255 solaris_define_comdat_signature (comdat_entry
**slot
,
256 void *aux ATTRIBUTE_UNUSED
)
258 comdat_entry
*entry
= *slot
;
259 tree decl
= entry
->decl
;
261 if (TREE_CODE (decl
) != IDENTIFIER_NODE
)
262 decl
= DECL_COMDAT_GROUP (decl
);
264 if (!TREE_SYMBOL_REFERENCED (decl
))
266 /* Switch to group section, otherwise Sun as complains
267 `Group Id symbol defined outside of group'. */
268 switch_to_section (get_section (entry
->name
, entry
->flags
, entry
->decl
));
270 ASM_OUTPUT_LABEL (asm_out_file
, entry
->sig
);
273 /* Continue with scan. */
277 /* Emit unreferenced COMDAT group signature symbols for Sun as. */
280 solaris_file_end (void)
282 if (!solaris_comdat_htab
)
285 solaris_comdat_htab
->traverse
<void *, solaris_define_comdat_signature
>
290 solaris_override_options (void)
292 /* Older versions of Solaris ld cannot handle CIE version 3 in .eh_frame.
293 Don't emit DWARF3/4 unless specifically selected if so. */
294 if (!HAVE_LD_EH_FRAME_CIEV3
&& !global_options_set
.x_dwarf_version
)