xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/config/netbsd.h (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /* Base configuration file for all NetBSD targets.
2    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3    2007 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 /* TARGET_OS_CPP_BUILTINS() common to all NetBSD targets.  */
22 #define NETBSD_OS_CPP_BUILTINS_COMMON()		\
23   do						\
24     {						\
25       builtin_define ("__NetBSD__");		\
26       builtin_define ("__unix__");		\
27       builtin_assert ("system=bsd");		\
28       builtin_assert ("system=unix");		\
29       builtin_assert ("system=NetBSD");		\
30     }						\
31   while (0)
32 
33 /* CPP_SPEC parts common to all NetBSD targets.  */
34 #define NETBSD_CPP_SPEC				\
35   "%{posix:-D_POSIX_SOURCE} \
36    %{pthread:-D_REENTRANT -D_PTHREADS}"
37 
38 /* NETBSD_NATIVE is defined when gcc is integrated into the NetBSD
39    source tree so it can be configured appropriately without using
40    the GNU configure/build mechanism.
41 
42    NETBSD_TOOLS is defined when gcc is built as cross-compiler for
43    the in-tree toolchain.
44  */
45 
46 #if defined(NETBSD_NATIVE) || defined(NETBSD_TOOLS)
47 
48 /* Look for the include files in the system-defined places.  */
49 
50 #undef GPLUSPLUS_INCLUDE_DIR
51 #define GPLUSPLUS_INCLUDE_DIR "/usr/include/g++"
52 
53 #undef GPLUSPLUS_BACKWARD_INCLUDE_DIR
54 #define GPLUSPLUS_BACKWARD_INCLUDE_DIR "/usr/include/g++/backward"
55 
56 /*
57  * XXX figure out a better way to do this
58  */
59 #undef GCC_INCLUDE_DIR
60 #define GCC_INCLUDE_DIR "/usr/include/gcc-4.5"
61 
62 #undef INCLUDE_DEFAULTS
63 #define INCLUDE_DEFAULTS				\
64   {							\
65     { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, 1 },		\
66     { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, 1 },	\
67     { GCC_INCLUDE_DIR, "GCC", 0, 0, 1 },		\
68     { "/usr/include", "GCC", 0, 0, 1 },			\
69     { 0, 0, 0, 0 }					\
70   }
71 
72 /* Under NetBSD, the normal location of the various *crt*.o files is the
73    /usr/lib directory.  */
74 
75 #undef STANDARD_STARTFILE_PREFIX
76 #define STANDARD_STARTFILE_PREFIX	"/usr/lib/"
77 #undef STANDARD_STARTFILE_PREFIX_1
78 #define STANDARD_STARTFILE_PREFIX_1	"/usr/lib/"
79 
80 #endif /* NETBSD_NATIVE || NETBSD_TOOLS */
81 
82 #if defined(NETBSD_NATIVE)
83 /* Under NetBSD, the normal location of the compiler back ends is the
84    /usr/libexec directory.  */
85 
86 #undef STANDARD_EXEC_PREFIX
87 #define STANDARD_EXEC_PREFIX		"/usr/libexec/"
88 
89 #undef TOOLDIR_BASE_PREFIX
90 #define TOOLDIR_BASE_PREFIX		"../"
91 
92 #undef STANDARD_BINDIR_PREFIX
93 #define STANDARD_BINDIR_PREFIX		"/usr/bin"
94 
95 #undef STANDARD_LIBEXEC_PREFIX
96 #define STANDARD_LIBEXEC_PREFIX		STANDARD_EXEC_PREFIX
97 
98 #endif /* NETBSD_NATIVE */
99 
100 
101 /* Provide a LIB_SPEC appropriate for NetBSD.  Here we:
102 
103    1. Select the appropriate set of libs, depending on whether we're
104       profiling.
105 
106    2. Include the pthread library if -pthread is specified (only
107       if threads are enabled).
108 
109    3. Include the posix library if -posix is specified.
110 
111    FIXME: Could eliminate the duplication here if we were allowed to
112    use string concatenation.  */
113 
114 #ifdef NETBSD_ENABLE_PTHREADS
115 #define NETBSD_LIB_SPEC		\
116   "%{pthread:			\
117      %{!p:			\
118        %{!pg:-lpthread}}	\
119      %{p:-lpthread_p}		\
120      %{pg:-lpthread_p}}		\
121    %{posix:			\
122      %{!p:			\
123        %{!pg:-lposix}}		\
124      %{p:-lposix_p}		\
125      %{pg:-lposix_p}}		\
126    %{shared:-lc}		\
127    %{!shared:			\
128      %{!symbolic:		\
129        %{!p:			\
130 	 %{!pg:-lc}}		\
131        %{p:-lc_p}		\
132        %{pg:-lc_p}}}"
133 #else
134 #define NETBSD_LIB_SPEC		\
135   "%{posix:			\
136      %{!p:			\
137        %{!pg:-lposix}}		\
138      %{p:-lposix_p}		\
139      %{pg:-lposix_p}}		\
140    %{shared:-lc}		\
141    %{!shared:			\
142      %{!symbolic:		\
143        %{!p:			\
144 	 %{!pg:-lc}}		\
145        %{p:-lc_p}		\
146        %{pg:-lc_p}}}"
147 #endif
148 
149 #undef LIB_SPEC
150 #define LIB_SPEC NETBSD_LIB_SPEC
151 
152 /* Pass -cxx-isystem to cc1/cc1plus.  */
153 #define NETBSD_CC1_AND_CC1PLUS_SPEC		\
154   "%{cxx-isystem}"
155 
156 #undef CC1_SPEC
157 #define CC1_SPEC NETBSD_CC1_AND_CC1PLUS_SPEC
158 
159 #undef CC1PLUS_SPEC
160 #define CC1PLUS_SPEC NETBSD_CC1_AND_CC1PLUS_SPEC
161 
162 /* When building shared libraries, the initialization and finalization
163    functions for the library are .init and .fini respectively.  */
164 
165 #define COLLECT_SHARED_INIT_FUNC(STREAM,FUNC)				\
166   do {									\
167     fprintf ((STREAM), "void __init() __asm__ (\".init\");");		\
168     fprintf ((STREAM), "void __init() {\n\t%s();\n}\n", (FUNC));	\
169   } while (0)
170 
171 #define COLLECT_SHARED_FINI_FUNC(STREAM,FUNC)				\
172   do {									\
173     fprintf ((STREAM), "void __fini() __asm__ (\".fini\");");		\
174     fprintf ((STREAM), "void __fini() {\n\t%s();\n}\n", (FUNC));	\
175   } while (0)
176 
177 #undef TARGET_POSIX_IO
178 #define TARGET_POSIX_IO
179 
180 /* Handle #pragma weak and #pragma pack.  */
181 
182 #define HANDLE_SYSV_PRAGMA 1
183 
184 /* Don't assume anything about the header files.  */
185 #undef  NO_IMPLICIT_EXTERN_C
186 #define NO_IMPLICIT_EXTERN_C    1
187 
188 /* Define some types that are the same on all NetBSD platforms,
189    making them agree with <machine/ansi.h>.  */
190 
191 #undef WCHAR_TYPE
192 #define WCHAR_TYPE "int"
193 
194 #undef WCHAR_TYPE_SIZE
195 #define WCHAR_TYPE_SIZE 32
196 
197 #undef WINT_TYPE
198 #define WINT_TYPE "int"
199 
200 
201 /* Attempt to turn on execute permission for the stack.  This may be
202    used by TARGET_TRAMPOLINE_INIT if the target needs it (that is,
203    if the target machine can change execute permissions on a page).
204 
205    There is no way to query the execute permission of the stack, so
206    we always issue the mprotect() call.
207 
208    Note that we go out of our way to use namespace-non-invasive calls
209    here.  Unfortunately, there is no libc-internal name for mprotect().
210 
211    Also note that no errors should be emitted by this code; it is considered
212    dangerous for library calls to send messages to stdout/stderr.  */
213 
214 #define NETBSD_ENABLE_EXECUTE_STACK					\
215 extern void __enable_execute_stack (void *);				\
216 void									\
217 __enable_execute_stack (void *addr)					\
218 {									\
219   extern int mprotect (void *, size_t, int);				\
220   extern int __sysctl (int *, unsigned int, void *, size_t *,		\
221 		       void *, size_t);					\
222 									\
223   static int size;							\
224   static long mask;							\
225 									\
226   char *page, *end;							\
227 									\
228   if (size == 0)							\
229     {									\
230       int mib[2];							\
231       size_t len;							\
232 									\
233       mib[0] = 6; /* CTL_HW */						\
234       mib[1] = 7; /* HW_PAGESIZE */					\
235       len = sizeof (size);						\
236       (void) __sysctl (mib, 2, &size, &len, NULL, 0);			\
237       mask = ~((long) size - 1);					\
238     }									\
239 									\
240   page = (char *) (((long) addr) & mask);				\
241   end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size);	\
242 									\
243   /* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */				\
244   (void) mprotect (page, end - page, 7);				\
245 }
246 
247 /* Define this so we can compile MS code for use with WINE.  */
248 #define HANDLE_PRAGMA_PACK_PUSH_POP 1
249 
250 #if defined(HAVE_LD_EH_FRAME_HDR)
251 #define LINK_EH_SPEC "--eh-frame-hdr "
252 #endif
253