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"
32 /* Masks for subtarget switches used by other files. */
33 #define MASK_NOP_FUN_DLLIMPORT 0x08000000 /* Ignore dllimport for functions */
35 /* Used in winnt.c. */
36 #define TARGET_NOP_FUN_DLLIMPORT (target_flags & MASK_NOP_FUN_DLLIMPORT)
38 #undef SUBTARGET_SWITCHES
39 #define SUBTARGET_SWITCHES \
40 { "cygwin", 0, N_("Use the Cygwin interface") }, \
41 { "no-cygwin", 0, N_("Use the Mingw32 interface") }, \
42 { "windows", 0, N_("Create GUI application") }, \
43 { "no-win32", 0, N_("Don't set Windows defines") }, \
44 { "win32", 0, N_("Set Windows defines") }, \
45 { "console", 0, N_("Create console application") },\
46 { "dll", 0, N_("Generate code for a DLL") }, \
47 { "nop-fun-dllimport", MASK_NOP_FUN_DLLIMPORT, \
48 N_("Ignore dllimport for functions") }, \
49 { "no-nop-fun-dllimport", -MASK_NOP_FUN_DLLIMPORT, "" }, \
50 { "threads", 0, N_("Use Mingw-specific thread support") },
52 #define MAYBE_UWIN_CPP_BUILTINS() /* Nothing. */
54 /* Support the __declspec keyword by turning them into attributes.
55 We currently only support: dllimport and dllexport.
56 Note that the current way we do this may result in a collision with
57 predefined attributes later on. This can be solved by using one attribute,
58 say __declspec__, and passing args to it. The problem with that approach
59 is that args are not accumulated: each new appearance would clobber any
62 #define TARGET_OS_CPP_BUILTINS() \
65 builtin_define ("_X86_=1"); \
66 builtin_assert ("system=winnt"); \
67 builtin_define ("__stdcall=__attribute__((__stdcall__))"); \
68 builtin_define ("__fastcall=__attribute__((__fastcall__))"); \
69 builtin_define ("__cdecl=__attribute__((__cdecl__))"); \
70 builtin_define ("__declspec(x)=__attribute__((x))"); \
73 builtin_define ("_stdcall=__attribute__((__stdcall__))"); \
74 builtin_define ("_fastcall=__attribute__((__fastcall__))"); \
75 builtin_define ("_cdecl=__attribute__((__cdecl__))"); \
77 MAYBE_UWIN_CPP_BUILTINS (); \
78 EXTRA_OS_CPP_BUILTINS (); \
82 /* Get tree.c to declare a target-specific specialization of
83 merge_decl_attributes. */
84 #define TARGET_DLLIMPORT_DECL_ATTRIBUTES
86 /* This macro defines names of additional specifications to put in the specs
87 that can be used in various specifications like CC1_SPEC. Its definition
88 is an initializer with a subgrouping for each command option.
90 Each subgrouping contains a string constant, that defines the
91 specification name, and a string constant that used by the GCC driver
94 Do not define this macro if it does not need to do anything. */
96 #undef SUBTARGET_EXTRA_SPECS
97 #define SUBTARGET_EXTRA_SPECS \
98 { "mingw_include_path", DEFAULT_TARGET_MACHINE }
101 #define MATH_LIBRARY ""
103 #define SIZE_TYPE "unsigned int"
104 #define PTRDIFF_TYPE "int"
105 #define WCHAR_TYPE_SIZE 16
106 #define WCHAR_TYPE "short unsigned int"
109 /* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop). */
110 #define HANDLE_PRAGMA_PACK_PUSH_POP 1
113 #define TREE union tree_node *
115 #undef EXTRA_SECTIONS
116 #define EXTRA_SECTIONS in_drectve
118 #undef EXTRA_SECTION_FUNCTIONS
119 #define EXTRA_SECTION_FUNCTIONS \
120 DRECTVE_SECTION_FUNCTION \
121 SWITCH_TO_SECTION_FUNCTION
123 #define DRECTVE_SECTION_FUNCTION \
125 drectve_section (void) \
127 if (in_section != in_drectve) \
129 fprintf (asm_out_file, "%s\n", "\t.section .drectve\n"); \
130 in_section = in_drectve; \
133 void drectve_section (void);
135 /* Older versions of gas don't handle 'r' as data.
136 Explicitly set data flag with 'd'. */
137 #define READONLY_DATA_SECTION_ASM_OP "\t.section .rdata,\"dr\""
139 /* Switch to SECTION (an `enum in_section').
141 ??? This facility should be provided by GCC proper.
142 The problem is that we want to temporarily switch sections in
143 ASM_DECLARE_OBJECT_NAME and then switch back to the original section
145 #define SWITCH_TO_SECTION_FUNCTION \
146 void switch_to_section (enum in_section, tree); \
148 switch_to_section (enum in_section section, tree decl) \
152 case in_text: text_section (); break; \
153 case in_data: data_section (); break; \
154 case in_readonly_data: readonly_data_section (); break; \
155 case in_named: named_section (decl, NULL, 0); break; \
156 case in_drectve: drectve_section (); break; \
157 default: abort (); break; \
161 /* Don't allow flag_pic to propagate since gas may produce invalid code
164 #undef SUBTARGET_OVERRIDE_OPTIONS
165 #define SUBTARGET_OVERRIDE_OPTIONS \
169 warning ("-f%s ignored for target (all code is position independent)",\
170 (flag_pic > 1) ? "PIC" : "pic"); \
175 /* Define this macro if references to a symbol must be treated
176 differently depending on something about the variable or
177 function named by the symbol (such as what section it is in).
179 On i386 running Windows NT, modify the assembler name with a suffix
180 consisting of an atsign (@) followed by string of digits that represents
181 the number of bytes of arguments passed to the function, if it has the
184 In addition, we must mark dll symbols specially. Definitions of
185 dllexport'd objects install some info in the .drectve section.
186 References to dllimport'd objects are fetched indirectly via
187 _imp__. If both are declared, dllexport overrides. This is also
188 needed to implement one-only vtables: they go into their own
189 section and we need to set DECL_SECTION_NAME so we do that here.
190 Note that we can be called twice on the same decl. */
192 #undef TARGET_ENCODE_SECTION_INFO
193 #define TARGET_ENCODE_SECTION_INFO i386_pe_encode_section_info
194 #undef TARGET_STRIP_NAME_ENCODING
195 #define TARGET_STRIP_NAME_ENCODING i386_pe_strip_name_encoding_full
197 /* Output a reference to a label. */
198 #undef ASM_OUTPUT_LABELREF
199 #define ASM_OUTPUT_LABELREF i386_pe_output_labelref
201 /* Output a common block. */
202 #undef ASM_OUTPUT_COMMON
203 #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED) \
205 if (i386_pe_dllexport_name_p (NAME)) \
206 i386_pe_record_exported_symbol (NAME, 1); \
207 if (! i386_pe_dllimport_name_p (NAME)) \
209 fprintf ((STREAM), "\t.comm\t"); \
210 assemble_name ((STREAM), (NAME)); \
211 fprintf ((STREAM), ", %d\t%s %d\n", \
212 (int)(ROUNDED), ASM_COMMENT_START, (int)(SIZE)); \
216 /* Output the label for an initialized variable. */
217 #undef ASM_DECLARE_OBJECT_NAME
218 #define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL) \
220 if (i386_pe_dllexport_name_p (NAME)) \
221 i386_pe_record_exported_symbol (NAME, 1); \
222 ASM_OUTPUT_LABEL ((STREAM), (NAME)); \
226 /* Emit code to check the stack when allocating more that 4000
229 #define CHECK_STACK_LIMIT 4000
231 /* By default, target has a 80387, uses IEEE compatible arithmetic,
232 returns float values in the 387 and needs stack probes.
233 We also align doubles to 64-bits for MSVC default compatibility. */
235 #undef TARGET_SUBTARGET_DEFAULT
236 #define TARGET_SUBTARGET_DEFAULT \
237 (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE \
240 /* This is how to output an assembler line
241 that says to advance the location counter
242 to a multiple of 2**LOG bytes. */
244 #undef ASM_OUTPUT_ALIGN
245 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
246 if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
248 /* Define this macro if in some cases global symbols from one translation
249 unit may not be bound to undefined symbols in another translation unit
250 without user intervention. For instance, under Microsoft Windows
251 symbols must be explicitly imported from shared libraries (DLLs). */
252 #define MULTIPLE_SYMBOL_SPACES
254 extern void i386_pe_unique_section (TREE
, int);
255 #define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
257 #define SUPPORTS_ONE_ONLY 1
259 /* Switch into a generic section. */
260 #define TARGET_ASM_NAMED_SECTION i386_pe_asm_named_section
262 /* Select attributes for named sections. */
263 #define TARGET_SECTION_TYPE_FLAGS i386_pe_section_type_flags
265 /* Write the extra assembler code needed to declare a function
266 properly. If we are generating SDB debugging information, this
267 will happen automatically, so we only need to handle other cases. */
268 #undef ASM_DECLARE_FUNCTION_NAME
269 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
272 if (i386_pe_dllexport_name_p (NAME)) \
273 i386_pe_record_exported_symbol (NAME, 0); \
274 if (write_symbols != SDB_DEBUG) \
275 i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL)); \
276 ASM_OUTPUT_LABEL (FILE, NAME); \
280 /* Add an external function to the list of functions to be declared at
281 the end of the file. */
282 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
285 if (TREE_CODE (DECL) == FUNCTION_DECL) \
286 i386_pe_record_external_function (NAME); \
290 /* Declare the type properly for any external libcall. */
291 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
292 i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
294 /* This says out to put a global symbol in the BSS section. */
295 #undef ASM_OUTPUT_ALIGNED_BSS
296 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
297 asm_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
299 /* Output function declarations at the end of the file. */
300 #undef TARGET_ASM_FILE_END
301 #define TARGET_ASM_FILE_END i386_pe_file_end
303 #undef ASM_COMMENT_START
304 #define ASM_COMMENT_START " #"
306 /* DWARF2 Unwinding doesn't work with exception handling yet. To make
307 it work, we need to build a libgcc_s.dll, and dcrt0.o should be
308 changed to call __register_frame_info/__deregister_frame_info. */
309 #define DWARF2_UNWIND_INFO 0
311 /* Don't assume anything about the header files. */
312 #define NO_IMPLICIT_EXTERN_C
315 #define PROFILE_HOOK(LABEL) \
316 if (MAIN_NAME_P (DECL_NAME (current_function_decl))) \
318 emit_call_insn (gen_rtx_CALL (VOIDmode, \
319 gen_rtx_MEM (FUNCTION_MODE, \
320 gen_rtx_SYMBOL_REF (Pmode, "_monstartup")), \
324 /* Java Native Interface (JNI) methods on Win32 are invoked using the
325 stdcall calling convention. */
326 #undef MODIFY_JNI_METHOD_CALL
327 #define MODIFY_JNI_METHOD_CALL(MDECL) \
328 build_type_attribute_variant ((MDECL), \
329 build_tree_list (get_identifier ("stdcall"), \
332 /* External function declarations. */
334 extern void i386_pe_record_external_function (const char *);
335 extern void i386_pe_declare_function_type (FILE *, const char *, int);
336 extern void i386_pe_record_exported_symbol (const char *, int);
337 extern void i386_pe_file_end (void);
338 extern int i386_pe_dllexport_name_p (const char *);
339 extern int i386_pe_dllimport_name_p (const char *);
341 /* For Win32 ABI compatibility */
342 #undef DEFAULT_PCC_STRUCT_RETURN
343 #define DEFAULT_PCC_STRUCT_RETURN 0
345 /* MSVC returns aggregate types of up to 8 bytes via registers.
346 See i386.c:ix86_return_in_memory. */
347 #undef MS_AGGREGATE_RETURN
348 #define MS_AGGREGATE_RETURN 1
350 /* No data type wants to be aligned rounder than this. */
351 #undef BIGGEST_ALIGNMENT
352 #define BIGGEST_ALIGNMENT 128
354 /* Native complier aligns internal doubles in structures on dword boundaries. */
355 #undef BIGGEST_FIELD_ALIGNMENT
356 #define BIGGEST_FIELD_ALIGNMENT 64
358 /* A bit-field declared as `int' forces `int' alignment for the struct. */
359 #undef PCC_BITFIELD_TYPE_MATTERS
360 #define PCC_BITFIELD_TYPE_MATTERS 1
361 #define GROUP_BITFIELDS_BY_ALIGN TYPE_NATIVE(rec)
363 /* Enable alias attribute support. */
365 #define SET_ASM_OP "\t.set\t"
367 /* This implements the `alias' attribute, keeping any stdcall or
368 fastcall decoration. */
369 #undef ASM_OUTPUT_DEF_FROM_DECLS
370 #define ASM_OUTPUT_DEF_FROM_DECLS(STREAM, DECL, TARGET) \
374 rtx rtlname = XEXP (DECL_RTL (DECL), 0); \
375 if (GET_CODE (rtlname) == SYMBOL_REF) \
376 alias = XSTR (rtlname, 0); \
379 if (TREE_CODE (DECL) == FUNCTION_DECL) \
380 i386_pe_declare_function_type (STREAM, alias, \
381 TREE_PUBLIC (DECL)); \
382 ASM_OUTPUT_DEF (STREAM, alias, IDENTIFIER_POINTER (TARGET)); \
385 /* Decide whether it is safe to use a local alias for a virtual function
386 when constructing thunks. */
387 #undef TARGET_USE_LOCAL_THUNK_ALIAS_P
388 #define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) (!DECL_ONE_ONLY (DECL))