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.
6 This file is part of GCC.
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)
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.
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. */
23 #define DBX_DEBUGGING_INFO 1
24 #define SDB_DEBUGGING_INFO 1
25 #undef PREFERRED_DEBUGGING_TYPE
26 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
28 #ifdef HAVE_GAS_PE_SECREL32_RELOC
29 #define DWARF2_DEBUGGING_INFO 1
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])
36 /* Use section relative relocations for debugging offsets. Unlike
37 other targets that fake this by putting the section VMA at 0, PE
39 #define ASM_OUTPUT_DWARF_OFFSET(FILE, SIZE, LABEL) \
44 fputs ("\t.secrel32\t", FILE); \
45 assemble_name (FILE, LABEL); \
49 #define TARGET_EXECUTABLE_SUFFIX ".exe"
53 /* Masks for subtarget switches used by other files. */
54 #define MASK_NOP_FUN_DLLIMPORT 0x08000000 /* Ignore dllimport for functions */
56 /* Used in winnt.c. */
57 #define TARGET_NOP_FUN_DLLIMPORT (target_flags & MASK_NOP_FUN_DLLIMPORT)
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") },
73 #define MAYBE_UWIN_CPP_BUILTINS() /* Nothing. */
75 #define TARGET_OS_CPP_BUILTINS() \
78 builtin_define ("_X86_=1"); \
79 builtin_assert ("system=winnt"); \
80 builtin_define ("__stdcall=__attribute__((__stdcall__))"); \
81 builtin_define ("__fastcall=__attribute__((__fastcall__))"); \
82 builtin_define ("__cdecl=__attribute__((__cdecl__))"); \
85 builtin_define ("_stdcall=__attribute__((__stdcall__))"); \
86 builtin_define ("_fastcall=__attribute__((__fastcall__))"); \
87 builtin_define ("_cdecl=__attribute__((__cdecl__))"); \
89 /* Even though linkonce works with static libs, this is needed \
90 to compare typeinfo symbols across dll boundaries. */ \
91 builtin_define ("__GXX_MERGED_TYPEINFO_NAMES=0"); \
92 MAYBE_UWIN_CPP_BUILTINS (); \
93 EXTRA_OS_CPP_BUILTINS (); \
97 /* Get tree.c to declare a target-specific specialization of
98 merge_decl_attributes. */
99 #define TARGET_DLLIMPORT_DECL_ATTRIBUTES 1
101 /* This macro defines names of additional specifications to put in the specs
102 that can be used in various specifications like CC1_SPEC. Its definition
103 is an initializer with a subgrouping for each command option.
105 Each subgrouping contains a string constant, that defines the
106 specification name, and a string constant that used by the GCC driver
109 Do not define this macro if it does not need to do anything. */
111 #undef SUBTARGET_EXTRA_SPECS
112 #define SUBTARGET_EXTRA_SPECS \
113 { "mingw_include_path", DEFAULT_TARGET_MACHINE }
116 #define MATH_LIBRARY ""
118 #define SIZE_TYPE "unsigned int"
119 #define PTRDIFF_TYPE "int"
120 #define WCHAR_TYPE_SIZE 16
121 #define WCHAR_TYPE "short unsigned int"
124 /* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop). */
125 #define HANDLE_PRAGMA_PACK_PUSH_POP 1
128 #define TREE union tree_node *
130 #undef EXTRA_SECTIONS
131 #define EXTRA_SECTIONS in_drectve
133 #undef EXTRA_SECTION_FUNCTIONS
134 #define EXTRA_SECTION_FUNCTIONS \
135 DRECTVE_SECTION_FUNCTION \
136 SWITCH_TO_SECTION_FUNCTION
138 #define DRECTVE_SECTION_FUNCTION \
140 drectve_section (void) \
142 if (in_section != in_drectve) \
144 fprintf (asm_out_file, "%s\n", "\t.section .drectve\n"); \
145 in_section = in_drectve; \
148 void drectve_section (void);
150 /* Older versions of gas don't handle 'r' as data.
151 Explicitly set data flag with 'd'. */
152 #define READONLY_DATA_SECTION_ASM_OP "\t.section .rdata,\"dr\""
154 /* Switch to SECTION (an `enum in_section').
156 ??? This facility should be provided by GCC proper.
157 The problem is that we want to temporarily switch sections in
158 ASM_DECLARE_OBJECT_NAME and then switch back to the original section
160 #define SWITCH_TO_SECTION_FUNCTION \
161 void switch_to_section (enum in_section, tree); \
163 switch_to_section (enum in_section section, tree decl) \
167 case in_text: text_section (); break; \
168 case in_unlikely_executed_text: unlikely_text_section (); break; \
169 case in_data: data_section (); break; \
170 case in_readonly_data: readonly_data_section (); break; \
171 case in_named: named_section (decl, NULL, 0); break; \
172 case in_drectve: drectve_section (); break; \
173 default: abort (); break; \
177 /* Don't allow flag_pic to propagate since gas may produce invalid code
180 #undef SUBTARGET_OVERRIDE_OPTIONS
181 #define SUBTARGET_OVERRIDE_OPTIONS \
185 warning ("-f%s ignored for target (all code is position independent)",\
186 (flag_pic > 1) ? "PIC" : "pic"); \
191 /* Define this macro if references to a symbol must be treated
192 differently depending on something about the variable or
193 function named by the symbol (such as what section it is in).
195 On i386 running Windows NT, modify the assembler name with a suffix
196 consisting of an atsign (@) followed by string of digits that represents
197 the number of bytes of arguments passed to the function, if it has the
200 In addition, we must mark dll symbols specially. Definitions of
201 dllexport'd objects install some info in the .drectve section.
202 References to dllimport'd objects are fetched indirectly via
203 _imp__. If both are declared, dllexport overrides. This is also
204 needed to implement one-only vtables: they go into their own
205 section and we need to set DECL_SECTION_NAME so we do that here.
206 Note that we can be called twice on the same decl. */
208 #undef TARGET_ENCODE_SECTION_INFO
209 #define TARGET_ENCODE_SECTION_INFO i386_pe_encode_section_info
210 #undef TARGET_STRIP_NAME_ENCODING
211 #define TARGET_STRIP_NAME_ENCODING i386_pe_strip_name_encoding_full
213 /* Output a reference to a label. */
214 #undef ASM_OUTPUT_LABELREF
215 #define ASM_OUTPUT_LABELREF i386_pe_output_labelref
217 /* Output a common block. */
218 #undef ASM_OUTPUT_COMMON
219 #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED) \
221 if (i386_pe_dllexport_name_p (NAME)) \
222 i386_pe_record_exported_symbol (NAME, 1); \
223 if (! i386_pe_dllimport_name_p (NAME)) \
225 fprintf ((STREAM), "\t.comm\t"); \
226 assemble_name ((STREAM), (NAME)); \
227 fprintf ((STREAM), ", %d\t%s %d\n", \
228 (int)(ROUNDED), ASM_COMMENT_START, (int)(SIZE)); \
232 /* Output the label for an initialized variable. */
233 #undef ASM_DECLARE_OBJECT_NAME
234 #define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL) \
236 if (i386_pe_dllexport_name_p (NAME)) \
237 i386_pe_record_exported_symbol (NAME, 1); \
238 ASM_OUTPUT_LABEL ((STREAM), (NAME)); \
242 /* Emit code to check the stack when allocating more that 4000
245 #define CHECK_STACK_LIMIT 4000
247 /* By default, target has a 80387, uses IEEE compatible arithmetic,
248 returns float values in the 387 and needs stack probes.
249 We also align doubles to 64-bits for MSVC default compatibility. */
251 #undef TARGET_SUBTARGET_DEFAULT
252 #define TARGET_SUBTARGET_DEFAULT \
253 (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE \
256 /* This is how to output an assembler line
257 that says to advance the location counter
258 to a multiple of 2**LOG bytes. */
260 #undef ASM_OUTPUT_ALIGN
261 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
262 if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
264 /* Windows uses explicit import from shared libraries. */
265 #define MULTIPLE_SYMBOL_SPACES 1
267 extern void i386_pe_unique_section (TREE, int);
268 #define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
269 #define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
271 #define SUPPORTS_ONE_ONLY 1
273 /* Switch into a generic section. */
274 #define TARGET_ASM_NAMED_SECTION i386_pe_asm_named_section
276 /* Select attributes for named sections. */
277 #define TARGET_SECTION_TYPE_FLAGS i386_pe_section_type_flags
279 /* Write the extra assembler code needed to declare a function
280 properly. If we are generating SDB debugging information, this
281 will happen automatically, so we only need to handle other cases. */
282 #undef ASM_DECLARE_FUNCTION_NAME
283 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
286 if (i386_pe_dllexport_name_p (NAME)) \
287 i386_pe_record_exported_symbol (NAME, 0); \
288 if (write_symbols != SDB_DEBUG) \
289 i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL)); \
290 ASM_OUTPUT_LABEL (FILE, NAME); \
294 /* Add an external function to the list of functions to be declared at
295 the end of the file. */
296 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
299 if (TREE_CODE (DECL) == FUNCTION_DECL) \
300 i386_pe_record_external_function (NAME); \
304 /* Declare the type properly for any external libcall. */
305 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
306 i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
308 /* This says out to put a global symbol in the BSS section. */
309 #undef ASM_OUTPUT_ALIGNED_BSS
310 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
311 asm_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
313 /* Output function declarations at the end of the file. */
314 #undef TARGET_ASM_FILE_END
315 #define TARGET_ASM_FILE_END i386_pe_file_end
317 #undef ASM_COMMENT_START
318 #define ASM_COMMENT_START " #"
320 /* DWARF2 Unwinding doesn't work with exception handling yet. To make
321 it work, we need to build a libgcc_s.dll, and dcrt0.o should be
322 changed to call __register_frame_info/__deregister_frame_info. */
323 #define DWARF2_UNWIND_INFO 0
325 /* Don't assume anything about the header files. */
326 #define NO_IMPLICIT_EXTERN_C
329 #define PROFILE_HOOK(LABEL) \
330 if (MAIN_NAME_P (DECL_NAME (current_function_decl))) \
332 emit_call_insn (gen_rtx_CALL (VOIDmode, \
333 gen_rtx_MEM (FUNCTION_MODE, \
334 gen_rtx_SYMBOL_REF (Pmode, "_monstartup")), \
338 /* Java Native Interface (JNI) methods on Win32 are invoked using the
339 stdcall calling convention. */
340 #undef MODIFY_JNI_METHOD_CALL
341 #define MODIFY_JNI_METHOD_CALL(MDECL) \
342 build_type_attribute_variant ((MDECL), \
343 build_tree_list (get_identifier ("stdcall"), \
346 /* External function declarations. */
348 extern void i386_pe_record_external_function (const char *);
349 extern void i386_pe_declare_function_type (FILE *, const char *, int);
350 extern void i386_pe_record_exported_symbol (const char *, int);
351 extern void i386_pe_file_end (void);
352 extern int i386_pe_dllexport_name_p (const char *);
353 extern int i386_pe_dllimport_name_p (const char *);
355 /* For Win32 ABI compatibility */
356 #undef DEFAULT_PCC_STRUCT_RETURN
357 #define DEFAULT_PCC_STRUCT_RETURN 0
359 /* MSVC returns aggregate types of up to 8 bytes via registers.
360 See i386.c:ix86_return_in_memory. */
361 #undef MS_AGGREGATE_RETURN
362 #define MS_AGGREGATE_RETURN 1
364 /* No data type wants to be aligned rounder than this. */
365 #undef BIGGEST_ALIGNMENT
366 #define BIGGEST_ALIGNMENT 128
368 /* Native complier aligns internal doubles in structures on dword boundaries. */
369 #undef BIGGEST_FIELD_ALIGNMENT
370 #define BIGGEST_FIELD_ALIGNMENT 64
372 /* A bit-field declared as `int' forces `int' alignment for the struct. */
373 #undef PCC_BITFIELD_TYPE_MATTERS
374 #define PCC_BITFIELD_TYPE_MATTERS 1
375 #define GROUP_BITFIELDS_BY_ALIGN TYPE_NATIVE(rec)
377 /* Enable alias attribute support. */
379 #define SET_ASM_OP "\t.set\t"
381 /* This implements the `alias' attribute, keeping any stdcall or
382 fastcall decoration. */
383 #undef ASM_OUTPUT_DEF_FROM_DECLS
384 #define ASM_OUTPUT_DEF_FROM_DECLS(STREAM, DECL, TARGET) \
388 rtx rtlname = XEXP (DECL_RTL (DECL), 0); \
389 if (GET_CODE (rtlname) == SYMBOL_REF) \
390 alias = XSTR (rtlname, 0); \
393 if (TREE_CODE (DECL) == FUNCTION_DECL) \
394 i386_pe_declare_function_type (STREAM, alias, \
395 TREE_PUBLIC (DECL)); \
396 ASM_OUTPUT_DEF (STREAM, alias, IDENTIFIER_POINTER (TARGET)); \
399 /* Decide whether it is safe to use a local alias for a virtual function
400 when constructing thunks. */
401 #undef TARGET_USE_LOCAL_THUNK_ALIAS_P
402 #define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) (!DECL_ONE_ONLY (DECL))