OSDN Git Service

PR c/448
[pf3gnuchains/gcc-fork.git] / gcc / config / sol2.h
1 /* Operating system specific defines to be used when targeting GCC for any
2    Solaris 2 system.
3    Copyright 2002, 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
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 /* We use stabs-in-elf for debugging, because that is what the native
22    toolchain uses.  */
23 #undef PREFERRED_DEBUGGING_TYPE
24 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
25
26 /* Solaris 2 (at least as of 2.5.1) uses a 32-bit wchar_t.  */
27 #undef WCHAR_TYPE
28 #define WCHAR_TYPE "long int"
29
30 #undef WCHAR_TYPE_SIZE
31 #define WCHAR_TYPE_SIZE BITS_PER_WORD
32
33 /* Solaris 2 uses a wint_t different from the default. This is required
34    by the SCD 2.4.1, p. 6-83, Figure 6-66.  */
35 #undef  WINT_TYPE
36 #define WINT_TYPE "long int"
37
38 #undef  WINT_TYPE_SIZE
39 #define WINT_TYPE_SIZE BITS_PER_WORD
40
41 #define SIG_ATOMIC_TYPE "int"
42
43 /* ??? This definition of int8_t follows the system header but does
44    not conform to C99.  Likewise int_fast8_t, int_least8_t.  */
45 #define INT8_TYPE "char"
46 #define INT16_TYPE "short int"
47 #define INT32_TYPE "int"
48 #define INT64_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "long long int")
49 #define UINT8_TYPE "unsigned char"
50 #define UINT16_TYPE "short unsigned int"
51 #define UINT32_TYPE "unsigned int"
52 #define UINT64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int")
53
54 #define INT_LEAST8_TYPE "char"
55 #define INT_LEAST16_TYPE "short int"
56 #define INT_LEAST32_TYPE "int"
57 #define INT_LEAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "long long int")
58 #define UINT_LEAST8_TYPE "unsigned char"
59 #define UINT_LEAST16_TYPE "short unsigned int"
60 #define UINT_LEAST32_TYPE "unsigned int"
61 #define UINT_LEAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int")
62
63 #define INT_FAST8_TYPE "char"
64 #define INT_FAST16_TYPE "int"
65 #define INT_FAST32_TYPE "int"
66 #define INT_FAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "long long int")
67 #define UINT_FAST8_TYPE "unsigned char"
68 #define UINT_FAST16_TYPE "unsigned int"
69 #define UINT_FAST32_TYPE "unsigned int"
70 #define UINT_FAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int")
71
72 #define INTPTR_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "int")
73 #define UINTPTR_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "unsigned int")
74
75 #define TARGET_HANDLE_PRAGMA_REDEFINE_EXTNAME 1
76
77 /* ??? Note: in order for -compat-bsd to work fully,
78    we must somehow arrange to fixincludes /usr/ucbinclude
79    and put the result in $(libsubdir)/ucbinclude.  */
80
81 #undef CPP_SUBTARGET_SPEC
82 #define CPP_SUBTARGET_SPEC "\
83 %{pthreads|pthread:-D_REENTRANT -D_PTHREADS} \
84 %{!pthreads:%{!pthread:%{threads:-D_REENTRANT -D_SOLARIS_THREADS}}} \
85 %{compat-bsd:-iwithprefixbefore ucbinclude -I/usr/ucbinclude} \
86 "
87
88 /* Names to predefine in the preprocessor for this target machine.  */
89 #define TARGET_SUB_OS_CPP_BUILTINS()
90 #define TARGET_OS_CPP_BUILTINS()                        \
91     do {                                                \
92         builtin_define_std ("unix");                    \
93         builtin_define_std ("sun");                     \
94         builtin_define ("__svr4__");                    \
95         builtin_define ("__SVR4");                      \
96         builtin_assert ("system=unix");                 \
97         builtin_assert ("system=svr4");                 \
98         /* For C++ we need to add some additional macro \
99            definitions required by the C++ standard     \
100            library.  */                                 \
101         if (c_dialect_cxx ())                           \
102           {                                             \
103             builtin_define ("_XOPEN_SOURCE=500");       \
104             builtin_define ("_LARGEFILE_SOURCE=1");     \
105             builtin_define ("_LARGEFILE64_SOURCE=1");   \
106             builtin_define ("__EXTENSIONS__");          \
107           }                                             \
108         TARGET_SUB_OS_CPP_BUILTINS();                   \
109     } while (0)
110
111 /* The system headers under Solaris 2 are C++-aware since 2.0.  */
112 #define NO_IMPLICIT_EXTERN_C
113
114 /* The sun bundled assembler doesn't accept -Yd, (and neither does gas).
115    It's safe to pass -s always, even if -g is not used.  */
116 #undef ASM_SPEC
117 #define ASM_SPEC "\
118 %{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Wa,*:%*} -s \
119 %{fpic|fpie|fPIC|fPIE:-K PIC} \
120 %(asm_cpu) \
121 "
122
123 /* We don't use the standard LIB_SPEC only because we don't yet support c++.  */
124 #undef LIB_SPEC
125 #define LIB_SPEC \
126   "%{compat-bsd:-lucb -lsocket -lnsl -lelf -laio} \
127    %{!shared:\
128      %{!symbolic:\
129        %{pthreads|pthread:-lpthread} \
130        %{!pthreads:%{!pthread:%{threads:-lthread}}} \
131        %{p|pg:-ldl} -lc}}"
132
133 #undef  ENDFILE_SPEC
134 #define ENDFILE_SPEC "crtend.o%s crtn.o%s"
135
136 /* We don't use the standard svr4 STARTFILE_SPEC because it's wrong for us.  */
137 #undef STARTFILE_SPEC
138 #define STARTFILE_SPEC "%{!shared: \
139                          %{!symbolic: \
140                           %{p:mcrt1.o%s} \
141                           %{!p: \
142                             %{pg:gcrt1.o%s gmon.o%s} \
143                             %{!pg:crt1.o%s}}}} \
144                         crti.o%s %(startfile_arch) \
145                         crtbegin.o%s"
146
147 #undef STARTFILE_ARCH32_SPEC
148 #define STARTFILE_ARCH32_SPEC "%{ansi:values-Xc.o%s} \
149                             %{!ansi:values-Xa.o%s}"
150
151 #undef STARTFILE_ARCH_SPEC
152 #define STARTFILE_ARCH_SPEC STARTFILE_ARCH32_SPEC
153
154 #undef LINK_ARCH32_SPEC_BASE
155 #define LINK_ARCH32_SPEC_BASE \
156   "%{G:-G} \
157    %{YP,*} \
158    %{R*} \
159    %{compat-bsd: \
160      %{!YP,*:%{p|pg:-Y P,/usr/ucblib:/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
161              %{!p:%{!pg:-Y P,/usr/ucblib:/usr/ccs/lib:/usr/lib}}} \
162              -R /usr/ucblib} \
163    %{!compat-bsd: \
164      %{!YP,*:%{p|pg:-Y P,/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
165              %{!p:%{!pg:-Y P,/usr/ccs/lib:/usr/lib}}}}"
166
167 #undef LINK_ARCH32_SPEC
168 #define LINK_ARCH32_SPEC LINK_ARCH32_SPEC_BASE
169
170 #undef LINK_ARCH_SPEC
171 #define LINK_ARCH_SPEC LINK_ARCH32_SPEC
172
173 /* This should be the same as in svr4.h, except with -R added.  */
174 #undef  LINK_SPEC
175 #define LINK_SPEC \
176   "%{h*} %{v:-V} \
177    %{b} \
178    %{static:-dn -Bstatic} \
179    %{shared:-G -dy %{!mimpure-text:-z text}} \
180    %{symbolic:-Bsymbolic -G -dy -z text} \
181    %(link_arch) \
182    %{Qy:} %{!Qn:-Qy}"
183
184 /* The Solaris linker doesn't understand constructor priorities.  (The
185    GNU linker does support constructor priorities, so GNU ld
186    configuration files for Solaris override this setting.)  */
187 #undef SUPPORTS_INIT_PRIORITY
188 #define SUPPORTS_INIT_PRIORITY 0
189
190 /* This defines which switch letters take arguments.
191    It is as in svr4.h but with -R added.  */
192 #undef SWITCH_TAKES_ARG
193 #define SWITCH_TAKES_ARG(CHAR) \
194   (DEFAULT_SWITCH_TAKES_ARG(CHAR) \
195    || (CHAR) == 'R' \
196    || (CHAR) == 'h' \
197    || (CHAR) == 'z')
198
199 #define STDC_0_IN_SYSTEM_HEADERS 1
200 \f
201 /*
202  * Attempt to turn on access permissions for the stack.
203  *
204  * _SC_STACK_PROT is only defined for post 2.6, but we want this code
205  * to run always.  2.6 can change the stack protection but has no way to
206  * query it.
207  *
208  */
209
210 /* sys/mman.h is not present on some non-Solaris configurations
211    that use sol2.h, so ENABLE_EXECUTE_STACK must use a magic
212    number instead of the appropriate PROT_* flags.  */
213
214 #define ENABLE_EXECUTE_STACK                                    \
215                                                                         \
216 /* #define STACK_PROT_RWX (PROT_READ | PROT_WRITE | PROT_EXEC) */       \
217                                                                         \
218 static int need_enable_exec_stack;                                      \
219                                                                         \
220 static void check_enabling(void) __attribute__ ((constructor));         \
221 static void check_enabling(void)                                        \
222 {                                                                       \
223   extern long sysconf(int);                                             \
224                                                                         \
225   int prot = (int) sysconf(515 /* _SC_STACK_PROT */);                   \
226   if (prot != 7 /* STACK_PROT_RWX */)                                   \
227     need_enable_exec_stack = 1;                                         \
228 }                                                                       \
229                                                                         \
230 extern void __enable_execute_stack (void *);                            \
231 void                                                                    \
232 __enable_execute_stack (void *addr)                                     \
233 {                                                                       \
234   extern int mprotect(void *, size_t, int);                             \
235   if (!need_enable_exec_stack)                                          \
236     return;                                                             \
237   else {                                                                \
238     long size = getpagesize ();                                         \
239     long mask = ~(size-1);                                              \
240     char *page = (char *) (((long) addr) & mask);                       \
241     char *end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
242                                                                         \
243     if (mprotect (page, end - page, 7 /* STACK_PROT_RWX */) < 0)        \
244       perror ("mprotect of trampoline code");                           \
245   }                                                                     \
246 }
247
248 /* Support Solaris-specific format checking for cmn_err.  */
249 #define TARGET_N_FORMAT_TYPES 1
250 #define TARGET_FORMAT_TYPES solaris_format_types
251
252 /* #pragma init and #pragma fini are implemented on top of init and
253    fini attributes.  */
254 #define SOLARIS_ATTRIBUTE_TABLE                                         \
255   { "init",      0, 0, true,  false,  false, NULL },                    \
256   { "fini",      0, 0, true,  false,  false, NULL }
257
258 /* This is how to declare the size of a function.  For Solaris, we output
259    any .init or .fini entries here.  */
260 #undef ASM_DECLARE_FUNCTION_SIZE
261 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)            \
262   do                                                            \
263     {                                                           \
264       if (!flag_inhibit_size_directive)                         \
265         ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);                 \
266       solaris_output_init_fini (FILE, DECL);                    \
267     }                                                           \
268   while (0)
269
270 extern GTY(()) tree solaris_pending_aligns;
271 extern GTY(()) tree solaris_pending_inits;
272 extern GTY(()) tree solaris_pending_finis;
273
274 /* Allow macro expansion in #pragma pack.  */
275 #define HANDLE_PRAGMA_PACK_WITH_EXPANSION