s390.md (*xordi3_cc): Mark xgrk as z196 only.
[gcc.git] / gcc / config / sol2.c
1 /* General Solaris system support.
2 Copyright (C) 2004, 2005 , 2007, 2010 Free Software Foundation, Inc.
3 Contributed by CodeSourcery, LLC.
4
5 This file is part of GCC.
6
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.
11
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.
16
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/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tree.h"
25 #include "output.h"
26 #include "tm.h"
27 #include "rtl.h"
28 #include "tm_p.h"
29 #include "diagnostic-core.h"
30 #include "toplev.h"
31 #include "ggc.h"
32
33 tree solaris_pending_aligns, solaris_pending_inits, solaris_pending_finis;
34
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. */
40
41 void
42 solaris_insert_attributes (tree decl, tree *attributes)
43 {
44 tree *x, next;
45
46 if (solaris_pending_aligns != NULL && TREE_CODE (decl) == VAR_DECL)
47 for (x = &solaris_pending_aligns; *x; x = &TREE_CHAIN (*x))
48 {
49 tree name = TREE_PURPOSE (*x);
50 tree value = TREE_VALUE (*x);
51 if (DECL_NAME (decl) == name)
52 {
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);
57 else
58 *attributes = tree_cons (get_identifier ("aligned"), value,
59 *attributes);
60 next = TREE_CHAIN (*x);
61 ggc_free (*x);
62 *x = next;
63 break;
64 }
65 }
66
67 if (solaris_pending_inits != NULL && TREE_CODE (decl) == FUNCTION_DECL)
68 for (x = &solaris_pending_inits; *x; x = &TREE_CHAIN (*x))
69 {
70 tree name = TREE_PURPOSE (*x);
71 if (DECL_NAME (decl) == name)
72 {
73 *attributes = tree_cons (get_identifier ("init"), NULL,
74 *attributes);
75 TREE_USED (decl) = 1;
76 DECL_PRESERVE_P (decl) = 1;
77 next = TREE_CHAIN (*x);
78 ggc_free (*x);
79 *x = next;
80 break;
81 }
82 }
83
84 if (solaris_pending_finis != NULL && TREE_CODE (decl) == FUNCTION_DECL)
85 for (x = &solaris_pending_finis; *x; x = &TREE_CHAIN (*x))
86 {
87 tree name = TREE_PURPOSE (*x);
88 if (DECL_NAME (decl) == name)
89 {
90 *attributes = tree_cons (get_identifier ("fini"), NULL,
91 *attributes);
92 TREE_USED (decl) = 1;
93 DECL_PRESERVE_P (decl) = 1;
94 next = TREE_CHAIN (*x);
95 ggc_free (*x);
96 *x = next;
97 break;
98 }
99 }
100 }
101
102 /* Output initializer or finalizer entries for DECL to FILE. */
103
104 void
105 solaris_output_init_fini (FILE *file, tree decl)
106 {
107 if (lookup_attribute ("init", DECL_ATTRIBUTES (decl)))
108 {
109 fprintf (file, PUSHSECTION_FORMAT, ".init");
110 ASM_OUTPUT_CALL (file, decl);
111 fprintf (file, "\t.popsection\n");
112 }
113
114 if (lookup_attribute ("fini", DECL_ATTRIBUTES (decl)))
115 {
116 fprintf (file, PUSHSECTION_FORMAT, ".fini");
117 ASM_OUTPUT_CALL (file, decl);
118 fprintf (file, "\t.popsection\n");
119 }
120 }
121
122 /* Emit an assembler directive to set symbol for DECL visibility to
123 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
124
125 void
126 solaris_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
127 int vis ATTRIBUTE_UNUSED)
128 {
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.
133
134 There are 3 Sun extensions GCC doesn't yet know about: STV_EXPORTED,
135 STV_SINGLETON, and STV_ELIMINATE.
136
137 See Linker and Libraries Guide, Ch. 2, Link-Editor, Defining
138 Additional Symbols with a mapfile,
139 http://docs.sun.com/app/docs/doc/819-0690/gdzmc?a=view
140 and Ch. 7, Object-File Format, Symbol Table Section,
141 http://docs.sun.com/app/docs/doc/819-0690/chapter6-79797?a=view */
142
143 static const char * const visibility_types[] = {
144 NULL, "symbolic", "hidden", "hidden"
145 };
146
147 const char *name, *type;
148
149 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
150 type = visibility_types[vis];
151
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
159 }