xref: /openbsd/gnu/usr.bin/gcc/gcc/config/sol2.h (revision 771fbea0)
1 /* Operating system specific defines to be used when targeting GCC for any
2    Solaris 2 system.
3    Copyright 2002 Free Software Foundation, Inc.
4 
5 This file is part of GNU CC.
6 
7 GNU CC 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 2, or (at your option)
10 any later version.
11 
12 GNU CC 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 GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, 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 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:-D_REENTRANT -D_PTHREADS} \
51 %{!pthreads:%{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_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_define ("__PRAGMA_REDEFINE_EXTNAME");	\
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_language == clk_cplusplus)		\
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     } while (0)
76 
77 /* The sun bundled assembler doesn't accept -Yd, (and neither does gas).
78    It's safe to pass -s always, even if -g is not used.  */
79 #undef ASM_SPEC
80 #define ASM_SPEC "\
81 %{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Wa,*:%*} -s \
82 %{fpic:-K PIC} %{fPIC:-K PIC} \
83 %(asm_cpu) \
84 "
85 
86 /* We don't use the standard LIB_SPEC only because we don't yet support c++.  */
87 #undef LIB_SPEC
88 #define LIB_SPEC \
89   "%{compat-bsd:-lucb -lsocket -lnsl -lelf -laio} \
90    %{!shared:\
91      %{!symbolic:\
92        %{pthreads:-lpthread} \
93        %{!pthreads:%{threads:-lthread}} \
94        %{p|pg:-ldl} -lc}}"
95 
96 #undef  ENDFILE_SPEC
97 #define ENDFILE_SPEC "crtend.o%s crtn.o%s"
98 
99 /* We don't use the standard svr4 STARTFILE_SPEC because it's wrong for us.  */
100 #undef STARTFILE_SPEC
101 #define STARTFILE_SPEC "%{!shared: \
102 			 %{!symbolic: \
103 			  %{p:mcrt1.o%s} \
104                           %{!p: \
105 	                    %{pg:gcrt1.o%s gmon.o%s} \
106                             %{!pg:crt1.o%s}}}} \
107 			crti.o%s %(startfile_arch) \
108 			crtbegin.o%s"
109 
110 #undef STARTFILE_ARCH32_SPEC
111 #define STARTFILE_ARCH32_SPEC "%{ansi:values-Xc.o%s} \
112 			    %{!ansi:values-Xa.o%s}"
113 
114 #undef STARTFILE_ARCH_SPEC
115 #define STARTFILE_ARCH_SPEC STARTFILE_ARCH32_SPEC
116 
117 #undef LINK_ARCH32_SPEC_BASE
118 #define LINK_ARCH32_SPEC_BASE \
119   "%{G:-G} \
120    %{YP,*} \
121    %{R*} \
122    %{compat-bsd: \
123      %{!YP,*:%{p|pg:-Y P,/usr/ucblib:/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
124              %{!p:%{!pg:-Y P,/usr/ucblib:/usr/ccs/lib:/usr/lib}}} \
125              -R /usr/ucblib} \
126    %{!compat-bsd: \
127      %{!YP,*:%{p|pg:-Y P,/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
128              %{!p:%{!pg:-Y P,/usr/ccs/lib:/usr/lib}}}}"
129 
130 #undef LINK_ARCH32_SPEC
131 #define LINK_ARCH32_SPEC LINK_ARCH32_SPEC_BASE
132 
133 #undef LINK_ARCH_SPEC
134 #define LINK_ARCH_SPEC LINK_ARCH32_SPEC
135 
136 /* This should be the same as in svr4.h, except with -R added.  */
137 #undef  LINK_SPEC
138 #define LINK_SPEC \
139   "%{h*} %{v:-V} \
140    %{b} %{Wl,*:%*} \
141    %{static:-dn -Bstatic} \
142    %{shared:-G -dy %{!mimpure-text:-z text}} \
143    %{symbolic:-Bsymbolic -G -dy -z text} \
144    %(link_arch) \
145    %{Qy:} %{!Qn:-Qy}"
146 
147 /* This defines which switch letters take arguments.
148    It is as in svr4.h but with -R added.  */
149 #undef SWITCH_TAKES_ARG
150 #define SWITCH_TAKES_ARG(CHAR) \
151   (DEFAULT_SWITCH_TAKES_ARG(CHAR) \
152    || (CHAR) == 'R' \
153    || (CHAR) == 'h' \
154    || (CHAR) == 'z')
155 
156 #define STDC_0_IN_SYSTEM_HEADERS 1
157 
158 /*
159  * Attempt to turn on access permissions for the stack.
160  *
161  * This code must be defined when compiling gcc but not when compiling
162  * libgcc2.a, unless we're generating code for 64-bit SPARC
163  *
164  * _SC_STACK_PROT is only defined for post 2.6, but we want this code
165  * to run always.  2.6 can change the stack protection but has no way to
166  * query it.
167  *
168  */
169 
170 /* This declares mprotect (used in TRANSFER_FROM_TRAMPOLINE) for
171    libgcc2.c.  */
172 /* We don't want to include this because sys/mman.h is not present on
173    some non-Solaris configurations that use sol2.h.  */
174 #if 0 /* def L_trampoline */
175 #include <sys/mman.h>
176 #endif
177 
178 #define TRANSFER_FROM_TRAMPOLINE					\
179 									\
180 /* #define STACK_PROT_RWX (PROT_READ | PROT_WRITE | PROT_EXEC) */	\
181 									\
182 static int need_enable_exec_stack;					\
183 									\
184 static void check_enabling(void) __attribute__ ((constructor));		\
185 static void check_enabling(void)					\
186 {									\
187   extern long sysconf(int);						\
188 									\
189   int prot = (int) sysconf(515 /* _SC_STACK_PROT */);			\
190   if (prot != 7 /* STACK_PROT_RWX */)					\
191     need_enable_exec_stack = 1;						\
192 }									\
193 									\
194 extern void __enable_execute_stack (void *);				\
195 void									\
196 __enable_execute_stack (addr)						\
197      void *addr;							\
198 {									\
199   if (!need_enable_exec_stack)						\
200     return;								\
201   else {								\
202     long size = getpagesize ();						\
203     long mask = ~(size-1);						\
204     char *page = (char *) (((long) addr) & mask); 			\
205     char *end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
206 									\
207     if (mprotect (page, end - page, 7 /* STACK_PROT_RWX */) < 0)	\
208       perror ("mprotect of trampoline code");				\
209   }									\
210 }
211