OSDN Git Service

* config/darwin-c.c (darwin_pragma_options): Use BAD instead.
[pf3gnuchains/gcc-fork.git] / gcc / config / openbsd.h
1 /* Base configuration file for all OpenBSD targets.
2    Copyright (C) 1999, 2000, 2004, 2005 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.  */
20
21 /* Common OpenBSD configuration. 
22    All OpenBSD architectures include this file, which is intended as
23    a repository for common defines. 
24
25    Some defines are common to all architectures, a few of them are
26    triggered by OBSD_* guards, so that we won't override architecture
27    defaults by mistakes.
28
29    OBSD_HAS_CORRECT_SPECS: 
30       another mechanism provides correct specs already.
31    OBSD_NO_DYNAMIC_LIBRARIES: 
32       no implementation of dynamic libraries.
33    OBSD_OLD_GAS: 
34       older flavor of gas which needs help for PIC.
35    OBSD_HAS_DECLARE_FUNCTION_NAME, OBSD_HAS_DECLARE_FUNCTION_SIZE,
36    OBSD_HAS_DECLARE_OBJECT: 
37       PIC support, FUNCTION_NAME/FUNCTION_SIZE are independent, whereas
38       the corresponding logic for OBJECTS is necessarily coupled.
39
40    There are also a few `default' defines such as ASM_WEAKEN_LABEL,
41    intended as common ground for arch that don't provide 
42    anything suitable.  */
43
44 /* OPENBSD_NATIVE is defined only when gcc is configured as part of
45    the OpenBSD source tree, specifically through Makefile.bsd-wrapper.
46
47    In such a case the include path can be trimmed as there is no
48    distinction between system includes and gcc includes.  */
49
50 /* This configuration method, namely Makefile.bsd-wrapper and
51    OPENBSD_NATIVE is NOT recommended for building cross-compilers.  */
52
53 #ifdef OPENBSD_NATIVE
54
55 /* The compiler is configured with ONLY the gcc/g++ standard headers.  */
56 #undef INCLUDE_DEFAULTS
57 #define INCLUDE_DEFAULTS                        \
58   {                                             \
59     { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 },     \
60     { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1 }, \
61     { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1 }, \
62     { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 }, \
63     { 0, 0, 0, 0 }                              \
64   }
65
66 /* Under OpenBSD, the normal location of the various *crt*.o files is the
67    /usr/lib directory.  */
68 #undef STANDARD_STARTFILE_PREFIX
69 #define STANDARD_STARTFILE_PREFIX       "/usr/local/lib/"
70
71 #endif
72
73 \f
74 /* Controlling the compilation driver.  */
75 /* TARGET_OS_CPP_BUILTINS() common to all OpenBSD targets.  */
76 #define OPENBSD_OS_CPP_BUILTINS()               \
77   do                                            \
78     {                                           \
79       builtin_define ("__OpenBSD__");           \
80       builtin_define ("__unix__");              \
81       builtin_define ("__ANSI_COMPAT");         \
82       builtin_assert ("system=unix");           \
83       builtin_assert ("system=bsd");            \
84       builtin_assert ("system=OpenBSD");        \
85     }                                           \
86   while (0)
87
88 /* CPP_SPEC appropriate for OpenBSD. We deal with -posix and -pthread.
89    XXX the way threads are handled currently is not very satisfying,
90    since all code must be compiled with -pthread to work. 
91    This two-stage defines makes it easy to pick that for targets that
92    have subspecs.  */
93 #ifdef CPP_CPU_SPEC
94 #define OBSD_CPP_SPEC "%(cpp_cpu) %{posix:-D_POSIX_SOURCE} %{pthread:-D_POSIX_THREADS}"
95 #else
96 #define OBSD_CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_POSIX_THREADS}"
97 #endif
98
99 /* LIB_SPEC appropriate for OpenBSD.  */
100 #ifdef HAS_LIBC_R
101 /*   -lc(_r)?(_p)?, select _r for threads, and _p for p or pg.  */
102 # define OBSD_LIB_SPEC "%{!shared:-lc%{pthread:_r}%{p:_p}%{!p:%{pg:_p}}}"
103 #else
104 /* Include -lpthread if -pthread is specified on the command line. */
105 # define OBSD_LIB_SPEC "%{!shared:%{pthread:-lpthread%{p:_p}%{!p:%{pg:_p}}}} %{!shared:-lc%{p:_p}%{!p:%{pg:_p}}}"
106 #endif
107
108
109 #ifndef OBSD_HAS_CORRECT_SPECS
110
111 #ifndef OBSD_NO_DYNAMIC_LIBRARIES
112 #undef SWITCH_TAKES_ARG
113 #define SWITCH_TAKES_ARG(CHAR) \
114   (DEFAULT_SWITCH_TAKES_ARG (CHAR) \
115    || (CHAR) == 'R')
116 #endif
117
118 #undef CPP_SPEC
119 #define CPP_SPEC OBSD_CPP_SPEC
120
121 #ifdef OBSD_OLD_GAS
122 /* ASM_SPEC appropriate for OpenBSD.  For some architectures, OpenBSD 
123    still uses a special flavor of gas that needs to be told when generating 
124    pic code.  */
125 #undef ASM_SPEC
126 #define ASM_SPEC "%{fpic|fpie:-k} %{fPIC|fPIE:-k -K}"
127 #endif
128
129 /* Since we use gas, stdin -> - is a good idea.  */
130 #define AS_NEEDS_DASH_FOR_PIPED_INPUT
131
132 /* LINK_SPEC appropriate for OpenBSD.  Support for GCC options 
133    -static, -assert, and -nostdlib.  */
134 #undef LINK_SPEC
135 #ifdef OBSD_NO_DYNAMIC_LIBRARIES
136 #define LINK_SPEC \
137   "%{g:%{!nostdlib:-L/usr/lib/debug}} %{!nostdlib:%{!r*:%{!e*:-e start}}} -dc -dp %{assert*}"
138 #else
139 #define LINK_SPEC \
140   "%{g:%{!nostdlib:-L/usr/lib/debug}} %{!shared:%{!nostdlib:%{!r*:%{!e*:-e start}}}} %{shared:-Bshareable -x} -dc -dp %{R*} %{static:-Bstatic} %{assert*}"
141 #endif
142
143 #undef LIB_SPEC
144 #define LIB_SPEC OBSD_LIB_SPEC
145 #endif
146
147 \f
148 /* Runtime target specification.  */
149
150 /* Miscellaneous parameters.  */
151
152 /* Controlling debugging info: dbx options.  */
153
154 /* Don't use the `xsTAG;' construct in DBX output; OpenBSD systems that
155    use DBX don't support it.  */
156 #define DBX_NO_XREFS
157
158 \f
159 /* Support of shared libraries, mostly imported from svr4.h through netbsd.  */
160 /* Two differences from svr4.h:
161    - we use . - _func instead of a local label,
162    - we put extra spaces in expressions such as 
163      .type _func , @function
164      This is more readable for a human being and confuses c++filt less.  */
165
166 /* Assembler format: output and generation of labels.  */
167
168 /* Define the strings used for the .type and .size directives.
169    These strings generally do not vary from one system running OpenBSD
170    to another, but if a given system needs to use different pseudo-op
171    names for these, they may be overridden in the arch specific file.  */ 
172
173 /* OpenBSD assembler is hacked to have .type & .size support even in a.out
174    format object files.  Functions size are supported but not activated 
175    yet (look for GRACE_PERIOD_EXPIRED in gas/config/obj-aout.c).  
176    SET_ASM_OP is needed for attribute alias to work.  */
177
178 #undef TYPE_ASM_OP
179 #undef SIZE_ASM_OP
180 #undef SET_ASM_OP
181 #undef GLOBAL_ASM_OP
182
183 #define TYPE_ASM_OP     "\t.type\t"
184 #define SIZE_ASM_OP     "\t.size\t"
185 #define SET_ASM_OP      "\t.set\t"
186 #define GLOBAL_ASM_OP   "\t.globl\t"
187
188 /* The following macro defines the format used to output the second
189    operand of the .type assembler directive.  */
190 #undef TYPE_OPERAND_FMT
191 #define TYPE_OPERAND_FMT        "@%s"
192
193 /* Provision if extra assembler code is needed to declare a function's result
194    (taken from svr4, not needed yet actually).  */
195 #ifndef ASM_DECLARE_RESULT
196 #define ASM_DECLARE_RESULT(FILE, RESULT)
197 #endif
198
199 /* These macros generate the special .type and .size directives which
200    are used to set the corresponding fields of the linker symbol table
201    entries under OpenBSD.  These macros also have to output the starting 
202    labels for the relevant functions/objects.  */
203
204 #ifndef OBSD_HAS_DECLARE_FUNCTION_NAME
205 /* Extra assembler code needed to declare a function properly.
206    Some assemblers may also need to also have something extra said 
207    about the function's return value.  We allow for that here.  */
208 #undef ASM_DECLARE_FUNCTION_NAME
209 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)                     \
210   do {                                                                  \
211     ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");                 \
212     ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL));                      \
213     ASM_OUTPUT_LABEL(FILE, NAME);                                       \
214   } while (0)
215 #endif
216
217 #ifndef OBSD_HAS_DECLARE_FUNCTION_SIZE
218 /* Declare the size of a function.  */
219 #undef ASM_DECLARE_FUNCTION_SIZE
220 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)            \
221   do {                                                          \
222     if (!flag_inhibit_size_directive)                           \
223       ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);                   \
224   } while (0)
225 #endif
226
227 #ifndef OBSD_HAS_DECLARE_OBJECT
228 /* Extra assembler code needed to declare an object properly.  */
229 #undef ASM_DECLARE_OBJECT_NAME
230 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)               \
231   do {                                                          \
232       HOST_WIDE_INT size;                                       \
233       ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object");         \
234       size_directive_output = 0;                                \
235       if (!flag_inhibit_size_directive                          \
236           && (DECL) && DECL_SIZE (DECL))                        \
237         {                                                       \
238           size_directive_output = 1;                            \
239           size = int_size_in_bytes (TREE_TYPE (DECL));          \
240           ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size);         \
241         }                                                       \
242       ASM_OUTPUT_LABEL (FILE, NAME);                            \
243   } while (0)
244
245 /* Output the size directive for a decl in rest_of_decl_compilation
246    in the case where we did not do so before the initializer.
247    Once we find the error_mark_node, we know that the value of
248    size_directive_output was set by ASM_DECLARE_OBJECT_NAME 
249    when it was run for the same decl.  */
250 #undef ASM_FINISH_DECLARE_OBJECT
251 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)         \
252 do {                                                                     \
253      const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0);             \
254      HOST_WIDE_INT size;                                                 \
255      if (!flag_inhibit_size_directive && DECL_SIZE (DECL)                \
256          && ! AT_END && TOP_LEVEL                                        \
257          && DECL_INITIAL (DECL) == error_mark_node                       \
258          && !size_directive_output)                                      \
259        {                                                                 \
260          size_directive_output = 1;                                      \
261          size = int_size_in_bytes (TREE_TYPE (DECL));                    \
262          ASM_OUTPUT_SIZE_DIRECTIVE (FILE, name, size);                   \
263        }                                                                 \
264    } while (0)
265 #endif
266
267 \f
268 /* Those are `generic' ways to weaken/globalize a label. We shouldn't need
269    to override a processor specific definition. Hence, #ifndef ASM_*
270    In case overriding turns out to be needed, one can always #undef ASM_* 
271    before including this file.  */
272
273 /* Tell the assembler that a symbol is weak.  */
274 /* Note: netbsd arm32 assembler needs a .globl here. An override may 
275    be needed when/if we go for arm32 support.  */
276 #ifndef ASM_WEAKEN_LABEL
277 #define ASM_WEAKEN_LABEL(FILE,NAME) \
278   do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \
279        fputc ('\n', FILE); } while (0)
280 #endif
281 \f
282 /* Storage layout.  */
283
284 \f
285 /* Otherwise, since we support weak, gthr.h erroneously tries to use
286    #pragma weak.  */
287 #define GTHREAD_USE_WEAK 0
288
289 /* bug work around: we don't want to support #pragma weak, but the current
290    code layout needs HANDLE_PRAGMA_WEAK asserted for __attribute((weak)) to
291    work.  On the other hand, we don't define HANDLE_PRAGMA_WEAK directly,
292    as this depends on a few other details as well...  */
293 #define HANDLE_SYSV_PRAGMA 1
294
295 /* Stack is explicitly denied execution rights on OpenBSD platforms.  */
296 #define ENABLE_EXECUTE_STACK                                            \
297 extern void __enable_execute_stack (void *);                            \
298 void                                                                    \
299 __enable_execute_stack (void *addr)                                     \
300 {                                                                       \
301   long size = getpagesize ();                                           \
302   long mask = ~(size-1);                                                \
303   char *page = (char *) (((long) addr) & mask);                         \
304   char *end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
305                                                                       \
306   if (mprotect (page, end - page, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) \
307     perror ("mprotect of trampoline code");                             \
308 }
309
310 #include <sys/types.h>
311 #include <sys/mman.h>