1 /* General Solaris system support.
2 Copyright (C) 2004-2017 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"
29 #include "stringpool.h"
30 #include "diagnostic-core.h"
34 tree solaris_pending_aligns
, solaris_pending_inits
, solaris_pending_finis
;
36 /* Attach any pending attributes for DECL to the list in *ATTRIBUTES.
37 Pending attributes come from #pragma or _Pragma, so this code is
38 only useful in the C family front ends, but it is included in
39 all languages to avoid changing the target machine initializer
40 depending on the language. */
43 solaris_insert_attributes (tree decl
, tree
*attributes
)
47 if (solaris_pending_aligns
!= NULL
&& TREE_CODE (decl
) == VAR_DECL
)
48 for (x
= &solaris_pending_aligns
; *x
; x
= &TREE_CHAIN (*x
))
50 tree name
= TREE_PURPOSE (*x
);
51 tree value
= TREE_VALUE (*x
);
52 if (DECL_NAME (decl
) == name
)
54 if (lookup_attribute ("aligned", DECL_ATTRIBUTES (decl
))
55 || lookup_attribute ("aligned", *attributes
))
56 warning (0, "ignoring %<#pragma align%> for explicitly "
57 "aligned %q+D", decl
);
59 *attributes
= tree_cons (get_identifier ("aligned"), value
,
61 next
= TREE_CHAIN (*x
);
68 if (solaris_pending_inits
!= NULL
&& TREE_CODE (decl
) == FUNCTION_DECL
)
69 for (x
= &solaris_pending_inits
; *x
; x
= &TREE_CHAIN (*x
))
71 tree name
= TREE_PURPOSE (*x
);
72 if (DECL_NAME (decl
) == name
)
74 *attributes
= tree_cons (get_identifier ("init"), NULL
,
77 DECL_PRESERVE_P (decl
) = 1;
78 next
= TREE_CHAIN (*x
);
85 if (solaris_pending_finis
!= NULL
&& TREE_CODE (decl
) == FUNCTION_DECL
)
86 for (x
= &solaris_pending_finis
; *x
; x
= &TREE_CHAIN (*x
))
88 tree name
= TREE_PURPOSE (*x
);
89 if (DECL_NAME (decl
) == name
)
91 *attributes
= tree_cons (get_identifier ("fini"), NULL
,
94 DECL_PRESERVE_P (decl
) = 1;
95 next
= TREE_CHAIN (*x
);
103 /* Output initializer or finalizer entries for DECL to FILE. */
106 solaris_output_init_fini (FILE *file
, tree decl
)
108 if (lookup_attribute ("init", DECL_ATTRIBUTES (decl
)))
110 fprintf (file
, "\t.pushsection\t" SECTION_NAME_FORMAT
"\n", ".init");
111 ASM_OUTPUT_CALL (file
, decl
);
112 fprintf (file
, "\t.popsection\n");
115 if (lookup_attribute ("fini", DECL_ATTRIBUTES (decl
)))
117 fprintf (file
, "\t.pushsection\t" SECTION_NAME_FORMAT
"\n", ".fini");
118 ASM_OUTPUT_CALL (file
, decl
);
119 fprintf (file
, "\t.popsection\n");
123 /* Emit an assembler directive to set symbol for DECL visibility to
124 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
127 solaris_assemble_visibility (tree decl
, int vis ATTRIBUTE_UNUSED
)
129 #ifdef HAVE_GAS_HIDDEN
130 /* Sun as uses .symbolic for STV_PROTECTED. STV_INTERNAL is marked as
131 `currently reserved', but the linker treats it like STV_HIDDEN. Sun
132 Studio 12.1 cc emits .hidden instead.
134 There are 3 Sun extensions GCC doesn't yet know about: STV_EXPORTED,
135 STV_SINGLETON, and STV_ELIMINATE.
137 See Linker and Libraries Guide, Ch. 2, Link-Editor, Defining
138 Additional Symbols, and Ch. 7, Object-File Format, Symbol Table
141 static const char * const visibility_types
[] = {
142 NULL
, "symbolic", "hidden", "hidden"
145 const char *name
, *type
;
146 tree id
= DECL_ASSEMBLER_NAME (decl
);
148 while (IDENTIFIER_TRANSPARENT_ALIAS (id
))
149 id
= TREE_CHAIN (id
);
150 name
= IDENTIFIER_POINTER (id
);
151 type
= visibility_types
[vis
];
153 fprintf (asm_out_file
, "\t.%s\t", type
);
154 assemble_name (asm_out_file
, name
);
155 fprintf (asm_out_file
, "\n");
157 if (!DECL_ARTIFICIAL (decl
))
158 warning (OPT_Wattributes
, "visibility attribute not supported "
159 "in this configuration; ignored");
163 /* Group section information entry stored in solaris_comdat_htab. */
165 typedef struct comdat_entry
173 /* Helpers for maintaining solaris_comdat_htab. */
175 struct comdat_entry_hasher
: nofree_ptr_hash
<comdat_entry
>
177 static inline hashval_t
hash (const comdat_entry
*);
178 static inline bool equal (const comdat_entry
*, const comdat_entry
*);
179 static inline void remove (comdat_entry
*);
183 comdat_entry_hasher::hash (const comdat_entry
*entry
)
185 return htab_hash_string (entry
->sig
);
189 comdat_entry_hasher::equal (const comdat_entry
*entry1
,
190 const comdat_entry
*entry2
)
192 return strcmp (entry1
->sig
, entry2
->sig
) == 0;
195 /* Hash table of group signature symbols. */
197 static hash_table
<comdat_entry_hasher
> *solaris_comdat_htab
;
199 /* Output assembly to switch to COMDAT group section NAME with attributes
200 FLAGS and group signature symbol DECL, using Sun as syntax. */
203 solaris_elf_asm_comdat_section (const char *name
, unsigned int flags
, tree decl
)
205 const char *signature
;
207 comdat_entry entry
, **slot
;
209 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
210 signature
= IDENTIFIER_POINTER (decl
);
212 signature
= IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
));
214 /* Sun as requires group sections to be fragmented, i.e. to have names of
215 the form <section>%<fragment>. Strictly speaking this is only
216 necessary to support cc -xF, but is enforced globally in violation of
217 the ELF gABI. We keep the section names generated by GCC (generally
218 of the form .text.<signature>) and append %<signature> to pacify as,
219 despite the redundancy. */
220 section
= concat (name
, "%", signature
, NULL
);
222 /* Clear SECTION_LINKONCE flag so targetm.asm_out.named_section only
223 emits this as a regular section. Emit section before .group
224 directive since Sun as treats undeclared sections as @progbits,
225 which conflicts with .bss* sections which are @nobits. */
226 targetm
.asm_out
.named_section (section
, flags
& ~SECTION_LINKONCE
, decl
);
228 /* Sun as separates declaration of a group section and of the group
229 itself, using the .group directive and the #comdat flag. */
230 fprintf (asm_out_file
, "\t.group\t%s," SECTION_NAME_FORMAT
",#comdat\n",
233 /* Unlike GNU as, group signature symbols need to be defined explicitly
234 for Sun as. With a few exceptions, this is already the case. To
235 identify the missing ones without changing the affected frontents,
236 remember the signature symbols and emit those not marked
237 TREE_SYMBOL_REFERENCED in solaris_file_end. */
238 if (!solaris_comdat_htab
)
239 solaris_comdat_htab
= new hash_table
<comdat_entry_hasher
> (37);
241 entry
.sig
= signature
;
242 slot
= solaris_comdat_htab
->find_slot (&entry
, INSERT
);
246 *slot
= XCNEW (comdat_entry
);
247 /* Remember fragmented section name. */
248 (*slot
)->name
= section
;
249 /* Emit as regular section, .group declaration has already been done. */
250 (*slot
)->flags
= flags
& ~SECTION_LINKONCE
;
251 (*slot
)->decl
= decl
;
252 (*slot
)->sig
= signature
;
256 /* Define unreferenced COMDAT group signature symbol corresponding to SLOT. */
259 solaris_define_comdat_signature (comdat_entry
**slot
,
260 void *aux ATTRIBUTE_UNUSED
)
262 comdat_entry
*entry
= *slot
;
263 tree decl
= entry
->decl
;
265 if (TREE_CODE (decl
) != IDENTIFIER_NODE
)
266 decl
= DECL_COMDAT_GROUP (decl
);
268 if (!TREE_SYMBOL_REFERENCED (decl
))
270 /* Switch to group section, otherwise Sun as complains
271 `Group Id symbol defined outside of group'. */
272 switch_to_section (get_section (entry
->name
, entry
->flags
, entry
->decl
));
274 ASM_OUTPUT_LABEL (asm_out_file
, entry
->sig
);
277 /* Continue with scan. */
281 /* Emit unreferenced COMDAT group signature symbols for Sun as. */
284 solaris_file_end (void)
286 if (!solaris_comdat_htab
)
289 solaris_comdat_htab
->traverse
<void *, solaris_define_comdat_signature
>
294 solaris_override_options (void)
296 /* Older versions of Solaris ld cannot handle CIE version 3 in .eh_frame.
297 Don't emit DWARF3/4 unless specifically selected if so. */
298 if (!HAVE_LD_EH_FRAME_CIEV3
&& !global_options_set
.x_dwarf_version
)