OSDN Git Service

18499801fe1eac3a35af65e5bdad1f50321dc143
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / cygwin32.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 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 /* Support the __declspec keyword by turning them into attributes.
34    We currently only support: dllimport and dllexport.
35    Note that the current way we do this may result in a collision with
36    predefined attributes later on.  This can be solved by using one attribute,
37    say __declspec__, and passing args to it.  The problem with that approach
38    is that args are not accumulated: each new appearance would clobber any
39    existing args.  */
40
41 #ifdef CPP_PREDEFINES
42 #undef CPP_PREDEFINES
43 #endif
44
45 #define CPP_PREDEFINES "-Di386 -D_WIN32 \
46   -D__CYGWIN32__ -DWINNT  -D_X86_=1 -D__STDC__=1\
47   -D__stdcall=__attribute__((__stdcall__)) \
48   -D__cdecl=__attribute__((__cdecl__)) \
49   -D__declspec(x)=__attribute__((x)) \
50   -Asystem(winnt) -Acpu(i386) -Amachine(i386)"
51
52 #undef CPP_SPEC
53 #define CPP_SPEC "-remap %(cpp_cpu) %[cpp_cpu] %{posix:-D_POSIX_SOURCE}"
54
55 /* We have to dynamic link to get to the system DLLs.  All of libc, libm and
56    the Unix stuff is in cygwin.dll.  The import library is called
57    'libcygwin.a'.  For Windows applications, include more libraries, but
58    always include kernel32.  We'd like to specific subsystem windows to
59    ld, but that doesn't work just yet.  */
60
61 #undef LIB_SPEC
62 #define LIB_SPEC "-lcygwin %{mwindows:-luser32 -lgdi32 -lcomdlg32} -lkernel32 \
63   -ladvapi32 -lshell32"
64
65 #define LINK_SPEC "%{mwindows:--subsystem windows}"
66
67 /* Normally, -lgcc is not needed since everything in it is in the DLL, but we
68    want to allow things to be added to it when installing new versions of
69    GCC without making a new CYGWIN.DLL, so we leave it.  */
70
71 #undef STARTFILE_SPEC
72 #define STARTFILE_SPEC "crt0%O%s"
73
74 #define SIZE_TYPE "unsigned int"
75 #define PTRDIFF_TYPE "int"
76 #define WCHAR_UNSIGNED 1
77 #define WCHAR_TYPE_SIZE 16
78 #define WCHAR_TYPE "short unsigned int"
79 #define HAVE_ATEXIT 1
80
81 \f
82 /* Ignore dllimport for functions.  */
83 #define TARGET_NOP_FUN_DLLIMPORT (target_flags & 0x20000)
84
85 #undef SUBTARGET_SWITCHES
86 #define SUBTARGET_SWITCHES                      \
87   { "nop-fun-dllimport",         0x20000 },     \
88   { "no-nop-fun-dllimport",     -0x20000 },     \
89   { "windows",                   0x0     },
90
91 /* A C expression whose value is nonzero if IDENTIFIER with arguments ARGS
92    is a valid machine specific attribute for DECL.
93    The attributes in ATTRIBUTES have previously been assigned to DECL.  */
94 extern int i386_pe_valid_decl_attribute_p ();
95
96 #undef VALID_MACHINE_DECL_ATTRIBUTE
97 #define VALID_MACHINE_DECL_ATTRIBUTE(DECL, ATTRIBUTES, IDENTIFIER, ARGS) \
98   i386_pe_valid_decl_attribute_p (DECL, ATTRIBUTES, IDENTIFIER, ARGS)
99
100 extern union tree_node *i386_pe_merge_decl_attributes ();
101 #define MERGE_MACHINE_DECL_ATTRIBUTES(OLD, NEW) \
102   i386_pe_merge_decl_attributes ((OLD), (NEW))
103
104 /* Used to implement dllexport overriding dllimport semantics.  It's also used
105    to handle vtables - the first pass won't do anything because
106    DECL_CONTEXT (DECL) will be 0 so i386_pe_dll{ex,im}port_p will return 0.
107    It's also used to handle dllimport override semantics.  */
108 #if 0
109 #define REDO_SECTION_INFO_P(DECL) \
110   ((DECL_MACHINE_ATTRIBUTES (DECL) != NULL_TREE) \
111    || (TREE_CODE (DECL) == VAR_DECL && DECL_VIRTUAL_P (DECL)))
112 #else
113 #define REDO_SECTION_INFO_P(DECL) 1
114 #endif
115
116 \f
117 #undef EXTRA_SECTIONS
118 #define EXTRA_SECTIONS in_ctor, in_dtor, in_drectve
119
120 #undef EXTRA_SECTION_FUNCTIONS
121 #define EXTRA_SECTION_FUNCTIONS                                 \
122   CTOR_SECTION_FUNCTION                                         \
123   DTOR_SECTION_FUNCTION                                         \
124   DRECTVE_SECTION_FUNCTION                                      \
125   SWITCH_TO_SECTION_FUNCTION
126
127 #define CTOR_SECTION_FUNCTION                                   \
128 void                                                            \
129 ctor_section ()                                                 \
130 {                                                               \
131   if (in_section != in_ctor)                                    \
132     {                                                           \
133       fprintf (asm_out_file, "\t.section .ctor\n");             \
134       in_section = in_ctor;                                     \
135     }                                                           \
136 }
137
138 #define DTOR_SECTION_FUNCTION                                   \
139 void                                                            \
140 dtor_section ()                                                 \
141 {                                                               \
142   if (in_section != in_dtor)                                    \
143     {                                                           \
144       fprintf (asm_out_file, "\t.section .dtor\n");             \
145       in_section = in_dtor;                                     \
146     }                                                           \
147 }
148
149 #define DRECTVE_SECTION_FUNCTION \
150 void                                                                    \
151 drectve_section ()                                                      \
152 {                                                                       \
153   if (in_section != in_drectve)                                         \
154     {                                                                   \
155       fprintf (asm_out_file, "%s\n", "\t.section .drectve\n");          \
156       in_section = in_drectve;                                          \
157     }                                                                   \
158 }
159
160 /* Switch to SECTION (an `enum in_section').
161
162    ??? This facility should be provided by GCC proper.
163    The problem is that we want to temporarily switch sections in
164    ASM_DECLARE_OBJECT_NAME and then switch back to the original section
165    afterwards.  */
166 #define SWITCH_TO_SECTION_FUNCTION                              \
167 void                                                            \
168 switch_to_section (section, decl)                               \
169      enum in_section section;                                   \
170      tree decl;                                                 \
171 {                                                               \
172   switch (section)                                              \
173     {                                                           \
174       case in_text: text_section (); break;                     \
175       case in_data: data_section (); break;                     \
176       case in_named: named_section (decl, NULL, 0); break;      \
177       case in_ctor: ctor_section (); break;                     \
178       case in_dtor: dtor_section (); break;                     \
179       case in_drectve: drectve_section (); break;               \
180       default: abort (); break;                                 \
181     }                                                           \
182 }
183
184 #define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME)       \
185   do {                                          \
186     ctor_section ();                            \
187     fprintf (FILE, "%s\t", ASM_LONG);           \
188     assemble_name (FILE, NAME);                 \
189     fprintf (FILE, "\n");                       \
190   } while (0)
191
192 #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME)        \
193   do {                                          \
194     dtor_section ();                            \
195     fprintf (FILE, "%s\t", ASM_LONG);           \
196     assemble_name (FILE, NAME);                 \
197     fprintf (FILE, "\n");                       \
198   } while (0)
199
200 /* Define this macro if references to a symbol must be treated
201    differently depending on something about the variable or
202    function named by the symbol (such as what section it is in).
203
204    On i386 running Windows NT, modify the assembler name with a suffix 
205    consisting of an atsign (@) followed by string of digits that represents
206    the number of bytes of arguments passed to the function, if it has the 
207    attribute STDCALL.
208
209    In addition, we must mark dll symbols specially. Definitions of 
210    dllexport'd objects install some info in the .drectve section.  
211    References to dllimport'd objects are fetched indirectly via
212    _imp__.  If both are declared, dllexport overrides.  This is also 
213    needed to implement one-only vtables: they go into their own
214    section and we need to set DECL_SECTION_NAME so we do that here.
215    Note that we can be called twice on the same decl.  */
216
217 extern void i386_pe_encode_section_info ();
218
219 #ifdef ENCODE_SECTION_INFO
220 #undef ENCODE_SECTION_INFO
221 #endif
222 #define ENCODE_SECTION_INFO(DECL) i386_pe_encode_section_info (DECL)
223
224 /* Utility used only in this file.  */
225 #define I386_PE_STRIP_ENCODING(SYM_NAME) \
226   ((SYM_NAME) + ((SYM_NAME)[0] == '@' ? 3 : 0))
227
228 /* This macro gets just the user-specified name
229    out of the string in a SYMBOL_REF.  Discard
230    trailing @[NUM] encoded by ENCODE_SECTION_INFO.  */
231 #undef  STRIP_NAME_ENCODING
232 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME)                            \
233 do {                                                                    \
234   char *_p;                                                             \
235   char *_name = I386_PE_STRIP_ENCODING (SYMBOL_NAME);                   \
236   for (_p = _name; *_p && *_p != '@'; ++_p)                             \
237     ;                                                                   \
238   if (*_p == '@')                                                       \
239     {                                                                   \
240       int _len = _p - _name;                                            \
241       (VAR) = (char *) alloca (_len + 1);                               \
242       strncpy ((VAR), _name, _len);                                     \
243       (VAR)[_len] = '\0';                                               \
244     }                                                                   \
245   else                                                                  \
246     (VAR) = _name;                                                      \
247 } while (0)
248       
249 \f
250 /* Output a reference to a label.  */
251 #undef ASM_OUTPUT_LABELREF
252 #define ASM_OUTPUT_LABELREF(STREAM, NAME)               \
253   fprintf (STREAM, "%s%s", USER_LABEL_PREFIX,           \
254            I386_PE_STRIP_ENCODING (NAME))               \
255
256 /* Output a common block.  */
257 #undef ASM_OUTPUT_COMMON
258 #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED)  \
259 do {                                                    \
260   if (i386_pe_dllexport_name_p (NAME))                  \
261     {                                                   \
262       drectve_section ();                               \
263       fprintf ((STREAM), "\t.ascii \" -export:%s\"\n",  \
264                I386_PE_STRIP_ENCODING (NAME));          \
265     }                                                   \
266   if (! i386_pe_dllimport_name_p (NAME))                \
267     {                                                   \
268       fprintf ((STREAM), "\t.comm\t");                  \
269       assemble_name ((STREAM), (NAME));                 \
270       fprintf ((STREAM), ", %d\t%s %d\n",               \
271                (ROUNDED), ASM_COMMENT_START, (SIZE));   \
272     }                                                   \
273 } while (0)
274
275 /* Output the label for an initialized variable.  */
276 #undef ASM_DECLARE_OBJECT_NAME
277 #define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL)     \
278 do {                                                    \
279   if (i386_pe_dllexport_name_p (NAME))                  \
280     {                                                   \
281       enum in_section save_section = in_section;        \
282       drectve_section ();                               \
283       fprintf ((STREAM), "\t.ascii \" -export:%s\"\n",  \
284                I386_PE_STRIP_ENCODING (NAME));          \
285       switch_to_section (save_section, (DECL));         \
286     }                                                   \
287   ASM_OUTPUT_LABEL ((STREAM), (NAME));                  \
288 } while (0)
289
290 \f
291 /* Emit code to check the stack when allocating more that 4000
292    bytes in one go. */
293
294 #define CHECK_STACK_LIMIT 4000
295
296 /* By default, target has a 80387, uses IEEE compatible arithmetic,
297    and returns float values in the 387 and needs stack probes */
298 #undef TARGET_DEFAULT
299
300 #define TARGET_DEFAULT \
301    (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE) 
302
303 /* This is how to output an assembler line
304    that says to advance the location counter
305    to a multiple of 2**LOG bytes.  */
306
307 #undef ASM_OUTPUT_ALIGN
308 #define ASM_OUTPUT_ALIGN(FILE,LOG)      \
309     if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
310
311 /* Define this macro if in some cases global symbols from one translation
312    unit may not be bound to undefined symbols in another translation unit
313    without user intervention.  For instance, under Microsoft Windows
314    symbols must be explicitly imported from shared libraries (DLLs).  */
315 #define MULTIPLE_SYMBOL_SPACES
316
317 #define UNIQUE_SECTION_P(DECL) DECL_ONE_ONLY (DECL)
318 extern void i386_pe_unique_section ();
319 #define UNIQUE_SECTION(DECL,RELOC) i386_pe_unique_section (DECL, RELOC)
320
321 #define SUPPORTS_ONE_ONLY 1
322
323 /* A C statement to output something to the assembler file to switch to section
324    NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or
325    NULL_TREE.  Some target formats do not support arbitrary sections.  Do not
326    define this macro in such cases.  */
327 #undef ASM_OUTPUT_SECTION_NAME
328 #define ASM_OUTPUT_SECTION_NAME(STREAM, DECL, NAME, RELOC)      \
329 do {                                                            \
330   if ((DECL) && TREE_CODE (DECL) == FUNCTION_DECL)              \
331     fprintf (STREAM, "\t.section %s,\"x\"\n", (NAME));          \
332   else if ((DECL) && DECL_READONLY_SECTION (DECL, RELOC))       \
333     fprintf (STREAM, "\t.section %s,\"\"\n", (NAME));           \
334   else                                                          \
335     fprintf (STREAM, "\t.section %s,\"w\"\n", (NAME));          \
336   /* Functions may have been compiled at various levels of      \
337      optimization so we can't use `same_size' here.  Instead,   \
338      have the linker pick one.  */                              \
339   if ((DECL) && DECL_ONE_ONLY (DECL))                           \
340     fprintf (STREAM, "\t.linkonce %s\n",                        \
341              TREE_CODE (DECL) == FUNCTION_DECL                  \
342              ? "discard" : "same_size");                        \
343 } while (0)
344
345 /* Write the extra assembler code needed to declare a function
346    properly.  If we are generating SDB debugging information, this
347    will happen automatically, so we only need to handle other cases.  */
348 #undef ASM_DECLARE_FUNCTION_NAME
349 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)                     \
350   do                                                                    \
351     {                                                                   \
352       if (i386_pe_dllexport_name_p (NAME))                              \
353         {                                                               \
354           drectve_section ();                                           \
355           fprintf ((FILE), "\t.ascii \" -export:%s\"\n",                \
356                    I386_PE_STRIP_ENCODING (NAME));                      \
357           function_section (DECL);                                      \
358         }                                                               \
359       if (write_symbols != SDB_DEBUG)                                   \
360         i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL)); \
361       ASM_OUTPUT_LABEL (FILE, NAME);                                    \
362     }                                                                   \
363   while (0)
364
365 /* Add an external function to the list of functions to be declared at
366    the end of the file.  */
367 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)                           \
368   do                                                                    \
369     {                                                                   \
370       if (TREE_CODE (DECL) == FUNCTION_DECL)                            \
371         i386_pe_record_external_function (NAME);                        \
372     }                                                                   \
373   while (0)
374
375 /* Declare the type properly for any external libcall.  */
376 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
377   i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
378
379 /* Output function declarations at the end of the file.  */
380 #define ASM_FILE_END(FILE) \
381   i386_pe_asm_file_end (FILE)
382
383 #undef ASM_COMMENT_START
384 #define ASM_COMMENT_START " #"
385
386 /* DWARF2 Unwinding doesn't work with exception handling yet. */
387 #define DWARF2_UNWIND_INFO 0
388
389 /* Don't assume anything about the header files. */
390 #define NO_IMPLICIT_EXTERN_C
391
392 /* External function declarations.  */
393
394 #ifndef PROTO
395 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
396 #define PROTO(ARGS) ARGS
397 #else
398 #define PROTO(ARGS) ()
399 #endif
400 #endif
401
402 #ifdef BUFSIZ           /* stdio.h has been included, ok to use FILE * */
403 #define STDIO_PROTO(ARGS) PROTO(ARGS)
404 #else
405 #define STDIO_PROTO(ARGS) ()
406 #endif
407
408 extern void i386_pe_record_external_function PROTO((char *));
409 extern void i386_pe_declare_function_type STDIO_PROTO((FILE *, char *, int));
410 extern void i386_pe_asm_file_end STDIO_PROTO((FILE *));