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