1/* Operating system specific defines to be used when targeting GCC for any
2   Solaris 2 system.
3   Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING.  If not, write to
19the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20Boston, MA 02110-1301, USA.  */
21
22/* We use stabs-in-elf for debugging, because that is what the native
23   toolchain uses.  */
24#undef PREFERRED_DEBUGGING_TYPE
25#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
26
27/* Solaris 2 (at least as of 2.5.1) uses a 32-bit wchar_t.  */
28#undef WCHAR_TYPE
29#define WCHAR_TYPE "long int"
30
31#undef WCHAR_TYPE_SIZE
32#define WCHAR_TYPE_SIZE BITS_PER_WORD
33
34/* Solaris 2 uses a wint_t different from the default. This is required
35   by the SCD 2.4.1, p. 6-83, Figure 6-66.  */
36#undef	WINT_TYPE
37#define	WINT_TYPE "long int"
38
39#undef	WINT_TYPE_SIZE
40#define	WINT_TYPE_SIZE BITS_PER_WORD
41
42#define TARGET_HANDLE_PRAGMA_REDEFINE_EXTNAME 1
43
44/* ??? Note: in order for -compat-bsd to work fully,
45   we must somehow arrange to fixincludes /usr/ucbinclude
46   and put the result in $(libsubdir)/ucbinclude.  */
47
48#undef CPP_SUBTARGET_SPEC
49#define CPP_SUBTARGET_SPEC "\
50%{pthreads|pthread:-D_REENTRANT -D_PTHREADS} \
51%{!pthreads:%{!pthread:%{threads:-D_REENTRANT -D_SOLARIS_THREADS}}} \
52%{compat-bsd:-iwithprefixbefore ucbinclude -I/usr/ucbinclude} \
53"
54
55/* Names to predefine in the preprocessor for this target machine.  */
56#define TARGET_SUB_OS_CPP_BUILTINS()
57#define TARGET_OS_CPP_BUILTINS()			\
58    do {						\
59	builtin_define_std ("unix");			\
60	builtin_define_std ("sun");			\
61	builtin_define ("__svr4__");			\
62	builtin_define ("__SVR4");			\
63	builtin_assert ("system=unix");			\
64	builtin_assert ("system=svr4");			\
65	/* For C++ we need to add some additional macro	\
66	   definitions required by the C++ standard	\
67	   library.  */					\
68	if (c_dialect_cxx ())				\
69	  {						\
70	    builtin_define ("_XOPEN_SOURCE=500");	\
71	    builtin_define ("_LARGEFILE_SOURCE=1");	\
72	    builtin_define ("_LARGEFILE64_SOURCE=1");	\
73	    builtin_define ("__EXTENSIONS__");		\
74	  }						\
75	if (flag_pic)					\
76	  {						\
77	    builtin_define ("__PIC__");			\
78	    builtin_define ("__pic__");			\
79	  }						\
80	TARGET_SUB_OS_CPP_BUILTINS();			\
81    } while (0)
82
83/* The system headers under Solaris 2 are C++-aware since 2.0.  */
84#define NO_IMPLICIT_EXTERN_C
85
86/* The sun bundled assembler doesn't accept -Yd, (and neither does gas).
87   It's safe to pass -s always, even if -g is not used.  */
88#undef ASM_SPEC
89#define ASM_SPEC "\
90%{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Wa,*:%*} -s \
91%{fpic|fpie|fPIC|fPIE:-K PIC} \
92%(asm_cpu) \
93"
94
95/* We don't use the standard LIB_SPEC only because we don't yet support c++.  */
96#undef LIB_SPEC
97#define LIB_SPEC \
98  "%{compat-bsd:-lucb -lsocket -lnsl -lelf -laio} \
99   %{!shared:\
100     %{!symbolic:\
101       %{pthreads|pthread:-lpthread} \
102       %{!pthreads:%{!pthread:%{threads:-lthread}}} \
103       %{p|pg:-ldl} -lc}}"
104
105#undef  ENDFILE_SPEC
106#define ENDFILE_SPEC "crtend.o%s crtn.o%s"
107
108/* We don't use the standard svr4 STARTFILE_SPEC because it's wrong for us.  */
109#undef STARTFILE_SPEC
110#define STARTFILE_SPEC "%{!shared: \
111			 %{!symbolic: \
112			  %{p:mcrt1.o%s} \
113                          %{!p: \
114	                    %{pg:gcrt1.o%s gmon.o%s} \
115                            %{!pg:crt1.o%s}}}} \
116			crti.o%s %(startfile_arch) \
117			crtbegin.o%s"
118
119#undef STARTFILE_ARCH32_SPEC
120#define STARTFILE_ARCH32_SPEC "%{ansi:values-Xc.o%s} \
121			    %{!ansi:values-Xa.o%s}"
122
123#undef STARTFILE_ARCH_SPEC
124#define STARTFILE_ARCH_SPEC STARTFILE_ARCH32_SPEC
125
126#undef LINK_ARCH32_SPEC_BASE
127#define LINK_ARCH32_SPEC_BASE \
128  "%{G:-G} \
129   %{YP,*} \
130   %{R*} \
131   %{compat-bsd: \
132     %{!YP,*:%{p|pg:-Y P,/usr/ucblib:/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
133             %{!p:%{!pg:-Y P,/usr/ucblib:/usr/ccs/lib:/usr/lib}}} \
134             -R /usr/ucblib} \
135   %{!compat-bsd: \
136     %{!YP,*:%{p|pg:-Y P,/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
137             %{!p:%{!pg:-Y P,/usr/ccs/lib:/usr/lib}}}}"
138
139#undef LINK_ARCH32_SPEC
140#define LINK_ARCH32_SPEC LINK_ARCH32_SPEC_BASE
141
142#undef LINK_ARCH_SPEC
143#define LINK_ARCH_SPEC LINK_ARCH32_SPEC
144
145/* This should be the same as in svr4.h, except with -R added.  */
146#undef  LINK_SPEC
147#define LINK_SPEC \
148  "%{h*} %{v:-V} \
149   %{b} \
150   %{static:-dn -Bstatic} \
151   %{shared:-G -dy %{!mimpure-text:-z text}} \
152   %{symbolic:-Bsymbolic -G -dy -z text} \
153   %(link_arch) \
154   %{Qy:} %{!Qn:-Qy}"
155
156/* The Solaris linker doesn't understand constructor priorities.  (The
157   GNU linker does support constructor priorities, so GNU ld
158   configuration files for Solaris override this setting.)  */
159#undef SUPPORTS_INIT_PRIORITY
160#define SUPPORTS_INIT_PRIORITY 0
161
162/* This defines which switch letters take arguments.
163   It is as in svr4.h but with -R added.  */
164#undef SWITCH_TAKES_ARG
165#define SWITCH_TAKES_ARG(CHAR) \
166  (DEFAULT_SWITCH_TAKES_ARG(CHAR) \
167   || (CHAR) == 'R' \
168   || (CHAR) == 'h' \
169   || (CHAR) == 'z')
170
171#define STDC_0_IN_SYSTEM_HEADERS 1
172
173/*
174 * Attempt to turn on access permissions for the stack.
175 *
176 * _SC_STACK_PROT is only defined for post 2.6, but we want this code
177 * to run always.  2.6 can change the stack protection but has no way to
178 * query it.
179 *
180 */
181
182/* sys/mman.h is not present on some non-Solaris configurations
183   that use sol2.h, so ENABLE_EXECUTE_STACK must use a magic
184   number instead of the appropriate PROT_* flags.  */
185
186#define ENABLE_EXECUTE_STACK					\
187									\
188/* #define STACK_PROT_RWX (PROT_READ | PROT_WRITE | PROT_EXEC) */	\
189									\
190static int need_enable_exec_stack;					\
191									\
192static void check_enabling(void) __attribute__ ((constructor));		\
193static void check_enabling(void)					\
194{									\
195  extern long sysconf(int);						\
196									\
197  int prot = (int) sysconf(515 /* _SC_STACK_PROT */);			\
198  if (prot != 7 /* STACK_PROT_RWX */)					\
199    need_enable_exec_stack = 1;						\
200}									\
201									\
202extern void __enable_execute_stack (void *);				\
203void									\
204__enable_execute_stack (void *addr)					\
205{									\
206  extern int mprotect(void *, size_t, int);				\
207  if (!need_enable_exec_stack)						\
208    return;								\
209  else {								\
210    long size = getpagesize ();						\
211    long mask = ~(size-1);						\
212    char *page = (char *) (((long) addr) & mask); 			\
213    char *end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
214									\
215    if (mprotect (page, end - page, 7 /* STACK_PROT_RWX */) < 0)	\
216      perror ("mprotect of trampoline code");				\
217  }									\
218}
219
220/* Support Solaris-specific format checking for cmn_err.  */
221#define TARGET_N_FORMAT_TYPES 1
222#define TARGET_FORMAT_TYPES solaris_format_types
223
224/* #pragma init and #pragma fini are implemented on top of init and
225   fini attributes.  */
226#define SOLARIS_ATTRIBUTE_TABLE						\
227  { "init",      0, 0, true,  false,  false, NULL },			\
228  { "fini",      0, 0, true,  false,  false, NULL }
229
230/* This is how to declare the size of a function.  For Solaris, we output
231   any .init or .fini entries here.  */
232#undef ASM_DECLARE_FUNCTION_SIZE
233#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)		\
234  do								\
235    {								\
236      if (!flag_inhibit_size_directive)				\
237	ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
238      solaris_output_init_fini (FILE, DECL);			\
239    }								\
240  while (0)
241
242/* Register the Solaris-specific #pragma directives.  */
243#define REGISTER_TARGET_PRAGMAS() solaris_register_pragmas ()
244
245extern GTY(()) tree solaris_pending_aligns;
246extern GTY(()) tree solaris_pending_inits;
247extern GTY(()) tree solaris_pending_finis;
248
249/* Allow macro expansion in #pragma pack.  */
250#define HANDLE_PRAGMA_PACK_WITH_EXPANSION
251