* config/i386/cygming.h [HAVE_GAS_PE_SECREL32_RELOC]
[gcc.git] / gcc / config / i386 / cygming.h
1 /* Operating system specific defines to be used when targeting GCC for
2 hosting on Windows32, using a Unix style C library and tools.
3 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
4 Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #define DBX_DEBUGGING_INFO 1
24 #define SDB_DEBUGGING_INFO 1
25 #undef PREFERRED_DEBUGGING_TYPE
26 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
27
28 #ifdef HAVE_GAS_PE_SECREL32_RELOC
29 #define DWARF2_DEBUGGING_INFO 1
30
31 #undef DBX_REGISTER_NUMBER
32 #define DBX_REGISTER_NUMBER(n) (write_symbols == DWARF2_DEBUG \
33 ? svr4_dbx_register_map[n] \
34 : dbx_register_map[n])
35
36 /* Use section relative relocations for debugging offsets. Unlike
37 other targets that fake this by putting the section VMA at 0, PE
38 won't allow it. */
39 #define ASM_OUTPUT_DWARF_OFFSET(FILE, SIZE, LABEL) \
40 do { \
41 if (SIZE != 4) \
42 abort (); \
43 \
44 fputs ("\t.secrel32\t", FILE); \
45 assemble_name (FILE, LABEL); \
46 } while (0)
47 #endif
48
49 #define TARGET_EXECUTABLE_SUFFIX ".exe"
50
51 #include <stdio.h>
52
53 /* Masks for subtarget switches used by other files. */
54 #define MASK_NOP_FUN_DLLIMPORT 0x08000000 /* Ignore dllimport for functions */
55
56 /* Used in winnt.c. */
57 #define TARGET_NOP_FUN_DLLIMPORT (target_flags & MASK_NOP_FUN_DLLIMPORT)
58
59 #undef SUBTARGET_SWITCHES
60 #define SUBTARGET_SWITCHES \
61 { "cygwin", 0, N_("Use the Cygwin interface") }, \
62 { "no-cygwin", 0, N_("Use the Mingw32 interface") }, \
63 { "windows", 0, N_("Create GUI application") }, \
64 { "no-win32", 0, N_("Don't set Windows defines") }, \
65 { "win32", 0, N_("Set Windows defines") }, \
66 { "console", 0, N_("Create console application") },\
67 { "dll", 0, N_("Generate code for a DLL") }, \
68 { "nop-fun-dllimport", MASK_NOP_FUN_DLLIMPORT, \
69 N_("Ignore dllimport for functions") }, \
70 { "no-nop-fun-dllimport", -MASK_NOP_FUN_DLLIMPORT, "" }, \
71 { "threads", 0, N_("Use Mingw-specific thread support") },
72
73 #define MAYBE_UWIN_CPP_BUILTINS() /* Nothing. */
74
75 /* Support the __declspec keyword by turning them into attributes.
76 We currently only support: dllimport and dllexport.
77 Note that the current way we do this may result in a collision with
78 predefined attributes later on. This can be solved by using one attribute,
79 say __declspec__, and passing args to it. The problem with that approach
80 is that args are not accumulated: each new appearance would clobber any
81 existing args. */
82
83 #define TARGET_OS_CPP_BUILTINS() \
84 do \
85 { \
86 builtin_define ("_X86_=1"); \
87 builtin_assert ("system=winnt"); \
88 builtin_define ("__stdcall=__attribute__((__stdcall__))"); \
89 builtin_define ("__fastcall=__attribute__((__fastcall__))"); \
90 builtin_define ("__cdecl=__attribute__((__cdecl__))"); \
91 builtin_define ("__declspec(x)=__attribute__((x))"); \
92 if (!flag_iso) \
93 { \
94 builtin_define ("_stdcall=__attribute__((__stdcall__))"); \
95 builtin_define ("_fastcall=__attribute__((__fastcall__))"); \
96 builtin_define ("_cdecl=__attribute__((__cdecl__))"); \
97 } \
98 MAYBE_UWIN_CPP_BUILTINS (); \
99 EXTRA_OS_CPP_BUILTINS (); \
100 } \
101 while (0)
102
103 /* Get tree.c to declare a target-specific specialization of
104 merge_decl_attributes. */
105 #define TARGET_DLLIMPORT_DECL_ATTRIBUTES
106
107 /* This macro defines names of additional specifications to put in the specs
108 that can be used in various specifications like CC1_SPEC. Its definition
109 is an initializer with a subgrouping for each command option.
110
111 Each subgrouping contains a string constant, that defines the
112 specification name, and a string constant that used by the GCC driver
113 program.
114
115 Do not define this macro if it does not need to do anything. */
116
117 #undef SUBTARGET_EXTRA_SPECS
118 #define SUBTARGET_EXTRA_SPECS \
119 { "mingw_include_path", DEFAULT_TARGET_MACHINE }
120
121 #undef MATH_LIBRARY
122 #define MATH_LIBRARY ""
123
124 #define SIZE_TYPE "unsigned int"
125 #define PTRDIFF_TYPE "int"
126 #define WCHAR_TYPE_SIZE 16
127 #define WCHAR_TYPE "short unsigned int"
128
129 \f
130 /* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop). */
131 #define HANDLE_PRAGMA_PACK_PUSH_POP 1
132
133 union tree_node;
134 #define TREE union tree_node *
135 \f
136 #undef EXTRA_SECTIONS
137 #define EXTRA_SECTIONS in_drectve
138
139 #undef EXTRA_SECTION_FUNCTIONS
140 #define EXTRA_SECTION_FUNCTIONS \
141 DRECTVE_SECTION_FUNCTION \
142 SWITCH_TO_SECTION_FUNCTION
143
144 #define DRECTVE_SECTION_FUNCTION \
145 void \
146 drectve_section (void) \
147 { \
148 if (in_section != in_drectve) \
149 { \
150 fprintf (asm_out_file, "%s\n", "\t.section .drectve\n"); \
151 in_section = in_drectve; \
152 } \
153 }
154 void drectve_section (void);
155
156 /* Older versions of gas don't handle 'r' as data.
157 Explicitly set data flag with 'd'. */
158 #define READONLY_DATA_SECTION_ASM_OP "\t.section .rdata,\"dr\""
159
160 /* Switch to SECTION (an `enum in_section').
161
162 ??? This facility should be provided by GCC proper.
163 The problem is that we want to temporarily switch sections in
164 ASM_DECLARE_OBJECT_NAME and then switch back to the original section
165 afterwards. */
166 #define SWITCH_TO_SECTION_FUNCTION \
167 void switch_to_section (enum in_section, tree); \
168 void \
169 switch_to_section (enum in_section section, tree decl) \
170 { \
171 switch (section) \
172 { \
173 case in_text: text_section (); break; \
174 case in_data: data_section (); break; \
175 case in_readonly_data: readonly_data_section (); break; \
176 case in_named: named_section (decl, NULL, 0); break; \
177 case in_drectve: drectve_section (); break; \
178 default: abort (); break; \
179 } \
180 }
181
182 /* Don't allow flag_pic to propagate since gas may produce invalid code
183 otherwise. */
184
185 #undef SUBTARGET_OVERRIDE_OPTIONS
186 #define SUBTARGET_OVERRIDE_OPTIONS \
187 do { \
188 if (flag_pic) \
189 { \
190 warning ("-f%s ignored for target (all code is position independent)",\
191 (flag_pic > 1) ? "PIC" : "pic"); \
192 flag_pic = 0; \
193 } \
194 } while (0) \
195
196 /* Define this macro if references to a symbol must be treated
197 differently depending on something about the variable or
198 function named by the symbol (such as what section it is in).
199
200 On i386 running Windows NT, modify the assembler name with a suffix
201 consisting of an atsign (@) followed by string of digits that represents
202 the number of bytes of arguments passed to the function, if it has the
203 attribute STDCALL.
204
205 In addition, we must mark dll symbols specially. Definitions of
206 dllexport'd objects install some info in the .drectve section.
207 References to dllimport'd objects are fetched indirectly via
208 _imp__. If both are declared, dllexport overrides. This is also
209 needed to implement one-only vtables: they go into their own
210 section and we need to set DECL_SECTION_NAME so we do that here.
211 Note that we can be called twice on the same decl. */
212
213 #undef TARGET_ENCODE_SECTION_INFO
214 #define TARGET_ENCODE_SECTION_INFO i386_pe_encode_section_info
215 #undef TARGET_STRIP_NAME_ENCODING
216 #define TARGET_STRIP_NAME_ENCODING i386_pe_strip_name_encoding_full
217 \f
218 /* Output a reference to a label. */
219 #undef ASM_OUTPUT_LABELREF
220 #define ASM_OUTPUT_LABELREF i386_pe_output_labelref
221
222 /* Output a common block. */
223 #undef ASM_OUTPUT_COMMON
224 #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED) \
225 do { \
226 if (i386_pe_dllexport_name_p (NAME)) \
227 i386_pe_record_exported_symbol (NAME, 1); \
228 if (! i386_pe_dllimport_name_p (NAME)) \
229 { \
230 fprintf ((STREAM), "\t.comm\t"); \
231 assemble_name ((STREAM), (NAME)); \
232 fprintf ((STREAM), ", %d\t%s %d\n", \
233 (int)(ROUNDED), ASM_COMMENT_START, (int)(SIZE)); \
234 } \
235 } while (0)
236
237 /* Output the label for an initialized variable. */
238 #undef ASM_DECLARE_OBJECT_NAME
239 #define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL) \
240 do { \
241 if (i386_pe_dllexport_name_p (NAME)) \
242 i386_pe_record_exported_symbol (NAME, 1); \
243 ASM_OUTPUT_LABEL ((STREAM), (NAME)); \
244 } while (0)
245
246 \f
247 /* Emit code to check the stack when allocating more that 4000
248 bytes in one go. */
249
250 #define CHECK_STACK_LIMIT 4000
251
252 /* By default, target has a 80387, uses IEEE compatible arithmetic,
253 returns float values in the 387 and needs stack probes.
254 We also align doubles to 64-bits for MSVC default compatibility. */
255
256 #undef TARGET_SUBTARGET_DEFAULT
257 #define TARGET_SUBTARGET_DEFAULT \
258 (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE \
259 | MASK_ALIGN_DOUBLE)
260
261 /* This is how to output an assembler line
262 that says to advance the location counter
263 to a multiple of 2**LOG bytes. */
264
265 #undef ASM_OUTPUT_ALIGN
266 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
267 if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
268
269 /* Define this macro if in some cases global symbols from one translation
270 unit may not be bound to undefined symbols in another translation unit
271 without user intervention. For instance, under Microsoft Windows
272 symbols must be explicitly imported from shared libraries (DLLs). */
273 #define MULTIPLE_SYMBOL_SPACES
274
275 extern void i386_pe_unique_section (TREE, int);
276 #define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
277
278 #define SUPPORTS_ONE_ONLY 1
279
280 /* Switch into a generic section. */
281 #define TARGET_ASM_NAMED_SECTION i386_pe_asm_named_section
282
283 /* Select attributes for named sections. */
284 #define TARGET_SECTION_TYPE_FLAGS i386_pe_section_type_flags
285
286 /* Write the extra assembler code needed to declare a function
287 properly. If we are generating SDB debugging information, this
288 will happen automatically, so we only need to handle other cases. */
289 #undef ASM_DECLARE_FUNCTION_NAME
290 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
291 do \
292 { \
293 if (i386_pe_dllexport_name_p (NAME)) \
294 i386_pe_record_exported_symbol (NAME, 0); \
295 if (write_symbols != SDB_DEBUG) \
296 i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL)); \
297 ASM_OUTPUT_LABEL (FILE, NAME); \
298 } \
299 while (0)
300
301 /* Add an external function to the list of functions to be declared at
302 the end of the file. */
303 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
304 do \
305 { \
306 if (TREE_CODE (DECL) == FUNCTION_DECL) \
307 i386_pe_record_external_function (NAME); \
308 } \
309 while (0)
310
311 /* Declare the type properly for any external libcall. */
312 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
313 i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
314
315 /* This says out to put a global symbol in the BSS section. */
316 #undef ASM_OUTPUT_ALIGNED_BSS
317 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
318 asm_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
319
320 /* Output function declarations at the end of the file. */
321 #undef TARGET_ASM_FILE_END
322 #define TARGET_ASM_FILE_END i386_pe_file_end
323
324 #undef ASM_COMMENT_START
325 #define ASM_COMMENT_START " #"
326
327 /* DWARF2 Unwinding doesn't work with exception handling yet. To make
328 it work, we need to build a libgcc_s.dll, and dcrt0.o should be
329 changed to call __register_frame_info/__deregister_frame_info. */
330 #define DWARF2_UNWIND_INFO 0
331
332 /* Don't assume anything about the header files. */
333 #define NO_IMPLICIT_EXTERN_C
334
335 #undef PROFILE_HOOK
336 #define PROFILE_HOOK(LABEL) \
337 if (MAIN_NAME_P (DECL_NAME (current_function_decl))) \
338 { \
339 emit_call_insn (gen_rtx_CALL (VOIDmode, \
340 gen_rtx_MEM (FUNCTION_MODE, \
341 gen_rtx_SYMBOL_REF (Pmode, "_monstartup")), \
342 const0_rtx)); \
343 }
344
345 /* Java Native Interface (JNI) methods on Win32 are invoked using the
346 stdcall calling convention. */
347 #undef MODIFY_JNI_METHOD_CALL
348 #define MODIFY_JNI_METHOD_CALL(MDECL) \
349 build_type_attribute_variant ((MDECL), \
350 build_tree_list (get_identifier ("stdcall"), \
351 NULL))
352
353 /* External function declarations. */
354
355 extern void i386_pe_record_external_function (const char *);
356 extern void i386_pe_declare_function_type (FILE *, const char *, int);
357 extern void i386_pe_record_exported_symbol (const char *, int);
358 extern void i386_pe_file_end (void);
359 extern int i386_pe_dllexport_name_p (const char *);
360 extern int i386_pe_dllimport_name_p (const char *);
361
362 /* For Win32 ABI compatibility */
363 #undef DEFAULT_PCC_STRUCT_RETURN
364 #define DEFAULT_PCC_STRUCT_RETURN 0
365
366 /* MSVC returns aggregate types of up to 8 bytes via registers.
367 See i386.c:ix86_return_in_memory. */
368 #undef MS_AGGREGATE_RETURN
369 #define MS_AGGREGATE_RETURN 1
370
371 /* No data type wants to be aligned rounder than this. */
372 #undef BIGGEST_ALIGNMENT
373 #define BIGGEST_ALIGNMENT 128
374
375 /* Native complier aligns internal doubles in structures on dword boundaries. */
376 #undef BIGGEST_FIELD_ALIGNMENT
377 #define BIGGEST_FIELD_ALIGNMENT 64
378
379 /* A bit-field declared as `int' forces `int' alignment for the struct. */
380 #undef PCC_BITFIELD_TYPE_MATTERS
381 #define PCC_BITFIELD_TYPE_MATTERS 1
382 #define GROUP_BITFIELDS_BY_ALIGN TYPE_NATIVE(rec)
383
384 /* Enable alias attribute support. */
385 #ifndef SET_ASM_OP
386 #define SET_ASM_OP "\t.set\t"
387 #endif
388 /* This implements the `alias' attribute, keeping any stdcall or
389 fastcall decoration. */
390 #undef ASM_OUTPUT_DEF_FROM_DECLS
391 #define ASM_OUTPUT_DEF_FROM_DECLS(STREAM, DECL, TARGET) \
392 do \
393 { \
394 const char *alias; \
395 rtx rtlname = XEXP (DECL_RTL (DECL), 0); \
396 if (GET_CODE (rtlname) == SYMBOL_REF) \
397 alias = XSTR (rtlname, 0); \
398 else \
399 abort (); \
400 if (TREE_CODE (DECL) == FUNCTION_DECL) \
401 i386_pe_declare_function_type (STREAM, alias, \
402 TREE_PUBLIC (DECL)); \
403 ASM_OUTPUT_DEF (STREAM, alias, IDENTIFIER_POINTER (TARGET)); \
404 } while (0)
405
406 /* Decide whether it is safe to use a local alias for a virtual function
407 when constructing thunks. */
408 #undef TARGET_USE_LOCAL_THUNK_ALIAS_P
409 #define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) (!DECL_ONE_ONLY (DECL))
410
411 #undef TREE
412
413 #ifndef BUFSIZ
414 # undef FILE
415 #endif