OSDN Git Service

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