OSDN Git Service

* i386/cygwin.h (SUBTARGET_OVERRIDE_OPTIONS): New macro to ignore
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / cygwin.h
1 /* Operating system specific defines to be used when targeting GCC for
2    hosting on Windows NT 3.x, using a Unix style C library and tools,
3    as distinct from winnt.h, which is used to build GCC for use with a
4    windows style library and tool set and uses the Microsoft tools.
5    Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
6
7 This file is part of GNU CC.
8
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING.  If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
23
24 #define YES_UNDERSCORES
25
26 #define DBX_DEBUGGING_INFO 
27 #define SDB_DEBUGGING_INFO 
28 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
29
30 #include "i386/gas.h"
31 #include "dbxcoff.h"
32
33 /* Augment TARGET_SWITCHES with the cygwin/no-cygwin options. */
34 #define MASK_WIN32 0x40000000 /* Use -lming32 interface */
35 #define MASK_CYGWIN  0x20000000 /* Use -lcygwin interface */
36 #define MASK_WINDOWS 0x10000000 /* Use windows interface */
37 #define MASK_DLL     0x08000000 /* Use dll interface    */
38 #define MASK_NOP_FUN_DLLIMPORT 0x20000 /* Ignore dllimport for functions */
39
40 #define TARGET_WIN32             (target_flags & MASK_WIN32)
41 #define TARGET_CYGWIN            (target_flags & MASK_CYGWIN)
42 #define TARGET_WINDOWS           (target_flags & MASK_WINDOWS)
43 #define TARGET_DLL               (target_flags & MASK_DLL)
44 #define TARGET_NOP_FUN_DLLIMPORT (target_flags & MASK_NOP_FUN_DLLIMPORT)
45
46 #undef  SUBTARGET_SWITCHES
47 #define SUBTARGET_SWITCHES \
48 { "no-cygwin",                       MASK_WIN32 }, \
49 { "cygwin",                          MASK_CYGWIN },  \
50 { "windows",                         MASK_WINDOWS }, \
51 { "dll",                             MASK_DLL },     \
52 { "nop-fun-dllimport",               MASK_NOP_FUN_DLLIMPORT }, \
53 { "no-nop-fun-dllimport",            MASK_NOP_FUN_DLLIMPORT },
54
55
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
62    existing args.  */
63
64 #ifdef CPP_PREDEFINES
65 #undef CPP_PREDEFINES
66 #endif
67
68 #define CPP_PREDEFINES "-Di386 -D_WIN32 \
69   -DWINNT  -D_X86_=1 -D__STDC__=1\
70   -D__stdcall=__attribute__((__stdcall__)) \
71   -D__cdecl=__attribute__((__cdecl__)) \
72   -D__declspec(x)=__attribute__((x)) \
73   -Asystem(winnt) -Acpu(i386) -Amachine(i386)"
74
75 /* Normally, -lgcc is not needed since everything in it is in the DLL, but we
76    want to allow things to be added to it when installing new versions of
77    GCC without making a new CYGWIN.DLL, so we leave it.  Profiling is handled
78    by calling the init function from the prologue. */
79
80 #undef STARTFILE_SPEC
81 #define STARTFILE_SPEC "%{mdll: %{!mno-cygwin:dllcrt0%O%s} \
82                                 %{mno-cygwin:dllcrt1%O%s}} \
83                         %{!mdll: %{!mno-cygwin:crt0%O%s} \
84                                  %{mno-cygwin:crt1%O%s} %{pg:gcrt0%O%s}}"
85
86 #undef CPP_SPEC
87 #define CPP_SPEC "-remap %(cpp_cpu) %{posix:-D_POSIX_SOURCE} \
88   %{!mno-cygwin:-D__CYGWIN32__ -D__CYGWIN__} \
89   %{mno-cygwin:-iwithprefixbefore include/mingw32 -D__MINGW32__=0.2}"
90
91 /* We have to dynamic link to get to the system DLLs.  All of libc, libm and
92    the Unix stuff is in cygwin.dll.  The import library is called
93    'libcygwin.a'.  For Windows applications, include more libraries, but
94    always include kernel32.  We'd like to specific subsystem windows to
95    ld, but that doesn't work just yet.  */
96
97 #undef LIB_SPEC
98 #define LIB_SPEC "%{pg:-lgmon} \
99                   %{!mno-cygwin:-lcygwin} \
100                   %{mno-cygwin:-lmingw32 -lmoldname -lcrtdll} \
101                   %{mwindows:-luser32 -lgdi32 -lcomdlg32} \
102                   -lkernel32 -ladvapi32 -lshell32"
103
104 #define LINK_SPEC "%{mwindows:--subsystem windows} \
105                    %{mdll:--dll -e _DllMainCRTStartup@12}"
106
107
108 #define SIZE_TYPE "unsigned int"
109 #define PTRDIFF_TYPE "int"
110 #define WCHAR_UNSIGNED 1
111 #define WCHAR_TYPE_SIZE 16
112 #define WCHAR_TYPE "short unsigned int"
113
114 #define HAVE_ATEXIT 1
115
116 \f
117 /* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop).  */
118 #define HANDLE_PRAGMA_PACK_PUSH_POP 1
119
120 /* A C expression whose value is nonzero if IDENTIFIER with arguments ARGS
121    is a valid machine specific attribute for DECL.
122    The attributes in ATTRIBUTES have previously been assigned to DECL.  */
123 extern int i386_pe_valid_decl_attribute_p ();
124
125 #undef VALID_MACHINE_DECL_ATTRIBUTE
126 #define VALID_MACHINE_DECL_ATTRIBUTE(DECL, ATTRIBUTES, IDENTIFIER, ARGS) \
127   i386_pe_valid_decl_attribute_p (DECL, ATTRIBUTES, IDENTIFIER, ARGS)
128
129 /* A C expression whose value is nonzero if IDENTIFIER with arguments ARGS
130    is a valid machine specific attribute for TYPE.
131    The attributes in ATTRIBUTES have previously been assigned to TYPE.  */
132
133 #undef VALID_MACHINE_TYPE_ATTRIBUTE
134 #define VALID_MACHINE_TYPE_ATTRIBUTE(TYPE, ATTRIBUTES, IDENTIFIER, ARGS) \
135   i386_pe_valid_type_attribute_p (TYPE, ATTRIBUTES, IDENTIFIER, ARGS)
136 extern int i386_pe_valid_type_attribute_p ();
137
138 extern union tree_node *i386_pe_merge_decl_attributes ();
139 #define MERGE_MACHINE_DECL_ATTRIBUTES(OLD, NEW) \
140   i386_pe_merge_decl_attributes ((OLD), (NEW))
141
142 /* Used to implement dllexport overriding dllimport semantics.  It's also used
143    to handle vtables - the first pass won't do anything because
144    DECL_CONTEXT (DECL) will be 0 so i386_pe_dll{ex,im}port_p will return 0.
145    It's also used to handle dllimport override semantics.  */
146 #if 0
147 #define REDO_SECTION_INFO_P(DECL) \
148   ((DECL_MACHINE_ATTRIBUTES (DECL) != NULL_TREE) \
149    || (TREE_CODE (DECL) == VAR_DECL && DECL_VIRTUAL_P (DECL)))
150 #else
151 #define REDO_SECTION_INFO_P(DECL) 1
152 #endif
153
154 \f
155 #undef EXTRA_SECTIONS
156 #define EXTRA_SECTIONS in_ctor, in_dtor, in_drectve
157
158 #undef EXTRA_SECTION_FUNCTIONS
159 #define EXTRA_SECTION_FUNCTIONS                                 \
160   CTOR_SECTION_FUNCTION                                         \
161   DTOR_SECTION_FUNCTION                                         \
162   DRECTVE_SECTION_FUNCTION                                      \
163   SWITCH_TO_SECTION_FUNCTION
164
165 #define CTOR_SECTION_FUNCTION                                   \
166 void                                                            \
167 ctor_section ()                                                 \
168 {                                                               \
169   if (in_section != in_ctor)                                    \
170     {                                                           \
171       fprintf (asm_out_file, "\t.section .ctor\n");             \
172       in_section = in_ctor;                                     \
173     }                                                           \
174 }
175
176 #define DTOR_SECTION_FUNCTION                                   \
177 void                                                            \
178 dtor_section ()                                                 \
179 {                                                               \
180   if (in_section != in_dtor)                                    \
181     {                                                           \
182       fprintf (asm_out_file, "\t.section .dtor\n");             \
183       in_section = in_dtor;                                     \
184     }                                                           \
185 }
186
187 #define DRECTVE_SECTION_FUNCTION \
188 void                                                                    \
189 drectve_section ()                                                      \
190 {                                                                       \
191   if (in_section != in_drectve)                                         \
192     {                                                                   \
193       fprintf (asm_out_file, "%s\n", "\t.section .drectve\n");          \
194       in_section = in_drectve;                                          \
195     }                                                                   \
196 }
197
198 /* Switch to SECTION (an `enum in_section').
199
200    ??? This facility should be provided by GCC proper.
201    The problem is that we want to temporarily switch sections in
202    ASM_DECLARE_OBJECT_NAME and then switch back to the original section
203    afterwards.  */
204 #define SWITCH_TO_SECTION_FUNCTION                              \
205 void                                                            \
206 switch_to_section (section, decl)                               \
207      enum in_section section;                                   \
208      tree decl;                                                 \
209 {                                                               \
210   switch (section)                                              \
211     {                                                           \
212       case in_text: text_section (); break;                     \
213       case in_data: data_section (); break;                     \
214       case in_named: named_section (decl, NULL, 0); break;      \
215       case in_ctor: ctor_section (); break;                     \
216       case in_dtor: dtor_section (); break;                     \
217       case in_drectve: drectve_section (); break;               \
218       default: abort (); break;                                 \
219     }                                                           \
220 }
221
222 #define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME)       \
223   do {                                          \
224     ctor_section ();                            \
225     fprintf (FILE, "%s\t", ASM_LONG);           \
226     assemble_name (FILE, NAME);                 \
227     fprintf (FILE, "\n");                       \
228   } while (0)
229
230 #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME)        \
231   do {                                          \
232     dtor_section ();                            \
233     fprintf (FILE, "%s\t", ASM_LONG);           \
234     assemble_name (FILE, NAME);                 \
235     fprintf (FILE, "\n");                       \
236   } while (0)
237
238 /* Don't allow flag_pic to propagate since gas may produce invalid code
239    otherwise. */
240
241 #undef  SUBTARGET_OVERRIDE_OPTIONS
242 #define SUBTARGET_OVERRIDE_OPTIONS                                      \
243 do {                                                                    \
244   if (flag_pic)                                                         \
245     {                                                                   \
246       warning ("-f%s ignored for target (all code is position independent)",\
247                (flag_pic > 1) ? "PIC" : "pic");                         \
248       flag_pic = 0;                                                     \
249     }                                                                   \
250 } while (0)                                                             \
251
252 /* Define this macro if references to a symbol must be treated
253    differently depending on something about the variable or
254    function named by the symbol (such as what section it is in).
255
256    On i386 running Windows NT, modify the assembler name with a suffix 
257    consisting of an atsign (@) followed by string of digits that represents
258    the number of bytes of arguments passed to the function, if it has the 
259    attribute STDCALL.
260
261    In addition, we must mark dll symbols specially. Definitions of 
262    dllexport'd objects install some info in the .drectve section.  
263    References to dllimport'd objects are fetched indirectly via
264    _imp__.  If both are declared, dllexport overrides.  This is also 
265    needed to implement one-only vtables: they go into their own
266    section and we need to set DECL_SECTION_NAME so we do that here.
267    Note that we can be called twice on the same decl.  */
268
269 extern void i386_pe_encode_section_info ();
270
271 #ifdef ENCODE_SECTION_INFO
272 #undef ENCODE_SECTION_INFO
273 #endif
274 #define ENCODE_SECTION_INFO(DECL) i386_pe_encode_section_info (DECL)
275
276 /* Utility used only in this file.  */
277 #define I386_PE_STRIP_ENCODING(SYM_NAME) \
278   ((SYM_NAME) + ((SYM_NAME)[0] == '@' ? 3 : 0))
279
280 /* This macro gets just the user-specified name
281    out of the string in a SYMBOL_REF.  Discard
282    trailing @[NUM] encoded by ENCODE_SECTION_INFO.  */
283 #undef  STRIP_NAME_ENCODING
284 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME)                            \
285 do {                                                                    \
286   char *_p;                                                             \
287   char *_name = I386_PE_STRIP_ENCODING (SYMBOL_NAME);                   \
288   for (_p = _name; *_p && *_p != '@'; ++_p)                             \
289     ;                                                                   \
290   if (*_p == '@')                                                       \
291     {                                                                   \
292       int _len = _p - _name;                                            \
293       (VAR) = (char *) alloca (_len + 1);                               \
294       strncpy ((VAR), _name, _len);                                     \
295       (VAR)[_len] = '\0';                                               \
296     }                                                                   \
297   else                                                                  \
298     (VAR) = _name;                                                      \
299 } while (0)
300       
301 \f
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))               \
307
308 /* Output a common block.  */
309 #undef ASM_OUTPUT_COMMON
310 #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED)  \
311 do {                                                    \
312   if (i386_pe_dllexport_name_p (NAME))                  \
313     {                                                   \
314       drectve_section ();                               \
315       fprintf ((STREAM), "\t.ascii \" -export:%s\"\n",  \
316                I386_PE_STRIP_ENCODING (NAME));          \
317     }                                                   \
318   if (! i386_pe_dllimport_name_p (NAME))                \
319     {                                                   \
320       fprintf ((STREAM), "\t.comm\t");                  \
321       assemble_name ((STREAM), (NAME));                 \
322       fprintf ((STREAM), ", %d\t%s %d\n",               \
323                (ROUNDED), ASM_COMMENT_START, (SIZE));   \
324     }                                                   \
325 } while (0)
326
327 /* Output the label for an initialized variable.  */
328 #undef ASM_DECLARE_OBJECT_NAME
329 #define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL)     \
330 do {                                                    \
331   if (i386_pe_dllexport_name_p (NAME))                  \
332     {                                                   \
333       enum in_section save_section = in_section;        \
334       drectve_section ();                               \
335       fprintf ((STREAM), "\t.ascii \" -export:%s\"\n",  \
336                I386_PE_STRIP_ENCODING (NAME));          \
337       switch_to_section (save_section, (DECL));         \
338     }                                                   \
339   ASM_OUTPUT_LABEL ((STREAM), (NAME));                  \
340 } while (0)
341
342 \f
343 /* Emit code to check the stack when allocating more that 4000
344    bytes in one go. */
345
346 #define CHECK_STACK_LIMIT 4000
347
348 /* By default, target has a 80387, uses IEEE compatible arithmetic,
349    and returns float values in the 387 and needs stack probes */
350 #undef TARGET_DEFAULT
351
352 #define TARGET_DEFAULT \
353    (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE) 
354
355 /* This is how to output an assembler line
356    that says to advance the location counter
357    to a multiple of 2**LOG bytes.  */
358
359 #undef ASM_OUTPUT_ALIGN
360 #define ASM_OUTPUT_ALIGN(FILE,LOG)      \
361     if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
362
363 /* Define this macro if in some cases global symbols from one translation
364    unit may not be bound to undefined symbols in another translation unit
365    without user intervention.  For instance, under Microsoft Windows
366    symbols must be explicitly imported from shared libraries (DLLs).  */
367 #define MULTIPLE_SYMBOL_SPACES
368
369 #define UNIQUE_SECTION_P(DECL) DECL_ONE_ONLY (DECL)
370 extern void i386_pe_unique_section ();
371 #define UNIQUE_SECTION(DECL,RELOC) i386_pe_unique_section (DECL, RELOC)
372
373 #define SUPPORTS_ONE_ONLY 1
374
375 /* A C statement to output something to the assembler file to switch to section
376    NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or
377    NULL_TREE.  Some target formats do not support arbitrary sections.  Do not
378    define this macro in such cases.  */
379 #undef ASM_OUTPUT_SECTION_NAME
380 #define ASM_OUTPUT_SECTION_NAME(STREAM, DECL, NAME, RELOC)              \
381 do {                                                                    \
382   static struct section_info                                            \
383     {                                                                   \
384       struct section_info *next;                                        \
385       char *name;                                                       \
386       enum sect_enum {SECT_RW, SECT_RO, SECT_EXEC} type;                \
387     } *sections;                                                        \
388   struct section_info *s;                                               \
389   char *mode;                                                           \
390   enum sect_enum type;                                                  \
391                                                                         \
392   for (s = sections; s; s = s->next)                                    \
393     if (!strcmp (NAME, s->name))                                        \
394       break;                                                            \
395                                                                         \
396   if (DECL && TREE_CODE (DECL) == FUNCTION_DECL)                        \
397     type = SECT_EXEC, mode = "x";                                       \
398   else if (DECL && DECL_READONLY_SECTION (DECL, RELOC))                 \
399     type = SECT_RO, mode = "";                                          \
400   else                                                                  \
401     type = SECT_RW, mode = "w";                                         \
402                                                                         \
403   if (s == 0)                                                           \
404     {                                                                   \
405       s = (struct section_info *) xmalloc (sizeof (struct section_info)); \
406       s->name = xmalloc ((strlen (NAME) + 1) * sizeof (*NAME));         \
407       strcpy (s->name, NAME);                                           \
408       s->type = type;                                                   \
409       s->next = sections;                                               \
410       sections = s;                                                     \
411       fprintf (STREAM, ".section\t%s,\"%s\"\n", NAME, mode);            \
412       /* Functions may have been compiled at various levels of          \
413          optimization so we can't use `same_size' here.  Instead,       \
414          have the linker pick one.  */                                  \
415       if ((DECL) && DECL_ONE_ONLY (DECL))                               \
416         fprintf (STREAM, "\t.linkonce %s\n",                            \
417                  TREE_CODE (DECL) == FUNCTION_DECL                      \
418                  ? "discard" : "same_size");                            \
419     }                                                                   \
420   else                                                                  \
421     {                                                                   \
422       fprintf (STREAM, ".section\t%s,\"%s\"\n", NAME, mode);            \
423     }                                                                   \
424 } while (0)
425
426 /* Write the extra assembler code needed to declare a function
427    properly.  If we are generating SDB debugging information, this
428    will happen automatically, so we only need to handle other cases.  */
429 #undef ASM_DECLARE_FUNCTION_NAME
430 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)                     \
431   do                                                                    \
432     {                                                                   \
433       if (i386_pe_dllexport_name_p (NAME))                              \
434         {                                                               \
435           drectve_section ();                                           \
436           fprintf ((FILE), "\t.ascii \" -export:%s\"\n",                \
437                    I386_PE_STRIP_ENCODING (NAME));                      \
438           function_section (DECL);                                      \
439         }                                                               \
440       if (write_symbols != SDB_DEBUG)                                   \
441         i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL)); \
442       ASM_OUTPUT_LABEL (FILE, NAME);                                    \
443     }                                                                   \
444   while (0)
445
446 /* Add an external function to the list of functions to be declared at
447    the end of the file.  */
448 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)                           \
449   do                                                                    \
450     {                                                                   \
451       if (TREE_CODE (DECL) == FUNCTION_DECL)                            \
452         i386_pe_record_external_function (NAME);                        \
453     }                                                                   \
454   while (0)
455
456 /* Declare the type properly for any external libcall.  */
457 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
458   i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
459
460 /* Output function declarations at the end of the file.  */
461 #define ASM_FILE_END(FILE) \
462   i386_pe_asm_file_end (FILE)
463
464 #undef ASM_COMMENT_START
465 #define ASM_COMMENT_START " #"
466
467 /* DWARF2 Unwinding doesn't work with exception handling yet. */
468 #define DWARF2_UNWIND_INFO 0
469
470 /* Don't assume anything about the header files. */
471 #define NO_IMPLICIT_EXTERN_C
472
473 #define SUBTARGET_PROLOGUE                                              \
474   if (profile_flag                                                      \
475       && strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),\
476                  "main") == 0)                                          \
477      {                                                                  \
478       rtx xops[1];                                                      \
479       xops[0] = gen_rtx_MEM (FUNCTION_MODE,                             \
480                          gen_rtx (SYMBOL_REF, Pmode, "_monstartup"));   \
481       if (do_rtl)                                                       \
482         emit_call_insn (gen_rtx (CALL, VOIDmode, xops[0], const0_rtx)); \
483       else                                                              \
484         output_asm_insn (AS1 (call,%P1), xops);                 \
485      }
486
487 /* External function declarations.  */
488
489 #ifndef PROTO
490 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
491 #define PROTO(ARGS) ARGS
492 #else
493 #define PROTO(ARGS) ()
494 #endif
495 #endif
496
497 #ifdef BUFSIZ           /* stdio.h has been included, ok to use FILE * */
498 #define STDIO_PROTO(ARGS) PROTO(ARGS)
499 #else
500 #define STDIO_PROTO(ARGS) ()
501 #endif
502
503 extern void i386_pe_record_external_function PROTO((char *));
504 extern void i386_pe_declare_function_type STDIO_PROTO((FILE *, char *, int));
505 extern void i386_pe_asm_file_end STDIO_PROTO((FILE *));
506
507 /* For Win32 ABI compatibility */
508 #undef DEFAULT_PCC_STRUCT_RETURN
509 #define DEFAULT_PCC_STRUCT_RETURN 0
510
511 /* No data type wants to be aligned rounder than this.  */
512 #undef  BIGGEST_ALIGNMENT
513 #define BIGGEST_ALIGNMENT 128
514
515 /* A bitfield declared as `int' forces `int' alignment for the struct.  */
516 #undef PCC_BITFIELDS_TYPE_MATTERS
517 #define PCC_BITFIELDS_TYPE_MATTERS 0
518