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 #define TARGET_EXECUTABLE_SUFFIX ".exe"
30 #define TARGET_IS_PE_COFF 1
34 /* Masks for subtarget switches used by other files. */
35 #define MASK_NOP_FUN_DLLIMPORT 0x08000000 /* Ignore dllimport for functions */
37 /* Used in winnt.c. */
38 #define TARGET_NOP_FUN_DLLIMPORT (target_flags & MASK_NOP_FUN_DLLIMPORT)
40 #undef SUBTARGET_SWITCHES
41 #define SUBTARGET_SWITCHES \
42 { "cygwin", 0, N_("Use the Cygwin interface") }, \
43 { "no-cygwin", 0, N_("Use the Mingw32 interface") }, \
44 { "windows", 0, N_("Create GUI application") }, \
45 { "no-win32", 0, N_("Don't set Windows defines") }, \
46 { "win32", 0, N_("Set Windows defines") }, \
47 { "console", 0, N_("Create console application") },\
48 { "dll", 0, N_("Generate code for a DLL") }, \
49 { "nop-fun-dllimport", MASK_NOP_FUN_DLLIMPORT, \
50 N_("Ignore dllimport for functions") }, \
51 { "no-nop-fun-dllimport", -MASK_NOP_FUN_DLLIMPORT, "" }, \
52 { "threads", 0, N_("Use Mingw-specific thread support") },
54 #define MAYBE_UWIN_CPP_BUILTINS() /* Nothing. */
56 /* Support the __declspec keyword by turning them into attributes.
57 We currently only support: dllimport and dllexport.
58 Note that the current way we do this may result in a collision with
59 predefined attributes later on. This can be solved by using one attribute,
60 say __declspec__, and passing args to it. The problem with that approach
61 is that args are not accumulated: each new appearance would clobber any
64 #define TARGET_OS_CPP_BUILTINS() \
67 builtin_define ("_X86_=1"); \
68 builtin_assert ("system=winnt"); \
69 builtin_define ("__stdcall=__attribute__((__stdcall__))"); \
70 builtin_define ("__fastcall=__attribute__((__fastcall__))"); \
71 builtin_define ("__cdecl=__attribute__((__cdecl__))"); \
72 builtin_define ("__declspec(x)=__attribute__((x))"); \
75 builtin_define ("_stdcall=__attribute__((__stdcall__))"); \
76 builtin_define ("_fastcall=__attribute__((__fastcall__))"); \
77 builtin_define ("_cdecl=__attribute__((__cdecl__))"); \
79 MAYBE_UWIN_CPP_BUILTINS (); \
80 EXTRA_OS_CPP_BUILTINS (); \
84 /* Get tree.c to declare a target-specific specialization of
85 merge_decl_attributes. */
86 #define TARGET_DLLIMPORT_DECL_ATTRIBUTES
88 /* This macro defines names of additional specifications to put in the specs
89 that can be used in various specifications like CC1_SPEC. Its definition
90 is an initializer with a subgrouping for each command option.
92 Each subgrouping contains a string constant, that defines the
93 specification name, and a string constant that used by the GCC driver
96 Do not define this macro if it does not need to do anything. */
98 #undef SUBTARGET_EXTRA_SPECS
99 #define SUBTARGET_EXTRA_SPECS \
100 { "mingw_include_path", DEFAULT_TARGET_MACHINE }
103 #define MATH_LIBRARY ""
105 #define SIZE_TYPE "unsigned int"
106 #define PTRDIFF_TYPE "int"
107 #define WCHAR_TYPE_SIZE 16
108 #define WCHAR_TYPE "short unsigned int"
111 /* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop). */
112 #define HANDLE_PRAGMA_PACK_PUSH_POP 1
115 #define TREE union tree_node *
117 #undef EXTRA_SECTIONS
118 #define EXTRA_SECTIONS in_drectve
120 #undef EXTRA_SECTION_FUNCTIONS
121 #define EXTRA_SECTION_FUNCTIONS \
122 DRECTVE_SECTION_FUNCTION \
123 SWITCH_TO_SECTION_FUNCTION
125 #define DRECTVE_SECTION_FUNCTION \
127 drectve_section (void) \
129 if (in_section != in_drectve) \
131 fprintf (asm_out_file, "%s\n", "\t.section .drectve\n"); \
132 in_section = in_drectve; \
135 void drectve_section (void);
137 /* Older versions of gas don't handle 'r' as data.
138 Explicitly set data flag with 'd'. */
139 #define READONLY_DATA_SECTION_ASM_OP "\t.section .rdata,\"dr\""
141 /* Switch to SECTION (an `enum in_section').
143 ??? This facility should be provided by GCC proper.
144 The problem is that we want to temporarily switch sections in
145 ASM_DECLARE_OBJECT_NAME and then switch back to the original section
147 #define SWITCH_TO_SECTION_FUNCTION \
148 void switch_to_section (enum in_section, tree); \
150 switch_to_section (enum in_section section, tree decl) \
154 case in_text: text_section (); break; \
155 case in_data: data_section (); break; \
156 case in_readonly_data: readonly_data_section (); break; \
157 case in_named: named_section (decl, NULL, 0); break; \
158 case in_drectve: drectve_section (); break; \
159 default: abort (); break; \
163 /* Don't allow flag_pic to propagate since gas may produce invalid code
166 #undef SUBTARGET_OVERRIDE_OPTIONS
167 #define SUBTARGET_OVERRIDE_OPTIONS \
171 warning ("-f%s ignored for target (all code is position independent)",\
172 (flag_pic > 1) ? "PIC" : "pic"); \
177 /* Define this macro if references to a symbol must be treated
178 differently depending on something about the variable or
179 function named by the symbol (such as what section it is in).
181 On i386 running Windows NT, modify the assembler name with a suffix
182 consisting of an atsign (@) followed by string of digits that represents
183 the number of bytes of arguments passed to the function, if it has the
186 In addition, we must mark dll symbols specially. Definitions of
187 dllexport'd objects install some info in the .drectve section.
188 References to dllimport'd objects are fetched indirectly via
189 _imp__. If both are declared, dllexport overrides. This is also
190 needed to implement one-only vtables: they go into their own
191 section and we need to set DECL_SECTION_NAME so we do that here.
192 Note that we can be called twice on the same decl. */
194 #undef TARGET_ENCODE_SECTION_INFO
195 #define TARGET_ENCODE_SECTION_INFO i386_pe_encode_section_info
196 #undef TARGET_STRIP_NAME_ENCODING
197 #define TARGET_STRIP_NAME_ENCODING i386_pe_strip_name_encoding_full
199 /* Output a reference to a label. */
200 #undef ASM_OUTPUT_LABELREF
201 #define ASM_OUTPUT_LABELREF i386_pe_output_labelref
203 /* Output a common block. */
204 #undef ASM_OUTPUT_COMMON
205 #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED) \
207 if (i386_pe_dllexport_name_p (NAME)) \
208 i386_pe_record_exported_symbol (NAME, 1); \
209 if (! i386_pe_dllimport_name_p (NAME)) \
211 fprintf ((STREAM), "\t.comm\t"); \
212 assemble_name ((STREAM), (NAME)); \
213 fprintf ((STREAM), ", %d\t%s %d\n", \
214 (int)(ROUNDED), ASM_COMMENT_START, (int)(SIZE)); \
218 /* Output the label for an initialized variable. */
219 #undef ASM_DECLARE_OBJECT_NAME
220 #define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL) \
222 if (i386_pe_dllexport_name_p (NAME)) \
223 i386_pe_record_exported_symbol (NAME, 1); \
224 ASM_OUTPUT_LABEL ((STREAM), (NAME)); \
228 /* Emit code to check the stack when allocating more that 4000
231 #define CHECK_STACK_LIMIT 4000
233 /* By default, target has a 80387, uses IEEE compatible arithmetic,
234 returns float values in the 387 and needs stack probes.
235 We also align doubles to 64-bits for MSVC default compatibility. */
237 #undef TARGET_SUBTARGET_DEFAULT
238 #define TARGET_SUBTARGET_DEFAULT \
239 (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE \
242 /* This is how to output an assembler line
243 that says to advance the location counter
244 to a multiple of 2**LOG bytes. */
246 #undef ASM_OUTPUT_ALIGN
247 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
248 if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
250 /* Define this macro if in some cases global symbols from one translation
251 unit may not be bound to undefined symbols in another translation unit
252 without user intervention. For instance, under Microsoft Windows
253 symbols must be explicitly imported from shared libraries (DLLs). */
254 #define MULTIPLE_SYMBOL_SPACES
256 extern void i386_pe_unique_section (TREE, int);
257 #define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
259 #define SUPPORTS_ONE_ONLY 1
261 /* Switch into a generic section. */
262 #define TARGET_ASM_NAMED_SECTION i386_pe_asm_named_section
264 /* Select attributes for named sections. */
265 #define TARGET_SECTION_TYPE_FLAGS i386_pe_section_type_flags
267 /* Write the extra assembler code needed to declare a function
268 properly. If we are generating SDB debugging information, this
269 will happen automatically, so we only need to handle other cases. */
270 #undef ASM_DECLARE_FUNCTION_NAME
271 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
274 if (i386_pe_dllexport_name_p (NAME)) \
275 i386_pe_record_exported_symbol (NAME, 0); \
276 if (write_symbols != SDB_DEBUG) \
277 i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL)); \
278 ASM_OUTPUT_LABEL (FILE, NAME); \
282 /* Add an external function to the list of functions to be declared at
283 the end of the file. */
284 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
287 if (TREE_CODE (DECL) == FUNCTION_DECL) \
288 i386_pe_record_external_function (NAME); \
292 /* Declare the type properly for any external libcall. */
293 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
294 i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
296 /* This says out to put a global symbol in the BSS section. */
297 #undef ASM_OUTPUT_ALIGNED_BSS
298 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
299 asm_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
301 /* Output function declarations at the end of the file. */
302 #undef TARGET_ASM_FILE_END
303 #define TARGET_ASM_FILE_END i386_pe_file_end
305 #undef ASM_COMMENT_START
306 #define ASM_COMMENT_START " #"
308 /* DWARF2 Unwinding doesn't work with exception handling yet. To make
309 it work, we need to build a libgcc_s.dll, and dcrt0.o should be
310 changed to call __register_frame_info/__deregister_frame_info. */
311 #define DWARF2_UNWIND_INFO 0
313 /* Don't assume anything about the header files. */
314 #define NO_IMPLICIT_EXTERN_C
317 #define PROFILE_HOOK(LABEL) \
318 if (MAIN_NAME_P (DECL_NAME (current_function_decl))) \
320 emit_call_insn (gen_rtx (CALL, VOIDmode, \
321 gen_rtx_MEM (FUNCTION_MODE, \
322 gen_rtx_SYMBOL_REF (Pmode, "_monstartup")), \
326 /* Java Native Interface (JNI) methods on Win32 are invoked using the
327 stdcall calling convention. */
328 #undef MODIFY_JNI_METHOD_CALL
329 #define MODIFY_JNI_METHOD_CALL(MDECL) \
330 build_type_attribute_variant ((MDECL), \
331 build_tree_list (get_identifier ("stdcall"), \
334 /* External function declarations. */
336 extern void i386_pe_record_external_function (const char *);
337 extern void i386_pe_declare_function_type (FILE *, const char *, int);
338 extern void i386_pe_record_exported_symbol (const char *, int);
339 extern void i386_pe_file_end (void);
340 extern int i386_pe_dllexport_name_p (const char *);
341 extern int i386_pe_dllimport_name_p (const char *);
343 /* For Win32 ABI compatibility */
344 #undef DEFAULT_PCC_STRUCT_RETURN
345 #define DEFAULT_PCC_STRUCT_RETURN 0
347 /* MSVC returns aggregate types of up to 8 bytes via registers.
348 See i386.c:ix86_return_in_memory. */
349 #undef MS_AGGREGATE_RETURN
350 #define MS_AGGREGATE_RETURN 1
352 /* No data type wants to be aligned rounder than this. */
353 #undef BIGGEST_ALIGNMENT
354 #define BIGGEST_ALIGNMENT 128
356 /* Native complier aligns internal doubles in structures on dword boundaries. */
357 #undef BIGGEST_FIELD_ALIGNMENT
358 #define BIGGEST_FIELD_ALIGNMENT 64
360 /* A bit-field declared as `int' forces `int' alignment for the struct. */
361 #undef PCC_BITFIELD_TYPE_MATTERS
362 #define PCC_BITFIELD_TYPE_MATTERS 1
363 #define GROUP_BITFIELDS_BY_ALIGN TYPE_NATIVE(rec)
365 /* Enable alias attribute support. */
367 #define SET_ASM_OP "\t.set\t"
369 /* This implements the `alias' attribute, keeping any stdcall or
370 fastcall decoration. */
371 #undef ASM_OUTPUT_DEF_FROM_DECLS
372 #define ASM_OUTPUT_DEF_FROM_DECLS(STREAM, DECL, TARGET) \
376 rtx rtlname = XEXP (DECL_RTL (DECL), 0); \
377 if (GET_CODE (rtlname) == SYMBOL_REF) \
378 alias = XSTR (rtlname, 0); \
381 if (TREE_CODE (DECL) == FUNCTION_DECL) \
382 i386_pe_declare_function_type (STREAM, alias, \
383 TREE_PUBLIC (DECL)); \
384 ASM_OUTPUT_DEF (STREAM, alias, IDENTIFIER_POINTER (TARGET)); \