1117395Skan/* Operating system specific defines to be used when targeting GCC for any
2117395Skan   Solaris 2 system.
3169689Skan   Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
4117395Skan
5132718SkanThis file is part of GCC.
6117395Skan
7132718SkanGCC is free software; you can redistribute it and/or modify
8117395Skanit under the terms of the GNU General Public License as published by
9117395Skanthe Free Software Foundation; either version 2, or (at your option)
10117395Skanany later version.
11117395Skan
12132718SkanGCC is distributed in the hope that it will be useful,
13117395Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of
14117395SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15117395SkanGNU General Public License for more details.
16117395Skan
17117395SkanYou should have received a copy of the GNU General Public License
18132718Skanalong with GCC; see the file COPYING.  If not, write to
19169689Skanthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
20169689SkanBoston, MA 02110-1301, USA.  */
21117395Skan
22117395Skan/* We use stabs-in-elf for debugging, because that is what the native
23117395Skan   toolchain uses.  */
24117395Skan#undef PREFERRED_DEBUGGING_TYPE
25117395Skan#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
26117395Skan
27117395Skan/* Solaris 2 (at least as of 2.5.1) uses a 32-bit wchar_t.  */
28117395Skan#undef WCHAR_TYPE
29117395Skan#define WCHAR_TYPE "long int"
30117395Skan
31117395Skan#undef WCHAR_TYPE_SIZE
32117395Skan#define WCHAR_TYPE_SIZE BITS_PER_WORD
33117395Skan
34117395Skan/* Solaris 2 uses a wint_t different from the default. This is required
35117395Skan   by the SCD 2.4.1, p. 6-83, Figure 6-66.  */
36117395Skan#undef	WINT_TYPE
37117395Skan#define	WINT_TYPE "long int"
38117395Skan
39117395Skan#undef	WINT_TYPE_SIZE
40117395Skan#define	WINT_TYPE_SIZE BITS_PER_WORD
41117395Skan
42169689Skan#define TARGET_HANDLE_PRAGMA_REDEFINE_EXTNAME 1
43117395Skan
44117395Skan/* ??? Note: in order for -compat-bsd to work fully,
45117395Skan   we must somehow arrange to fixincludes /usr/ucbinclude
46117395Skan   and put the result in $(libsubdir)/ucbinclude.  */
47117395Skan
48117395Skan#undef CPP_SUBTARGET_SPEC
49117395Skan#define CPP_SUBTARGET_SPEC "\
50169689Skan%{pthreads|pthread:-D_REENTRANT -D_PTHREADS} \
51169689Skan%{!pthreads:%{!pthread:%{threads:-D_REENTRANT -D_SOLARIS_THREADS}}} \
52117395Skan%{compat-bsd:-iwithprefixbefore ucbinclude -I/usr/ucbinclude} \
53117395Skan"
54117395Skan
55117395Skan/* Names to predefine in the preprocessor for this target machine.  */
56132718Skan#define TARGET_SUB_OS_CPP_BUILTINS()
57117395Skan#define TARGET_OS_CPP_BUILTINS()			\
58117395Skan    do {						\
59117395Skan	builtin_define_std ("unix");			\
60117395Skan	builtin_define_std ("sun");			\
61117395Skan	builtin_define ("__svr4__");			\
62117395Skan	builtin_define ("__SVR4");			\
63117395Skan	builtin_assert ("system=unix");			\
64117395Skan	builtin_assert ("system=svr4");			\
65132718Skan	/* For C++ we need to add some additional macro	\
66117395Skan	   definitions required by the C++ standard	\
67117395Skan	   library.  */					\
68132718Skan	if (c_dialect_cxx ())				\
69117395Skan	  {						\
70117395Skan	    builtin_define ("_XOPEN_SOURCE=500");	\
71117395Skan	    builtin_define ("_LARGEFILE_SOURCE=1");	\
72117395Skan	    builtin_define ("_LARGEFILE64_SOURCE=1");	\
73117395Skan	    builtin_define ("__EXTENSIONS__");		\
74117395Skan	  }						\
75132718Skan	TARGET_SUB_OS_CPP_BUILTINS();			\
76117395Skan    } while (0)
77117395Skan
78132718Skan/* The system headers under Solaris 2 are C++-aware since 2.0.  */
79132718Skan#define NO_IMPLICIT_EXTERN_C
80132718Skan
81117395Skan/* The sun bundled assembler doesn't accept -Yd, (and neither does gas).
82117395Skan   It's safe to pass -s always, even if -g is not used.  */
83117395Skan#undef ASM_SPEC
84117395Skan#define ASM_SPEC "\
85117395Skan%{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Wa,*:%*} -s \
86132718Skan%{fpic|fpie|fPIC|fPIE:-K PIC} \
87117395Skan%(asm_cpu) \
88117395Skan"
89117395Skan
90117395Skan/* We don't use the standard LIB_SPEC only because we don't yet support c++.  */
91117395Skan#undef LIB_SPEC
92117395Skan#define LIB_SPEC \
93117395Skan  "%{compat-bsd:-lucb -lsocket -lnsl -lelf -laio} \
94117395Skan   %{!shared:\
95117395Skan     %{!symbolic:\
96169689Skan       %{pthreads|pthread:-lpthread} \
97169689Skan       %{!pthreads:%{!pthread:%{threads:-lthread}}} \
98117395Skan       %{p|pg:-ldl} -lc}}"
99117395Skan
100117395Skan#undef  ENDFILE_SPEC
101117395Skan#define ENDFILE_SPEC "crtend.o%s crtn.o%s"
102117395Skan
103117395Skan/* We don't use the standard svr4 STARTFILE_SPEC because it's wrong for us.  */
104117395Skan#undef STARTFILE_SPEC
105117395Skan#define STARTFILE_SPEC "%{!shared: \
106117395Skan			 %{!symbolic: \
107117395Skan			  %{p:mcrt1.o%s} \
108117395Skan                          %{!p: \
109117395Skan	                    %{pg:gcrt1.o%s gmon.o%s} \
110117395Skan                            %{!pg:crt1.o%s}}}} \
111117395Skan			crti.o%s %(startfile_arch) \
112117395Skan			crtbegin.o%s"
113117395Skan
114117395Skan#undef STARTFILE_ARCH32_SPEC
115117395Skan#define STARTFILE_ARCH32_SPEC "%{ansi:values-Xc.o%s} \
116117395Skan			    %{!ansi:values-Xa.o%s}"
117117395Skan
118117395Skan#undef STARTFILE_ARCH_SPEC
119117395Skan#define STARTFILE_ARCH_SPEC STARTFILE_ARCH32_SPEC
120117395Skan
121132718Skan#undef LINK_ARCH32_SPEC_BASE
122132718Skan#define LINK_ARCH32_SPEC_BASE \
123117395Skan  "%{G:-G} \
124117395Skan   %{YP,*} \
125117395Skan   %{R*} \
126117395Skan   %{compat-bsd: \
127117395Skan     %{!YP,*:%{p|pg:-Y P,/usr/ucblib:/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
128117395Skan             %{!p:%{!pg:-Y P,/usr/ucblib:/usr/ccs/lib:/usr/lib}}} \
129117395Skan             -R /usr/ucblib} \
130117395Skan   %{!compat-bsd: \
131117395Skan     %{!YP,*:%{p|pg:-Y P,/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
132117395Skan             %{!p:%{!pg:-Y P,/usr/ccs/lib:/usr/lib}}}}"
133117395Skan
134132718Skan#undef LINK_ARCH32_SPEC
135132718Skan#define LINK_ARCH32_SPEC LINK_ARCH32_SPEC_BASE
136132718Skan
137117395Skan#undef LINK_ARCH_SPEC
138117395Skan#define LINK_ARCH_SPEC LINK_ARCH32_SPEC
139117395Skan
140117395Skan/* This should be the same as in svr4.h, except with -R added.  */
141117395Skan#undef  LINK_SPEC
142117395Skan#define LINK_SPEC \
143117395Skan  "%{h*} %{v:-V} \
144169689Skan   %{b} \
145117395Skan   %{static:-dn -Bstatic} \
146117395Skan   %{shared:-G -dy %{!mimpure-text:-z text}} \
147117395Skan   %{symbolic:-Bsymbolic -G -dy -z text} \
148117395Skan   %(link_arch) \
149117395Skan   %{Qy:} %{!Qn:-Qy}"
150117395Skan
151169689Skan/* The Solaris linker doesn't understand constructor priorities.  (The
152169689Skan   GNU linker does support constructor priorities, so GNU ld
153169689Skan   configuration files for Solaris override this setting.)  */
154169689Skan#undef SUPPORTS_INIT_PRIORITY
155169689Skan#define SUPPORTS_INIT_PRIORITY 0
156169689Skan
157117395Skan/* This defines which switch letters take arguments.
158117395Skan   It is as in svr4.h but with -R added.  */
159117395Skan#undef SWITCH_TAKES_ARG
160117395Skan#define SWITCH_TAKES_ARG(CHAR) \
161117395Skan  (DEFAULT_SWITCH_TAKES_ARG(CHAR) \
162117395Skan   || (CHAR) == 'R' \
163117395Skan   || (CHAR) == 'h' \
164117395Skan   || (CHAR) == 'z')
165117395Skan
166117395Skan#define STDC_0_IN_SYSTEM_HEADERS 1
167117395Skan
168117395Skan/*
169117395Skan * Attempt to turn on access permissions for the stack.
170117395Skan *
171117395Skan * _SC_STACK_PROT is only defined for post 2.6, but we want this code
172117395Skan * to run always.  2.6 can change the stack protection but has no way to
173117395Skan * query it.
174117395Skan *
175117395Skan */
176117395Skan
177132718Skan/* sys/mman.h is not present on some non-Solaris configurations
178132718Skan   that use sol2.h, so ENABLE_EXECUTE_STACK must use a magic
179132718Skan   number instead of the appropriate PROT_* flags.  */
180117395Skan
181132718Skan#define ENABLE_EXECUTE_STACK					\
182117395Skan									\
183117395Skan/* #define STACK_PROT_RWX (PROT_READ | PROT_WRITE | PROT_EXEC) */	\
184117395Skan									\
185117395Skanstatic int need_enable_exec_stack;					\
186117395Skan									\
187117395Skanstatic void check_enabling(void) __attribute__ ((constructor));		\
188117395Skanstatic void check_enabling(void)					\
189117395Skan{									\
190117395Skan  extern long sysconf(int);						\
191117395Skan									\
192117395Skan  int prot = (int) sysconf(515 /* _SC_STACK_PROT */);			\
193117395Skan  if (prot != 7 /* STACK_PROT_RWX */)					\
194117395Skan    need_enable_exec_stack = 1;						\
195117395Skan}									\
196117395Skan									\
197117395Skanextern void __enable_execute_stack (void *);				\
198117395Skanvoid									\
199132718Skan__enable_execute_stack (void *addr)					\
200117395Skan{									\
201169689Skan  extern int mprotect(void *, size_t, int);				\
202117395Skan  if (!need_enable_exec_stack)						\
203117395Skan    return;								\
204117395Skan  else {								\
205117395Skan    long size = getpagesize ();						\
206117395Skan    long mask = ~(size-1);						\
207117395Skan    char *page = (char *) (((long) addr) & mask); 			\
208117395Skan    char *end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
209117395Skan									\
210117395Skan    if (mprotect (page, end - page, 7 /* STACK_PROT_RWX */) < 0)	\
211117395Skan      perror ("mprotect of trampoline code");				\
212117395Skan  }									\
213117395Skan}
214169689Skan
215169689Skan/* Support Solaris-specific format checking for cmn_err.  */
216169689Skan#define TARGET_N_FORMAT_TYPES 1
217169689Skan#define TARGET_FORMAT_TYPES solaris_format_types
218169689Skan
219169689Skan/* #pragma init and #pragma fini are implemented on top of init and
220169689Skan   fini attributes.  */
221169689Skan#define SOLARIS_ATTRIBUTE_TABLE						\
222169689Skan  { "init",      0, 0, true,  false,  false, NULL },			\
223169689Skan  { "fini",      0, 0, true,  false,  false, NULL }
224169689Skan
225169689Skan/* This is how to declare the size of a function.  For Solaris, we output
226169689Skan   any .init or .fini entries here.  */
227169689Skan#undef ASM_DECLARE_FUNCTION_SIZE
228169689Skan#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)		\
229169689Skan  do								\
230169689Skan    {								\
231169689Skan      if (!flag_inhibit_size_directive)				\
232169689Skan	ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
233169689Skan      solaris_output_init_fini (FILE, DECL);			\
234169689Skan    }								\
235169689Skan  while (0)
236169689Skan
237169689Skan/* Register the Solaris-specific #pragma directives.  */
238169689Skan#define REGISTER_TARGET_PRAGMAS() solaris_register_pragmas ()
239169689Skan
240169689Skanextern GTY(()) tree solaris_pending_aligns;
241169689Skanextern GTY(()) tree solaris_pending_inits;
242169689Skanextern GTY(()) tree solaris_pending_finis;
243169689Skan
244169689Skan/* Allow macro expansion in #pragma pack.  */
245169689Skan#define HANDLE_PRAGMA_PACK_WITH_EXPANSION
246