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