FSF GCC merge 02/23/03
[official-gcc.git] / gcc / config / i386 / cygwin.h
blobdf269298d5d5e35ae9b9c34ea9068b5f4dddadc0
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
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)
11 any later version.
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 DBX_DEBUGGING_INFO 1
24 #define SDB_DEBUGGING_INFO 1
25 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
27 #define TARGET_VERSION fprintf (stderr, " (x86 Cygwin)");
28 #define TARGET_EXECUTABLE_SUFFIX ".exe"
30 #include <stdio.h>
31 #include "i386/i386.h"
32 #include "i386/unix.h"
33 #include "i386/bsd.h"
34 #include "i386/gas.h"
35 #include "dbxcoff.h"
37 /* Masks for subtarget switches used by other files. */
38 #define MASK_NOP_FUN_DLLIMPORT 0x08000000 /* Ignore dllimport for functions */
40 /* Used in winnt.c. */
41 #define TARGET_NOP_FUN_DLLIMPORT (target_flags & MASK_NOP_FUN_DLLIMPORT)
43 #undef SUBTARGET_SWITCHES
44 #define SUBTARGET_SWITCHES \
45 { "cygwin", 0, N_("Use the Cygwin interface") }, \
46 { "no-cygwin", 0, N_("Use the Mingw32 interface") }, \
47 { "windows", 0, N_("Create GUI application") }, \
48 { "no-win32", 0, N_("Don't set Windows defines") }, \
49 { "win32", 0, N_("Set Windows defines") }, \
50 { "console", 0, N_("Create console application") },\
51 { "dll", 0, N_("Generate code for a DLL") }, \
52 { "nop-fun-dllimport", MASK_NOP_FUN_DLLIMPORT, \
53 N_("Ignore dllimport for functions") }, \
54 { "no-nop-fun-dllimport", -MASK_NOP_FUN_DLLIMPORT, "" }, \
55 { "threads", 0, N_("Use Mingw-specific thread support") },
57 #define MAYBE_UWIN_CPP_BUILTINS() /* Nothing. */
58 #define TARGET_OS_CPP_BUILTINS() \
59 do \
60 { \
61 builtin_define ("_X86_=1"); \
62 builtin_assert ("system=winnt"); \
63 builtin_define ("__stdcall=__attribute__((__stdcall__))"); \
64 builtin_define ("__fastcall=__attribute__((__fastcall__))"); \
65 builtin_define ("__cdecl=__attribute__((__cdecl__))"); \
66 builtin_define ("__declspec(x)=__attribute__((x))"); \
67 if (!flag_iso) \
68 { \
69 builtin_define ("_stdcall=__attribute__((__stdcall__))"); \
70 builtin_define ("_fastcall=__attribute__((__fastcall__))"); \
71 builtin_define ("_cdecl=__attribute__((__cdecl__))"); \
72 } \
73 MAYBE_UWIN_CPP_BUILTINS (); \
74 } \
75 while (0)
77 #ifdef CROSS_COMPILE
78 #define CYGWIN_INCLUDES "%{!nostdinc:-idirafter " CYGWIN_CROSS_DIR "/include}"
79 #define W32API_INC "%{!nostdinc:-idirafter " CYGWIN_CROSS_DIR "/include/w32api}"
80 #define W32API_LIB "-L" CYGWIN_CROSS_DIR "/lib/w32api/"
81 #define CYGWIN_LIB CYGWIN_CROSS_DIR "/lib"
82 #define MINGW_LIBS "-L" CYGWIN_CROSS_DIR "/lib/mingw"
83 #define MINGW_INCLUDES "%{!nostdinc:-isystem " CYGWIN_CROSS_DIR "/include/mingw/g++-3 "\
84 "-isystem " CYGWIN_CROSS_DIR "/include/mingw/g++ "\
85 "-idirafter " CYGWIN_CROSS_DIR "/include/mingw}"
86 #else
87 #define CYGWIN_INCLUDES "%{!nostdinc:-isystem /usr/local/include "\
88 "-idirafter " CYGWIN_CROSS_DIR "/include "\
89 "-idirafter /usr/include}"
90 #define W32API_INC "%{!nostdinc:"\
91 "-idirafter " CYGWIN_CROSS_DIR "/include/w32api "\
92 "-idirafter /usr/include/w32api}"
93 #define W32API_LIB "-L" CYGWIN_CROSS_DIR "/lib/w32api/ -L/usr/lib/w32api/"
94 #define CYGWIN_LIB "/usr/lib"
95 #define MINGW_LIBS "-L/usr/local/lib/mingw -L/usr/lib/mingw"
96 #define MINGW_INCLUDES "%{!nostdinc:-isystem /usr/include/mingw/g++-3 "\
97 "-isystem /usr/include/mingw/g++ "\
98 "-isystem /usr/local/include/mingw "\
99 "-idirafter " CYGWIN_CROSS_DIR "/include/mingw "\
100 "-idirafter /usr/include/mingw}"
101 #endif
103 /* Get tree.c to declare a target-specific specialization of
104 merge_decl_attributes. */
105 #define TARGET_DLLIMPORT_DECL_ATTRIBUTES
107 /* Support the __declspec keyword by turning them into attributes.
108 We currently only support: dllimport and dllexport.
109 Note that the current way we do this may result in a collision with
110 predefined attributes later on. This can be solved by using one attribute,
111 say __declspec__, and passing args to it. The problem with that approach
112 is that args are not accumulated: each new appearance would clobber any
113 existing args. */
115 #undef CPP_SPEC
116 #define CPP_SPEC "%{posix:-D_POSIX_SOURCE} \
117 %{mno-win32:%{mno-cygwin: %emno-cygwin and mno-win32 are not compatible}} \
118 %{mno-cygwin:-D__MSVCRT__ -D__MINGW32__ %{mthreads:-D_MT} "\
119 MINGW_INCLUDES "} \
120 %{!mno-cygwin:-D__CYGWIN32__ -D__CYGWIN__ %{!ansi:-Dunix} -D__unix__ -D__unix "\
121 CYGWIN_INCLUDES "}\
122 %{mwin32|mno-cygwin:-DWIN32 -D_WIN32 -D__WIN32 -D__WIN32__ %{!ansi:-DWINNT}}\
123 %{!mno-win32:" W32API_INC "}\
126 #undef STARTFILE_SPEC
127 #define STARTFILE_SPEC "\
128 %{shared|mdll: %{mno-cygwin:" MINGW_LIBS " dllcrt2%O%s}}\
129 %{!shared: %{!mdll: %{!mno-cygwin:crt0%O%s} %{mno-cygwin:" MINGW_LIBS " crt2%O%s}\
130 %{pg:gcrt0%O%s}}}\
133 /* Normally, -lgcc is not needed since everything in it is in the DLL, but we
134 want to allow things to be added to it when installing new versions of
135 GCC without making a new CYGWIN.DLL, so we leave it. Profiling is handled
136 by calling the init function from the prologue. */
138 #undef LIBGCC_SPEC
139 #define LIBGCC_SPEC "%{mno-cygwin: %{mthreads:-lmingwthrd} -lmingw32} \
140 -lgcc %{mno-cygwin:-lmoldname -lmingwex -lmsvcrt}"
142 /* This macro defines names of additional specifications to put in the specs
143 that can be used in various specifications like CC1_SPEC. Its definition
144 is an initializer with a subgrouping for each command option.
146 Each subgrouping contains a string constant, that defines the
147 specification name, and a string constant that used by the GNU CC driver
148 program.
150 Do not define this macro if it does not need to do anything. */
152 #undef SUBTARGET_EXTRA_SPECS
153 #define SUBTARGET_EXTRA_SPECS \
154 { "mingw_include_path", DEFAULT_TARGET_MACHINE }
156 /* We have to dynamic link to get to the system DLLs. All of libc, libm and
157 the Unix stuff is in cygwin.dll. The import library is called
158 'libcygwin.a'. For Windows applications, include more libraries, but
159 always include kernel32. We'd like to specific subsystem windows to
160 ld, but that doesn't work just yet. */
162 #undef LIB_SPEC
163 #define LIB_SPEC "\
164 %{pg:-lgmon} \
165 %{!mno-cygwin:-lcygwin} \
166 %{mno-cygwin:%{mthreads:-lmingwthrd} -lmingw32} \
167 %{mwindows:-lgdi32 -lcomdlg32} \
168 -luser32 -lkernel32 -ladvapi32 -lshell32"
170 #define LINK_SPEC W32API_LIB "\
171 %{mwindows:--subsystem windows} \
172 %{mconsole:--subsystem console} \
173 %{shared: %{mdll: %eshared and mdll are not compatible}} \
174 %{shared: --shared} %{mdll:--dll} \
175 %{static:-Bstatic} %{!static:-Bdynamic} \
176 %{shared|mdll: -e \
177 %{mno-cygwin:_DllMainCRTStartup@12} \
178 %{!mno-cygwin:__cygwin_dll_entry@12}}\
179 --dll-search-prefix=cyg"
181 #undef MATH_LIBRARY
182 #define MATH_LIBRARY ""
184 #define SIZE_TYPE "unsigned int"
185 #define PTRDIFF_TYPE "int"
186 #define WCHAR_TYPE_SIZE 16
187 #define WCHAR_TYPE "short unsigned int"
190 /* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop). */
191 #define HANDLE_PRAGMA_PACK_PUSH_POP 1
193 union tree_node;
194 #define TREE union tree_node *
196 #undef EXTRA_SECTIONS
197 #define EXTRA_SECTIONS in_drectve
199 #undef EXTRA_SECTION_FUNCTIONS
200 #define EXTRA_SECTION_FUNCTIONS \
201 DRECTVE_SECTION_FUNCTION \
202 SWITCH_TO_SECTION_FUNCTION
204 #define DRECTVE_SECTION_FUNCTION \
205 void \
206 drectve_section () \
208 if (in_section != in_drectve) \
210 fprintf (asm_out_file, "%s\n", "\t.section .drectve\n"); \
211 in_section = in_drectve; \
214 void drectve_section PARAMS ((void));
216 /* Switch to SECTION (an `enum in_section').
218 ??? This facility should be provided by GCC proper.
219 The problem is that we want to temporarily switch sections in
220 ASM_DECLARE_OBJECT_NAME and then switch back to the original section
221 afterwards. */
222 #define SWITCH_TO_SECTION_FUNCTION \
223 void switch_to_section PARAMS ((enum in_section, tree)); \
224 void \
225 switch_to_section (section, decl) \
226 enum in_section section; \
227 tree decl; \
229 switch (section) \
231 case in_text: text_section (); break; \
232 case in_data: data_section (); break; \
233 case in_named: named_section (decl, NULL, 0); break; \
234 case in_drectve: drectve_section (); break; \
235 default: abort (); break; \
239 /* Don't allow flag_pic to propagate since gas may produce invalid code
240 otherwise. */
242 #undef SUBTARGET_OVERRIDE_OPTIONS
243 #define SUBTARGET_OVERRIDE_OPTIONS \
244 do { \
245 if (flag_pic) \
247 warning ("-f%s ignored for target (all code is position independent)",\
248 (flag_pic > 1) ? "PIC" : "pic"); \
249 flag_pic = 0; \
251 } while (0) \
253 /* Define this macro if references to a symbol must be treated
254 differently depending on something about the variable or
255 function named by the symbol (such as what section it is in).
257 On i386 running Windows NT, modify the assembler name with a suffix
258 consisting of an atsign (@) followed by string of digits that represents
259 the number of bytes of arguments passed to the function, if it has the
260 attribute STDCALL.
262 In addition, we must mark dll symbols specially. Definitions of
263 dllexport'd objects install some info in the .drectve section.
264 References to dllimport'd objects are fetched indirectly via
265 _imp__. If both are declared, dllexport overrides. This is also
266 needed to implement one-only vtables: they go into their own
267 section and we need to set DECL_SECTION_NAME so we do that here.
268 Note that we can be called twice on the same decl. */
270 #undef TARGET_ENCODE_SECTION_INFO
271 #define TARGET_ENCODE_SECTION_INFO i386_pe_encode_section_info
272 #undef TARGET_STRIP_NAME_ENCODING
273 #define TARGET_STRIP_NAME_ENCODING i386_pe_strip_name_encoding_full
275 /* Output a reference to a label. */
276 #undef ASM_OUTPUT_LABELREF
277 #define ASM_OUTPUT_LABELREF i386_pe_output_labelref
279 /* Output a common block. */
280 #undef ASM_OUTPUT_COMMON
281 #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED) \
282 do { \
283 if (i386_pe_dllexport_name_p (NAME)) \
284 i386_pe_record_exported_symbol (NAME, 1); \
285 if (! i386_pe_dllimport_name_p (NAME)) \
287 fprintf ((STREAM), "\t.comm\t"); \
288 assemble_name ((STREAM), (NAME)); \
289 fprintf ((STREAM), ", %d\t%s %d\n", \
290 (ROUNDED), ASM_COMMENT_START, (SIZE)); \
292 } while (0)
294 /* Output the label for an initialized variable. */
295 #undef ASM_DECLARE_OBJECT_NAME
296 #define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL) \
297 do { \
298 if (i386_pe_dllexport_name_p (NAME)) \
299 i386_pe_record_exported_symbol (NAME, 1); \
300 ASM_OUTPUT_LABEL ((STREAM), (NAME)); \
301 } while (0)
304 /* Emit code to check the stack when allocating more that 4000
305 bytes in one go. */
307 #define CHECK_STACK_LIMIT 4000
309 /* By default, target has a 80387, uses IEEE compatible arithmetic,
310 returns float values in the 387 and needs stack probes.
311 We also align doubles to 64-bits for MSVC default compatibility. */
313 #undef TARGET_SUBTARGET_DEFAULT
314 #define TARGET_SUBTARGET_DEFAULT \
315 (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE \
316 | MASK_ALIGN_DOUBLE)
318 /* This is how to output an assembler line
319 that says to advance the location counter
320 to a multiple of 2**LOG bytes. */
322 #undef ASM_OUTPUT_ALIGN
323 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
324 if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
326 /* Define this macro if in some cases global symbols from one translation
327 unit may not be bound to undefined symbols in another translation unit
328 without user intervention. For instance, under Microsoft Windows
329 symbols must be explicitly imported from shared libraries (DLLs). */
330 #define MULTIPLE_SYMBOL_SPACES
332 extern void i386_pe_unique_section PARAMS ((TREE, int));
333 #define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
335 #define SUPPORTS_ONE_ONLY 1
337 /* Switch into a generic section. */
338 #define TARGET_ASM_NAMED_SECTION i386_pe_asm_named_section
340 /* Select attributes for named sections. */
341 #define TARGET_SECTION_TYPE_FLAGS i386_pe_section_type_flags
343 /* Write the extra assembler code needed to declare a function
344 properly. If we are generating SDB debugging information, this
345 will happen automatically, so we only need to handle other cases. */
346 #undef ASM_DECLARE_FUNCTION_NAME
347 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
348 do \
350 if (i386_pe_dllexport_name_p (NAME)) \
351 i386_pe_record_exported_symbol (NAME, 0); \
352 if (write_symbols != SDB_DEBUG) \
353 i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL)); \
354 ASM_OUTPUT_LABEL (FILE, NAME); \
356 while (0)
358 /* Add an external function to the list of functions to be declared at
359 the end of the file. */
360 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
361 do \
363 if (TREE_CODE (DECL) == FUNCTION_DECL) \
364 i386_pe_record_external_function (NAME); \
366 while (0)
368 /* Declare the type properly for any external libcall. */
369 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
370 i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
372 /* This says out to put a global symbol in the BSS section. */
373 #undef ASM_OUTPUT_ALIGNED_BSS
374 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
375 asm_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
377 /* Output function declarations at the end of the file. */
378 #undef ASM_FILE_END
379 #define ASM_FILE_END(FILE) \
380 i386_pe_asm_file_end (FILE)
382 #undef ASM_COMMENT_START
383 #define ASM_COMMENT_START " #"
385 /* DWARF2 Unwinding doesn't work with exception handling yet. To make
386 it work, we need to build a libgcc_s.dll, and dcrt0.o should be
387 changed to call __register_frame_info/__deregister_frame_info. */
388 #define DWARF2_UNWIND_INFO 0
390 /* Don't assume anything about the header files. */
391 #define NO_IMPLICIT_EXTERN_C
393 #undef PROFILE_HOOK
394 #define PROFILE_HOOK(LABEL) \
395 if (MAIN_NAME_P (DECL_NAME (current_function_decl))) \
397 emit_call_insn (gen_rtx (CALL, VOIDmode, \
398 gen_rtx_MEM (FUNCTION_MODE, \
399 gen_rtx_SYMBOL_REF (Pmode, "_monstartup")), \
400 const0_rtx)); \
403 /* Java Native Interface (JNI) methods on Win32 are invoked using the
404 stdcall calling convention. */
405 #undef MODIFY_JNI_METHOD_CALL
406 #define MODIFY_JNI_METHOD_CALL(MDECL) \
407 build_type_attribute_variant ((MDECL), \
408 build_tree_list (get_identifier ("stdcall"), \
409 NULL))
412 /* External function declarations. */
414 extern void i386_pe_record_external_function PARAMS ((const char *));
415 extern void i386_pe_declare_function_type PARAMS ((FILE *, const char *, int));
416 extern void i386_pe_record_exported_symbol PARAMS ((const char *, int));
417 extern void i386_pe_asm_file_end PARAMS ((FILE *));
418 extern int i386_pe_dllexport_name_p PARAMS ((const char *));
419 extern int i386_pe_dllimport_name_p PARAMS ((const char *));
421 /* For Win32 ABI compatibility */
422 #undef DEFAULT_PCC_STRUCT_RETURN
423 #define DEFAULT_PCC_STRUCT_RETURN 0
425 /* MSVC returns aggregate types of up to 8 bytes via registers.
426 See i386.c:ix86_return_in_memory. */
427 #undef MS_AGGREGATE_RETURN
428 #define MS_AGGREGATE_RETURN 1
430 /* No data type wants to be aligned rounder than this. */
431 #undef BIGGEST_ALIGNMENT
432 #define BIGGEST_ALIGNMENT 128
434 /* Native complier aligns internal doubles in structures on dword boundaries. */
435 #undef BIGGEST_FIELD_ALIGNMENT
436 #define BIGGEST_FIELD_ALIGNMENT 64
438 /* A bit-field declared as `int' forces `int' alignment for the struct. */
439 #undef PCC_BITFIELD_TYPE_MATTERS
440 #define PCC_BITFIELD_TYPE_MATTERS 1
441 #define GROUP_BITFIELDS_BY_ALIGN TYPE_NATIVE(rec)
444 /* Enable alias attribute support. */
445 #ifndef SET_ASM_OP
446 #define SET_ASM_OP "\t.set\t"
447 #endif
449 /* Override GCC's relative pathname lookup (ie., relocatability) unless
450 otherwise told by other subtargets. */
451 #ifndef WIN32_NO_ABSOLUTE_INST_DIRS
452 #undef MD_STARTFILE_PREFIX
453 #define MD_STARTFILE_PREFIX "/usr/lib/"
455 #undef STANDARD_STARTFILE_PREFIX
456 #define STANDARD_STARTFILE_PREFIX "/usr/lib/mingw/"
458 #ifndef CROSS_COMPILE
459 #undef LOCAL_INCLUDE_DIR
460 #undef TOOL_INCLUDE_DIR
461 #undef SYSTEM_INCLUDE_DIR
462 #undef STANDARD_INCLUDE_DIR
463 #define STANDARD_INCLUDE_DIR 0
464 #endif /* not CROSS_COMPILE */
465 #endif /* not WIN32_NO_ABSOLUTE_INST_DIRS */
467 #undef TREE
469 #ifndef BUFSIZ
470 # undef FILE
471 #endif