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