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
4 Free Software Foundation, Inc.
6 This file is part of GNU CC.
8 GNU CC 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 GNU CC 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 GNU CC; 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 YES_UNDERSCORES
25 #define DBX_DEBUGGING_INFO
26 #define SDB_DEBUGGING_INFO
27 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
29 #define TARGET_EXECUTABLE_SUFFIX ".exe"
35 /* Augment TARGET_SWITCHES with the cygwin/no-cygwin options. */
36 #define MASK_WIN32 0x40000000 /* Use -lming32 interface */
37 #define MASK_CYGWIN 0x20000000 /* Use -lcygwin interface */
38 #define MASK_WINDOWS 0x10000000 /* Use windows interface */
39 #define MASK_DLL 0x08000000 /* Use dll interface */
40 #define MASK_NOP_FUN_DLLIMPORT 0x20000 /* Ignore dllimport for functions */
42 #define TARGET_WIN32 (target_flags & MASK_WIN32)
43 #define TARGET_CYGWIN (target_flags & MASK_CYGWIN)
44 #define TARGET_WINDOWS (target_flags & MASK_WINDOWS)
45 #define TARGET_DLL (target_flags & MASK_DLL)
46 #define TARGET_NOP_FUN_DLLIMPORT (target_flags & MASK_NOP_FUN_DLLIMPORT)
48 #undef SUBTARGET_SWITCHES
49 #define SUBTARGET_SWITCHES \
50 { "cygwin", MASK_CYGWIN, \
51 N_("Use the Cygwin interface") }, \
52 { "no-cygwin", MASK_WIN32, \
53 N_("Use the Mingw32 interface") }, \
54 { "windows", MASK_WINDOWS, N_("Create GUI application") }, \
55 { "no-win32", -MASK_WIN32, N_("Don't set Windows defines") },\
56 { "win32", 0, N_("Set Windows defines") }, \
57 { "console", -MASK_WINDOWS, \
58 N_("Create console application") }, \
59 { "dll", MASK_DLL, N_("Generate code for a DLL") }, \
60 { "nop-fun-dllimport", MASK_NOP_FUN_DLLIMPORT, \
61 N_("Ignore dllimport for functions") }, \
62 { "no-nop-fun-dllimport", -MASK_NOP_FUN_DLLIMPORT, "" }, \
63 { "threads", 0, N_("Use Mingw-specific thread support") },
66 #define CPP_PREDEFINES "-D_X86_=1 -Asystem=winnt"
69 #define CYGWIN_INCLUDES "%{!nostdinc:-idirafter " CYGWIN_CROSS_DIR "/include}"
70 #define W32API_INC "%{!nostdinc:-idirafter " CYGWIN_CROSS_DIR "/include/w32api}"
71 #define W32API_LIB "-L" CYGWIN_CROSS_DIR "/lib/w32api/"
72 #define CYGWIN_LIB CYGWIN_CROSS_DIR "/lib"
73 #define MINGW_LIBS "-L" CYGWIN_CROSS_DIR "/lib/mingw"
74 #define MINGW_INCLUDES "%{!nostdinc:-isystem " CYGWIN_CROSS_DIR "/include/mingw/g++-3 "\
75 "-isystem " CYGWIN_CROSS_DIR "/include/mingw/g++ "\
76 "-idirafter " CYGWIN_CROSS_DIR "/include/mingw}"
78 #define CYGWIN_INCLUDES "%{!nostdinc:-isystem /usr/local/include "\
79 "-idirafter " CYGWIN_CROSS_DIR "/include "\
80 "-idirafter /usr/include}"
81 #define W32API_INC "%{!nostdinc:"\
82 "-idirafter " CYGWIN_CROSS_DIR "/include/w32api "\
83 "-idirafter /usr/include/w32api}"
84 #define W32API_LIB "-L" CYGWIN_CROSS_DIR "/lib/w32api/ -L/usr/lib/w32api/"
85 #define CYGWIN_LIB "/usr/lib"
86 #define MINGW_LIBS "-L/usr/local/lib/mingw -L/usr/lib/mingw"
87 #define MINGW_INCLUDES "%{!nostdinc:-isystem /usr/include/mingw/g++-3 "\
88 "-isystem /usr/include/mingw/g++ "\
89 "-isystem /usr/local/include/mingw "\
90 "-idirafter " CYGWIN_CROSS_DIR "/include/mingw "\
91 "-idirafter /usr/include/mingw}"
94 /* Get tree.c to declare a target-specific specialization of
95 merge_decl_attributes. */
96 #define TARGET_DLLIMPORT_DECL_ATTRIBUTES
98 /* Support the __declspec keyword by turning them into attributes.
99 We currently only support: dllimport and dllexport.
100 Note that the current way we do this may result in a collision with
101 predefined attributes later on. This can be solved by using one attribute,
102 say __declspec__, and passing args to it. The problem with that approach
103 is that args are not accumulated: each new appearance would clobber any
107 #define CPP_SPEC "%(cpp_cpu) %{posix:-D_POSIX_SOURCE} \
108 -D__stdcall=__attribute__((__stdcall__)) \
109 -D__cdecl=__attribute__((__cdecl__)) \
110 %{!ansi:-D_stdcall=__attribute__((__stdcall__)) \
111 -D_cdecl=__attribute__((__cdecl__))} \
112 -D__declspec(x)=__attribute__((x)) \
113 -D__i386__ -D__i386 \
114 %{mno-win32:%{mno-cygwin: %emno-cygwin and mno-win32 are not compatible}} \
115 %{mno-cygwin:-D__MSVCRT__ -D__MINGW32__ %{mthreads:-D_MT} "\
117 %{!mno-cygwin:-D__CYGWIN32__ -D__CYGWIN__ %{!ansi:-Dunix} -D__unix__ -D__unix "\
119 %{mwin32|mno-cygwin:-DWIN32 -D_WIN32 -D__WIN32 -D__WIN32__ %{!ansi:-DWINNT}}\
120 %{!mno-win32:" W32API_INC "}\
123 #undef STARTFILE_SPEC
124 #define STARTFILE_SPEC "\
125 %{shared|mdll: %{mno-cygwin:" MINGW_LIBS " dllcrt2%O%s}}\
126 %{!shared: %{!mdll: %{!mno-cygwin:crt0%O%s} %{mno-cygwin:" MINGW_LIBS " crt2%O%s}\
130 /* Normally, -lgcc is not needed since everything in it is in the DLL, but we
131 want to allow things to be added to it when installing new versions of
132 GCC without making a new CYGWIN.DLL, so we leave it. Profiling is handled
133 by calling the init function from the prologue. */
136 #define LIBGCC_SPEC "%{mno-cygwin: %{mthreads:-lmingwthrd} -lmingw32} -lgcc %{mno-cygwin:-lmoldname -lmsvcrt}"
138 /* This macro defines names of additional specifications to put in the specs
139 that can be used in various specifications like CC1_SPEC. Its definition
140 is an initializer with a subgrouping for each command option.
142 Each subgrouping contains a string constant, that defines the
143 specification name, and a string constant that used by the GNU CC driver
146 Do not define this macro if it does not need to do anything. */
148 #undef SUBTARGET_EXTRA_SPECS
149 #define SUBTARGET_EXTRA_SPECS \
150 { "mingw_include_path", DEFAULT_TARGET_MACHINE }
152 /* We have to dynamic link to get to the system DLLs. All of libc, libm and
153 the Unix stuff is in cygwin.dll. The import library is called
154 'libcygwin.a'. For Windows applications, include more libraries, but
155 always include kernel32. We'd like to specific subsystem windows to
156 ld, but that doesn't work just yet. */
161 %{!mno-cygwin:-lcygwin} \
162 %{mno-cygwin:%{mthreads:-lmingwthrd} -lmingw32} \
163 %{mwindows:-lgdi32 -lcomdlg32} \
164 -luser32 -lkernel32 -ladvapi32 -lshell32"
166 #define LINK_SPEC W32API_LIB "\
167 %{mwindows:--subsystem windows} \
168 %{mconsole:--subsystem console} \
169 %{shared: %{mdll: %eshared and mdll are not compatible}} \
170 %{shared: --shared} %{mdll:--dll} \
171 %{static:-Bstatic} %{!static:-Bdynamic} \
173 %{mno-cygwin:_DllMainCRTStartup@12} \
174 %{!mno-cygwin:__cygwin_dll_entry@12}}\
175 --dll-search-prefix=cyg"
178 #define MATH_LIBRARY ""
180 #define SIZE_TYPE "unsigned int"
181 #define PTRDIFF_TYPE "int"
182 #define WCHAR_UNSIGNED 1
183 #define WCHAR_TYPE_SIZE 16
184 #define WCHAR_TYPE "short unsigned int"
187 /* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop). */
188 #define HANDLE_PRAGMA_PACK_PUSH_POP 1
191 #define TREE union tree_node *
193 #undef EXTRA_SECTIONS
194 #define EXTRA_SECTIONS in_drectve
196 #undef EXTRA_SECTION_FUNCTIONS
197 #define EXTRA_SECTION_FUNCTIONS \
198 DRECTVE_SECTION_FUNCTION \
199 SWITCH_TO_SECTION_FUNCTION
201 #define DRECTVE_SECTION_FUNCTION \
205 if (in_section != in_drectve) \
207 fprintf (asm_out_file, "%s\n", "\t.section .drectve\n"); \
208 in_section = in_drectve; \
211 void drectve_section PARAMS ((void));
213 /* Switch to SECTION (an `enum in_section').
215 ??? This facility should be provided by GCC proper.
216 The problem is that we want to temporarily switch sections in
217 ASM_DECLARE_OBJECT_NAME and then switch back to the original section
219 #define SWITCH_TO_SECTION_FUNCTION \
220 void switch_to_section PARAMS ((enum in_section, tree)); \
222 switch_to_section (section, decl) \
223 enum in_section section; \
228 case in_text: text_section (); break; \
229 case in_data: data_section (); break; \
230 case in_named: named_section (decl, NULL, 0); break; \
231 case in_drectve: drectve_section (); break; \
232 default: abort (); break; \
236 /* Don't allow flag_pic to propagate since gas may produce invalid code
239 #undef SUBTARGET_OVERRIDE_OPTIONS
240 #define SUBTARGET_OVERRIDE_OPTIONS \
244 warning ("-f%s ignored for target (all code is position independent)",\
245 (flag_pic > 1) ? "PIC" : "pic"); \
250 /* Define this macro if references to a symbol must be treated
251 differently depending on something about the variable or
252 function named by the symbol (such as what section it is in).
254 On i386 running Windows NT, modify the assembler name with a suffix
255 consisting of an atsign (@) followed by string of digits that represents
256 the number of bytes of arguments passed to the function, if it has the
259 In addition, we must mark dll symbols specially. Definitions of
260 dllexport'd objects install some info in the .drectve section.
261 References to dllimport'd objects are fetched indirectly via
262 _imp__. If both are declared, dllexport overrides. This is also
263 needed to implement one-only vtables: they go into their own
264 section and we need to set DECL_SECTION_NAME so we do that here.
265 Note that we can be called twice on the same decl. */
267 extern void i386_pe_encode_section_info PARAMS ((TREE, int));
269 #undef ENCODE_SECTION_INFO
270 #define ENCODE_SECTION_INFO(DECL, FIRST) \
271 i386_pe_encode_section_info (DECL, FIRST)
273 /* Utility used only in this file. */
274 #define I386_PE_STRIP_ENCODING(SYM_NAME) \
275 ((SYM_NAME) + ((SYM_NAME)[0] == '@' \
276 ? ((SYM_NAME)[3] == '*' ? 4 : 3) : 0) \
277 + ((SYM_NAME)[0] == '*' ? 1 : 0))
279 /* This macro gets just the user-specified name
280 out of the string in a SYMBOL_REF. Discard
281 trailing @[NUM] encoded by ENCODE_SECTION_INFO. */
282 #undef STRIP_NAME_ENCODING
283 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
286 const char *_name = I386_PE_STRIP_ENCODING (SYMBOL_NAME); \
287 for (_p = _name; *_p && *_p != '@'; ++_p) \
291 int _len = _p - _name; \
292 char *_new_name = (char *) alloca (_len + 1); \
293 strncpy (_new_name, _name, _len); \
294 _new_name[_len] = '\0'; \
302 /* Output a reference to a label. */
303 #undef ASM_OUTPUT_LABELREF
304 #define ASM_OUTPUT_LABELREF(STREAM, NAME) \
305 fprintf (STREAM, "%s%s", USER_LABEL_PREFIX, \
306 I386_PE_STRIP_ENCODING (NAME)) \
308 /* Output a common block. */
309 #undef ASM_OUTPUT_COMMON
310 #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED) \
312 if (i386_pe_dllexport_name_p (NAME)) \
313 i386_pe_record_exported_symbol (NAME, 1); \
314 if (! i386_pe_dllimport_name_p (NAME)) \
316 fprintf ((STREAM), "\t.comm\t"); \
317 assemble_name ((STREAM), (NAME)); \
318 fprintf ((STREAM), ", %d\t%s %d\n", \
319 (ROUNDED), ASM_COMMENT_START, (SIZE)); \
323 /* Output the label for an initialized variable. */
324 #undef ASM_DECLARE_OBJECT_NAME
325 #define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL) \
327 if (i386_pe_dllexport_name_p (NAME)) \
328 i386_pe_record_exported_symbol (NAME, 1); \
329 ASM_OUTPUT_LABEL ((STREAM), (NAME)); \
333 /* Emit code to check the stack when allocating more that 4000
336 #define CHECK_STACK_LIMIT 4000
338 /* By default, target has a 80387, uses IEEE compatible arithmetic,
339 and returns float values in the 387 and needs stack probes */
340 #undef TARGET_SUBTARGET_DEFAULT
342 #define TARGET_SUBTARGET_DEFAULT \
343 (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE)
345 /* This is how to output an assembler line
346 that says to advance the location counter
347 to a multiple of 2**LOG bytes. */
349 #undef ASM_OUTPUT_ALIGN
350 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
351 if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
353 /* Define this macro if in some cases global symbols from one translation
354 unit may not be bound to undefined symbols in another translation unit
355 without user intervention. For instance, under Microsoft Windows
356 symbols must be explicitly imported from shared libraries (DLLs). */
357 #define MULTIPLE_SYMBOL_SPACES
359 extern void i386_pe_unique_section PARAMS ((TREE, int));
360 #define UNIQUE_SECTION(DECL,RELOC) i386_pe_unique_section (DECL, RELOC)
362 #define SUPPORTS_ONE_ONLY 1
364 /* Switch into a generic section. */
365 #define TARGET_ASM_NAMED_SECTION i386_pe_asm_named_section
367 /* Select attributes for named sections. */
368 #define TARGET_SECTION_TYPE_FLAGS i386_pe_section_type_flags
370 /* Write the extra assembler code needed to declare a function
371 properly. If we are generating SDB debugging information, this
372 will happen automatically, so we only need to handle other cases. */
373 #undef ASM_DECLARE_FUNCTION_NAME
374 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
377 if (i386_pe_dllexport_name_p (NAME)) \
378 i386_pe_record_exported_symbol (NAME, 0); \
379 if (write_symbols != SDB_DEBUG) \
380 i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL)); \
381 ASM_OUTPUT_LABEL (FILE, NAME); \
385 /* Add an external function to the list of functions to be declared at
386 the end of the file. */
387 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
390 if (TREE_CODE (DECL) == FUNCTION_DECL) \
391 i386_pe_record_external_function (NAME); \
395 /* Declare the type properly for any external libcall. */
396 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
397 i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
399 /* This says out to put a global symbol in the BSS section. */
400 #undef ASM_OUTPUT_ALIGNED_BSS
401 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
402 asm_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
404 /* Output function declarations at the end of the file. */
406 #define ASM_FILE_END(FILE) \
407 i386_pe_asm_file_end (FILE)
409 #undef ASM_COMMENT_START
410 #define ASM_COMMENT_START " #"
412 /* Don't assume anything about the header files. */
413 #define NO_IMPLICIT_EXTERN_C
415 #define SUBTARGET_PROLOGUE \
416 if (current_function_profile \
417 && MAIN_NAME_P (DECL_NAME (current_function_decl))) \
419 emit_call_insn (gen_rtx (CALL, VOIDmode, \
420 gen_rtx_MEM (FUNCTION_MODE, \
421 gen_rtx_SYMBOL_REF (Pmode, "_monstartup")), \
425 /* External function declarations. */
427 extern void i386_pe_record_external_function PARAMS ((const char *));
428 extern void i386_pe_declare_function_type PARAMS ((FILE *, const char *, int));
429 extern void i386_pe_record_exported_symbol PARAMS ((const char *, int));
430 extern void i386_pe_asm_file_end PARAMS ((FILE *));
431 extern int i386_pe_dllexport_name_p PARAMS ((const char *));
432 extern int i386_pe_dllimport_name_p PARAMS ((const char *));
434 /* For Win32 ABI compatibility */
435 #undef DEFAULT_PCC_STRUCT_RETURN
436 #define DEFAULT_PCC_STRUCT_RETURN 0
438 /* No data type wants to be aligned rounder than this. */
439 #undef BIGGEST_ALIGNMENT
440 #define BIGGEST_ALIGNMENT 128
442 /* Native complier aligns internal doubles in structures on dword boundaries. */
443 #undef BIGGEST_FIELD_ALIGNMENT
444 #define BIGGEST_FIELD_ALIGNMENT 64
446 /* A bitfield declared as `int' forces `int' alignment for the struct. */
447 #undef PCC_BITFIELD_TYPE_MATTERS
448 #define PCC_BITFIELD_TYPE_MATTERS 1
449 #define GROUP_BITFIELDS_BY_ALIGN TYPE_NATIVE(rec)
452 /* Enable alias attribute support. */
454 #define SET_ASM_OP "\t.set\t"
457 /* Override GCC's relative pathname lookup (ie., relocatability) unless
458 otherwise told by other subtargets. */
459 #ifndef WIN32_NO_ABSOLUTE_INST_DIRS
460 #undef MD_STARTFILE_PREFIX
461 #define MD_STARTFILE_PREFIX "/usr/lib/"
463 #undef STANDARD_STARTFILE_PREFIX
464 #define STANDARD_STARTFILE_PREFIX "/usr/lib/mingw/"
466 #ifndef CROSS_COMPILE
467 #undef LOCAL_INCLUDE_DIR
468 #undef TOOL_INCLUDE_DIR
469 #undef SYSTEM_INCLUDE_DIR
470 #undef STANDARD_INCLUDE_DIR
471 #define STANDARD_INCLUDE_DIR 0
472 #endif /* not CROSS_COMPILE */
473 #endif /* not WIN32_NO_ABSOLUTE_INST_DIRS */