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