2008-07-01 Jerry DeLisle <jvdelisle@gcc.gnu.org>
[official-gcc.git] / gcc / config / sol2.h
blob512d0ff17f5e6ab16a69144d9a6b5eb7dc7f2ef0
1 /* Operating system specific defines to be used when targeting GCC for any
2 Solaris 2 system.
3 Copyright 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
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)
10 any later version.
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/>. */
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
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"
30 #undef WCHAR_TYPE_SIZE
31 #define WCHAR_TYPE_SIZE BITS_PER_WORD
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"
38 #undef WINT_TYPE_SIZE
39 #define WINT_TYPE_SIZE BITS_PER_WORD
41 #define TARGET_HANDLE_PRAGMA_REDEFINE_EXTNAME 1
43 /* ??? Note: in order for -compat-bsd to work fully,
44 we must somehow arrange to fixincludes /usr/ucbinclude
45 and put the result in $(libsubdir)/ucbinclude. */
47 #undef CPP_SUBTARGET_SPEC
48 #define CPP_SUBTARGET_SPEC "\
49 %{pthreads|pthread:-D_REENTRANT -D_PTHREADS} \
50 %{!pthreads:%{!pthread:%{threads:-D_REENTRANT -D_SOLARIS_THREADS}}} \
51 %{compat-bsd:-iwithprefixbefore ucbinclude -I/usr/ucbinclude} \
54 /* Names to predefine in the preprocessor for this target machine. */
55 #define TARGET_SUB_OS_CPP_BUILTINS()
56 #define TARGET_OS_CPP_BUILTINS() \
57 do { \
58 builtin_define_std ("unix"); \
59 builtin_define_std ("sun"); \
60 builtin_define ("__svr4__"); \
61 builtin_define ("__SVR4"); \
62 builtin_assert ("system=unix"); \
63 builtin_assert ("system=svr4"); \
64 /* For C++ we need to add some additional macro \
65 definitions required by the C++ standard \
66 library. */ \
67 if (c_dialect_cxx ()) \
68 { \
69 builtin_define ("_XOPEN_SOURCE=500"); \
70 builtin_define ("_LARGEFILE_SOURCE=1"); \
71 builtin_define ("_LARGEFILE64_SOURCE=1"); \
72 builtin_define ("__EXTENSIONS__"); \
73 } \
74 TARGET_SUB_OS_CPP_BUILTINS(); \
75 } while (0)
77 /* The system headers under Solaris 2 are C++-aware since 2.0. */
78 #define NO_IMPLICIT_EXTERN_C
80 /* The sun bundled assembler doesn't accept -Yd, (and neither does gas).
81 It's safe to pass -s always, even if -g is not used. */
82 #undef ASM_SPEC
83 #define ASM_SPEC "\
84 %{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Wa,*:%*} -s \
85 %{fpic|fpie|fPIC|fPIE:-K PIC} \
86 %(asm_cpu) \
89 /* We don't use the standard LIB_SPEC only because we don't yet support c++. */
90 #undef LIB_SPEC
91 #define LIB_SPEC \
92 "%{compat-bsd:-lucb -lsocket -lnsl -lelf -laio} \
93 %{!shared:\
94 %{!symbolic:\
95 %{pthreads|pthread:-lpthread} \
96 %{!pthreads:%{!pthread:%{threads:-lthread}}} \
97 %{p|pg:-ldl} -lc}}"
99 #undef ENDFILE_SPEC
100 #define ENDFILE_SPEC "crtend.o%s crtn.o%s"
102 /* We don't use the standard svr4 STARTFILE_SPEC because it's wrong for us. */
103 #undef STARTFILE_SPEC
104 #define STARTFILE_SPEC "%{!shared: \
105 %{!symbolic: \
106 %{p:mcrt1.o%s} \
107 %{!p: \
108 %{pg:gcrt1.o%s gmon.o%s} \
109 %{!pg:crt1.o%s}}}} \
110 crti.o%s %(startfile_arch) \
111 crtbegin.o%s"
113 #undef STARTFILE_ARCH32_SPEC
114 #define STARTFILE_ARCH32_SPEC "%{ansi:values-Xc.o%s} \
115 %{!ansi:values-Xa.o%s}"
117 #undef STARTFILE_ARCH_SPEC
118 #define STARTFILE_ARCH_SPEC STARTFILE_ARCH32_SPEC
120 #undef LINK_ARCH32_SPEC_BASE
121 #define LINK_ARCH32_SPEC_BASE \
122 "%{G:-G} \
123 %{YP,*} \
124 %{R*} \
125 %{compat-bsd: \
126 %{!YP,*:%{p|pg:-Y P,/usr/ucblib:/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
127 %{!p:%{!pg:-Y P,/usr/ucblib:/usr/ccs/lib:/usr/lib}}} \
128 -R /usr/ucblib} \
129 %{!compat-bsd: \
130 %{!YP,*:%{p|pg:-Y P,/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
131 %{!p:%{!pg:-Y P,/usr/ccs/lib:/usr/lib}}}}"
133 #undef LINK_ARCH32_SPEC
134 #define LINK_ARCH32_SPEC LINK_ARCH32_SPEC_BASE
136 #undef LINK_ARCH_SPEC
137 #define LINK_ARCH_SPEC LINK_ARCH32_SPEC
139 /* This should be the same as in svr4.h, except with -R added. */
140 #undef LINK_SPEC
141 #define LINK_SPEC \
142 "%{h*} %{v:-V} \
143 %{b} \
144 %{static:-dn -Bstatic} \
145 %{shared:-G -dy %{!mimpure-text:-z text}} \
146 %{symbolic:-Bsymbolic -G -dy -z text} \
147 %(link_arch) \
148 %{Qy:} %{!Qn:-Qy}"
150 /* The Solaris linker doesn't understand constructor priorities. (The
151 GNU linker does support constructor priorities, so GNU ld
152 configuration files for Solaris override this setting.) */
153 #undef SUPPORTS_INIT_PRIORITY
154 #define SUPPORTS_INIT_PRIORITY 0
156 /* This defines which switch letters take arguments.
157 It is as in svr4.h but with -R added. */
158 #undef SWITCH_TAKES_ARG
159 #define SWITCH_TAKES_ARG(CHAR) \
160 (DEFAULT_SWITCH_TAKES_ARG(CHAR) \
161 || (CHAR) == 'R' \
162 || (CHAR) == 'h' \
163 || (CHAR) == 'z')
165 #define STDC_0_IN_SYSTEM_HEADERS 1
168 * Attempt to turn on access permissions for the stack.
170 * _SC_STACK_PROT is only defined for post 2.6, but we want this code
171 * to run always. 2.6 can change the stack protection but has no way to
172 * query it.
176 /* sys/mman.h is not present on some non-Solaris configurations
177 that use sol2.h, so ENABLE_EXECUTE_STACK must use a magic
178 number instead of the appropriate PROT_* flags. */
180 #define ENABLE_EXECUTE_STACK \
182 /* #define STACK_PROT_RWX (PROT_READ | PROT_WRITE | PROT_EXEC) */ \
184 static int need_enable_exec_stack; \
186 static void check_enabling(void) __attribute__ ((constructor)); \
187 static void check_enabling(void) \
189 extern long sysconf(int); \
191 int prot = (int) sysconf(515 /* _SC_STACK_PROT */); \
192 if (prot != 7 /* STACK_PROT_RWX */) \
193 need_enable_exec_stack = 1; \
196 extern void __enable_execute_stack (void *); \
197 void \
198 __enable_execute_stack (void *addr) \
200 extern int mprotect(void *, size_t, int); \
201 if (!need_enable_exec_stack) \
202 return; \
203 else { \
204 long size = getpagesize (); \
205 long mask = ~(size-1); \
206 char *page = (char *) (((long) addr) & mask); \
207 char *end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
209 if (mprotect (page, end - page, 7 /* STACK_PROT_RWX */) < 0) \
210 perror ("mprotect of trampoline code"); \
214 /* Support Solaris-specific format checking for cmn_err. */
215 #define TARGET_N_FORMAT_TYPES 1
216 #define TARGET_FORMAT_TYPES solaris_format_types
218 /* #pragma init and #pragma fini are implemented on top of init and
219 fini attributes. */
220 #define SOLARIS_ATTRIBUTE_TABLE \
221 { "init", 0, 0, true, false, false, NULL }, \
222 { "fini", 0, 0, true, false, false, NULL }
224 /* This is how to declare the size of a function. For Solaris, we output
225 any .init or .fini entries here. */
226 #undef ASM_DECLARE_FUNCTION_SIZE
227 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \
228 do \
230 if (!flag_inhibit_size_directive) \
231 ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME); \
232 solaris_output_init_fini (FILE, DECL); \
234 while (0)
236 /* Register the Solaris-specific #pragma directives. */
237 #define REGISTER_TARGET_PRAGMAS() solaris_register_pragmas ()
239 extern GTY(()) tree solaris_pending_aligns;
240 extern GTY(()) tree solaris_pending_inits;
241 extern GTY(()) tree solaris_pending_finis;
243 /* Allow macro expansion in #pragma pack. */
244 #define HANDLE_PRAGMA_PACK_WITH_EXPANSION