OSDN Git Service

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