1 /* Base configuration file for all OpenBSD targets.
2    Copyright (C) 1999-2013 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 3, 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 COPYING3.  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 #define INCLUDE_DEFAULTS			\
57   {						\
58     { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 },	\
59     { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1 }, \
60     { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1 }, \
61     { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0 }, \
62     { 0, 0, 0, 0 }				\
63   }
64 
65 /* Under OpenBSD, the normal location of the various *crt*.o files is the
66    /usr/lib directory.  */
67 #undef STANDARD_STARTFILE_PREFIX
68 #define STANDARD_STARTFILE_PREFIX	"/usr/local/lib/"
69 
70 #endif
71 
72 
73 /* Controlling the compilation driver.  */
74 /* TARGET_OS_CPP_BUILTINS() common to all OpenBSD targets.  */
75 #define OPENBSD_OS_CPP_BUILTINS()		\
76   do						\
77     {						\
78       builtin_define ("__OpenBSD__");		\
79       builtin_define ("__unix__");		\
80       builtin_define ("__ANSI_COMPAT");		\
81       builtin_assert ("system=unix");		\
82       builtin_assert ("system=bsd");		\
83       builtin_assert ("system=OpenBSD");	\
84     }						\
85   while (0)
86 
87 /* TARGET_OS_CPP_BUILTINS() common to all OpenBSD ELF targets.  */
88 #define OPENBSD_OS_CPP_BUILTINS_ELF()		\
89   do						\
90     {						\
91       OPENBSD_OS_CPP_BUILTINS();		\
92       builtin_define ("__ELF__");		\
93     }						\
94 while (0)
95 
96 /* TARGET_OS_CPP_BUILTINS() common to all LP64 OpenBSD targets.  */
97 #define OPENBSD_OS_CPP_BUILTINS_LP64()		\
98   do						\
99     {						\
100       builtin_define ("_LP64");			\
101       builtin_define ("__LP64__");		\
102     }						\
103   while (0)
104 
105 /* CPP_SPEC appropriate for OpenBSD. We deal with -posix and -pthread.
106    XXX the way threads are handled currently is not very satisfying,
107    since all code must be compiled with -pthread to work.
108    This two-stage defines makes it easy to pick that for targets that
109    have subspecs.  */
110 #ifdef CPP_CPU_SPEC
111 #define OBSD_CPP_SPEC "%(cpp_cpu) %{posix:-D_POSIX_SOURCE} %{pthread:-D_POSIX_THREADS}"
112 #else
113 #define OBSD_CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_POSIX_THREADS}"
114 #endif
115 
116 #undef LIB_SPEC
117 #define LIB_SPEC OBSD_LIB_SPEC
118 
119 #ifndef OBSD_HAS_CORRECT_SPECS
120 
121 #undef CPP_SPEC
122 #define CPP_SPEC OBSD_CPP_SPEC
123 
124 #ifdef OBSD_OLD_GAS
125 /* ASM_SPEC appropriate for OpenBSD.  For some architectures, OpenBSD
126    still uses a special flavor of gas that needs to be told when generating
127    pic code.  */
128 #undef ASM_SPEC
129 #define ASM_SPEC "%{fpic|fpie:-k} %{fPIC|fPIE:-k -K}"
130 #endif
131 
132 /* Since we use gas, stdin -> - is a good idea.  */
133 #define AS_NEEDS_DASH_FOR_PIPED_INPUT
134 
135 #undef LIB_SPEC
136 #define LIB_SPEC OBSD_LIB_SPEC
137 
138 #if defined(HAVE_LD_EH_FRAME_HDR)
139 #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
140 #endif
141 
142 #undef LIB_SPEC
143 #define LIB_SPEC OBSD_LIB_SPEC
144 #endif
145 
146 #define TARGET_POSIX_IO
147 
148 /* All new versions of OpenBSD have C99 functions.  */
149 #define TARGET_C99_FUNCTIONS 1
150 
151 
152 /* Runtime target specification.  */
153 
154 /* Miscellaneous parameters.  */
155 
156 /* Controlling debugging info: dbx options.  */
157 
158 /* Don't use the `xsTAG;' construct in DBX output; OpenBSD systems that
159    use DBX don't support it.  */
160 #define DBX_NO_XREFS
161 
162 
163 /* - we use . - _func instead of a local label,
164    - we put extra spaces in expressions such as
165      .type _func , @function
166      This is more readable for a human being and confuses c++filt less.  */
167 
168 /* Assembler format: output and generation of labels.  */
169 
170 /* Define the strings used for the .type and .size directives.
171    These strings generally do not vary from one system running OpenBSD
172    to another, but if a given system needs to use different pseudo-op
173    names for these, they may be overridden in the arch specific file.  */
174 
175 /* OpenBSD assembler is hacked to have .type & .size support even in a.out
176    format object files.  Functions size are supported but not activated
177    yet (look for GRACE_PERIOD_EXPIRED in gas/config/obj-aout.c).
178    SET_ASM_OP is needed for attribute alias to work.  */
179 
180 #undef TYPE_ASM_OP
181 #undef SIZE_ASM_OP
182 #undef SET_ASM_OP
183 #undef GLOBAL_ASM_OP
184 
185 #define TYPE_ASM_OP	"\t.type\t"
186 #define SIZE_ASM_OP	"\t.size\t"
187 #define SET_ASM_OP	"\t.set\t"
188 #define GLOBAL_ASM_OP	"\t.globl\t"
189 
190 /* The following macro defines the format used to output the second
191    operand of the .type assembler directive.  */
192 #undef TYPE_OPERAND_FMT
193 #define TYPE_OPERAND_FMT	"@%s"
194 
195 /* Provision if extra assembler code is needed to declare a function's result
196    (taken from svr4, not needed yet actually).  */
197 #ifndef ASM_DECLARE_RESULT
198 #define ASM_DECLARE_RESULT(FILE, RESULT)
199 #endif
200 
201 /* These macros generate the special .type and .size directives which
202    are used to set the corresponding fields of the linker symbol table
203    entries under OpenBSD.  These macros also have to output the starting
204    labels for the relevant functions/objects.  */
205 
206 #ifndef OBSD_HAS_DECLARE_FUNCTION_NAME
207 /* Extra assembler code needed to declare a function properly.
208    Some assemblers may also need to also have something extra said
209    about the function's return value.  We allow for that here.  */
210 #undef ASM_DECLARE_FUNCTION_NAME
211 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)			\
212   do {									\
213     ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");			\
214     ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL));			\
215     ASM_OUTPUT_FUNCTION_LABEL (FILE, NAME, DECL);			\
216   } while (0)
217 #endif
218 
219 #ifndef OBSD_HAS_DECLARE_FUNCTION_SIZE
220 /* Declare the size of a function.  */
221 #undef ASM_DECLARE_FUNCTION_SIZE
222 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)		\
223   do {								\
224     if (!flag_inhibit_size_directive)				\
225       ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
226   } while (0)
227 #endif
228 
229 #ifndef OBSD_HAS_DECLARE_OBJECT
230 /* Extra assembler code needed to declare an object properly.  */
231 #undef ASM_DECLARE_OBJECT_NAME
232 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)		\
233   do {								\
234       HOST_WIDE_INT size;					\
235       ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object");		\
236       size_directive_output = 0;				\
237       if (!flag_inhibit_size_directive				\
238 	  && (DECL) && DECL_SIZE (DECL))			\
239 	{							\
240 	  size_directive_output = 1;				\
241 	  size = int_size_in_bytes (TREE_TYPE (DECL));		\
242 	  ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size);		\
243 	}							\
244       ASM_OUTPUT_LABEL (FILE, NAME);				\
245   } while (0)
246 
247 /* Output the size directive for a decl in rest_of_decl_compilation
248    in the case where we did not do so before the initializer.
249    Once we find the error_mark_node, we know that the value of
250    size_directive_output was set by ASM_DECLARE_OBJECT_NAME
251    when it was run for the same decl.  */
252 #undef ASM_FINISH_DECLARE_OBJECT
253 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)	 \
254 do {									 \
255      const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0);		 \
256      HOST_WIDE_INT size;						 \
257      if (!flag_inhibit_size_directive && DECL_SIZE (DECL)		 \
258          && ! AT_END && TOP_LEVEL					 \
259 	 && DECL_INITIAL (DECL) == error_mark_node			 \
260 	 && !size_directive_output)					 \
261        {								 \
262 	 size_directive_output = 1;					 \
263 	 size = int_size_in_bytes (TREE_TYPE (DECL));			 \
264 	 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, name, size);			 \
265        }								 \
266    } while (0)
267 #endif
268 
269 
270 /* Those are `generic' ways to weaken/globalize a label. We shouldn't need
271    to override a processor specific definition. Hence, #ifndef ASM_*
272    In case overriding turns out to be needed, one can always #undef ASM_*
273    before including this file.  */
274 
275 /* Tell the assembler that a symbol is weak.  */
276 /* Note: netbsd arm32 assembler needs a .globl here. An override may
277    be needed when/if we go for arm32 support.  */
278 #ifndef ASM_WEAKEN_LABEL
279 #define ASM_WEAKEN_LABEL(FILE,NAME) \
280   do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \
281        fputc ('\n', FILE); } while (0)
282 #endif
283 
284 /* Storage layout.  */
285 
286 
287 #define HAVE_ENABLE_EXECUTE_STACK
288