OSDN Git Service

PR middle-end/21275
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / cygming.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, 2003,
4    2004, 2005
5    Free Software Foundation, Inc.
6
7 This file is part of GCC.
8
9 GCC 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 GCC 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 GCC; see the file COPYING.  If not, write to
21 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.  */
23
24 #define DBX_DEBUGGING_INFO 1
25 #define SDB_DEBUGGING_INFO 1
26 #undef PREFERRED_DEBUGGING_TYPE
27 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
28
29 #ifdef HAVE_GAS_PE_SECREL32_RELOC
30 #define DWARF2_DEBUGGING_INFO 1
31
32 #undef DBX_REGISTER_NUMBER
33 #define DBX_REGISTER_NUMBER(n) (write_symbols == DWARF2_DEBUG   \
34                                 ? svr4_dbx_register_map[n]      \
35                                 : dbx_register_map[n])
36
37 /* Use section relative relocations for debugging offsets.  Unlike
38    other targets that fake this by putting the section VMA at 0, PE
39    won't allow it.  */
40 #define ASM_OUTPUT_DWARF_OFFSET(FILE, SIZE, LABEL)    \
41   do {                                                \
42     if (SIZE != 4)                                    \
43       abort ();                                       \
44                                                       \
45     fputs ("\t.secrel32\t", FILE);                    \
46     assemble_name (FILE, LABEL);                      \
47   } while (0)
48 #endif
49
50 #define TARGET_EXECUTABLE_SUFFIX ".exe"
51
52 #include <stdio.h>
53
54 #define MAYBE_UWIN_CPP_BUILTINS() /* Nothing.  */
55
56 #define TARGET_OS_CPP_BUILTINS()                                        \
57   do                                                                    \
58     {                                                                   \
59         builtin_define ("_X86_=1");                                     \
60         builtin_assert ("system=winnt");                                \
61         builtin_define ("__stdcall=__attribute__((__stdcall__))");      \
62         builtin_define ("__fastcall=__attribute__((__fastcall__))");    \
63         builtin_define ("__cdecl=__attribute__((__cdecl__))");          \
64         if (!flag_iso)                                                  \
65           {                                                             \
66             builtin_define ("_stdcall=__attribute__((__stdcall__))");   \
67             builtin_define ("_fastcall=__attribute__((__fastcall__))"); \
68             builtin_define ("_cdecl=__attribute__((__cdecl__))");       \
69           }                                                             \
70         /* Even though linkonce works with static libs, this is needed  \
71             to compare typeinfo symbols across dll boundaries.  */      \
72         builtin_define ("__GXX_MERGED_TYPEINFO_NAMES=0");               \
73         MAYBE_UWIN_CPP_BUILTINS ();                                     \
74         EXTRA_OS_CPP_BUILTINS ();                                       \
75   }                                                                     \
76   while (0)
77
78 /* Get tree.c to declare a target-specific specialization of
79    merge_decl_attributes.  */
80 #define TARGET_DLLIMPORT_DECL_ATTRIBUTES 1
81
82 /* This macro defines names of additional specifications to put in the specs
83    that can be used in various specifications like CC1_SPEC.  Its definition
84    is an initializer with a subgrouping for each command option.
85
86    Each subgrouping contains a string constant, that defines the
87    specification name, and a string constant that used by the GCC driver
88    program.
89
90    Do not define this macro if it does not need to do anything.  */
91
92 #undef  SUBTARGET_EXTRA_SPECS
93 #define SUBTARGET_EXTRA_SPECS                                           \
94   { "mingw_include_path", DEFAULT_TARGET_MACHINE }
95
96 #undef MATH_LIBRARY
97 #define MATH_LIBRARY ""
98
99 #define SIZE_TYPE "unsigned int"
100 #define PTRDIFF_TYPE "int"
101 #define WCHAR_TYPE_SIZE 16
102 #define WCHAR_TYPE "short unsigned int"
103
104 \f
105 /* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop).  */
106 #define HANDLE_PRAGMA_PACK_PUSH_POP 1
107
108 union tree_node;
109 #define TREE union tree_node *
110 \f
111 #undef EXTRA_SECTIONS
112 #define EXTRA_SECTIONS in_drectve
113
114 #undef EXTRA_SECTION_FUNCTIONS
115 #define EXTRA_SECTION_FUNCTIONS                                 \
116   DRECTVE_SECTION_FUNCTION                                      \
117   SWITCH_TO_SECTION_FUNCTION
118
119 #define DRECTVE_SECTION_FUNCTION \
120 void                                                                    \
121 drectve_section (void)                                                  \
122 {                                                                       \
123   if (in_section != in_drectve)                                         \
124     {                                                                   \
125       fprintf (asm_out_file, "%s\n", "\t.section .drectve\n");          \
126       in_section = in_drectve;                                          \
127     }                                                                   \
128 }
129 void drectve_section (void);
130
131 /* Older versions of gas don't handle 'r' as data.
132    Explicitly set data flag with 'd'.  */  
133 #define READONLY_DATA_SECTION_ASM_OP "\t.section .rdata,\"dr\""
134
135 /* Switch to SECTION (an `enum in_section').
136
137    ??? This facility should be provided by GCC proper.
138    The problem is that we want to temporarily switch sections in
139    ASM_DECLARE_OBJECT_NAME and then switch back to the original section
140    afterwards.  */
141 #define SWITCH_TO_SECTION_FUNCTION                              \
142 void switch_to_section (enum in_section, tree);                 \
143 void                                                            \
144 switch_to_section (enum in_section section, tree decl)          \
145 {                                                               \
146   switch (section)                                              \
147     {                                                           \
148       case in_text: text_section (); break;                     \
149       case in_unlikely_executed_text: unlikely_text_section (); break; \
150       case in_data: data_section (); break;                     \
151       case in_readonly_data: readonly_data_section (); break;   \
152       case in_named: named_section (decl, NULL, 0); break;      \
153       case in_drectve: drectve_section (); break;               \
154       default: abort (); break;                         \
155     }                                                           \
156 }
157
158 /* Don't allow flag_pic to propagate since gas may produce invalid code
159    otherwise.  */
160
161 #undef  SUBTARGET_OVERRIDE_OPTIONS
162 #define SUBTARGET_OVERRIDE_OPTIONS                                      \
163 do {                                                                    \
164   if (flag_pic)                                                         \
165     {                                                                   \
166       warning (0, "-f%s ignored for target (all code is position independent)",\
167                (flag_pic > 1) ? "PIC" : "pic");                         \
168       flag_pic = 0;                                                     \
169     }                                                                   \
170 } while (0)                                                             \
171
172 /* Define this macro if references to a symbol must be treated
173    differently depending on something about the variable or
174    function named by the symbol (such as what section it is in).
175
176    On i386 running Windows NT, modify the assembler name with a suffix
177    consisting of an atsign (@) followed by string of digits that represents
178    the number of bytes of arguments passed to the function, if it has the
179    attribute STDCALL.
180
181    In addition, we must mark dll symbols specially. Definitions of
182    dllexport'd objects install some info in the .drectve section.
183    References to dllimport'd objects are fetched indirectly via
184    _imp__.  If both are declared, dllexport overrides.  This is also
185    needed to implement one-only vtables: they go into their own
186    section and we need to set DECL_SECTION_NAME so we do that here.
187    Note that we can be called twice on the same decl.  */
188
189 #undef SUBTARGET_ENCODE_SECTION_INFO
190 #define SUBTARGET_ENCODE_SECTION_INFO  i386_pe_encode_section_info
191 #undef  TARGET_STRIP_NAME_ENCODING
192 #define TARGET_STRIP_NAME_ENCODING  i386_pe_strip_name_encoding_full
193 \f
194 /* Output a reference to a label.  */
195 #undef ASM_OUTPUT_LABELREF
196 #define ASM_OUTPUT_LABELREF  i386_pe_output_labelref
197
198 #undef  COMMON_ASM_OP
199 #define COMMON_ASM_OP   "\t.comm\t"
200
201 /* Output a common block.  */
202 #undef ASM_OUTPUT_COMMON
203 #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED)  \
204 do {                                                    \
205   if (i386_pe_dllexport_name_p (NAME))                  \
206     i386_pe_record_exported_symbol (NAME, 1);           \
207   if (! i386_pe_dllimport_name_p (NAME))                \
208     {                                                   \
209       fprintf ((STREAM), "\t.comm\t");                  \
210       assemble_name ((STREAM), (NAME));                 \
211       fprintf ((STREAM), ", %d\t%s %d\n",               \
212                (int)(ROUNDED), ASM_COMMENT_START, (int)(SIZE)); \
213     }                                                   \
214 } while (0)
215
216 /* Output the label for an initialized variable.  */
217 #undef ASM_DECLARE_OBJECT_NAME
218 #define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL)     \
219 do {                                                    \
220   if (i386_pe_dllexport_name_p (NAME))                  \
221     i386_pe_record_exported_symbol (NAME, 1);           \
222   ASM_OUTPUT_LABEL ((STREAM), (NAME));                  \
223 } while (0)
224
225 \f
226 /* Emit code to check the stack when allocating more that 4000
227    bytes in one go.  */
228
229 #define CHECK_STACK_LIMIT 4000
230
231 /* By default, target has a 80387, uses IEEE compatible arithmetic,
232    returns float values in the 387 and needs stack probes.
233    We also align doubles to 64-bits for MSVC default compatibility.  */
234
235 #undef TARGET_SUBTARGET_DEFAULT
236 #define TARGET_SUBTARGET_DEFAULT \
237    (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE \
238     | MASK_ALIGN_DOUBLE)
239
240 /* This is how to output an assembler line
241    that says to advance the location counter
242    to a multiple of 2**LOG bytes.  */
243
244 #undef ASM_OUTPUT_ALIGN
245 #define ASM_OUTPUT_ALIGN(FILE,LOG)      \
246     if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
247
248 /* Windows uses explicit import from shared libraries.  */
249 #define MULTIPLE_SYMBOL_SPACES 1
250
251 extern void i386_pe_unique_section (TREE, int);
252 #define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
253 #define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
254
255 #define SUPPORTS_ONE_ONLY 1
256
257 /* Switch into a generic section.  */
258 #define TARGET_ASM_NAMED_SECTION  i386_pe_asm_named_section
259
260 /* Select attributes for named sections.  */
261 #define TARGET_SECTION_TYPE_FLAGS  i386_pe_section_type_flags
262
263 /* Write the extra assembler code needed to declare a function
264    properly.  If we are generating SDB debugging information, this
265    will happen automatically, so we only need to handle other cases.  */
266 #undef ASM_DECLARE_FUNCTION_NAME
267 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)                     \
268   do                                                                    \
269     {                                                                   \
270       if (i386_pe_dllexport_name_p (NAME))                              \
271         i386_pe_record_exported_symbol (NAME, 0);                       \
272       if (write_symbols != SDB_DEBUG)                                   \
273         i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL)); \
274       ASM_OUTPUT_LABEL (FILE, NAME);                                    \
275     }                                                                   \
276   while (0)
277
278 /* Add an external function to the list of functions to be declared at
279    the end of the file.  */
280 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)                           \
281   do                                                                    \
282     {                                                                   \
283       if (TREE_CODE (DECL) == FUNCTION_DECL)                            \
284         i386_pe_record_external_function ((DECL), (NAME));              \
285     }                                                                   \
286   while (0)
287
288 /* Declare the type properly for any external libcall.  */
289 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
290   i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
291
292 /* This says out to put a global symbol in the BSS section.  */
293 #undef ASM_OUTPUT_ALIGNED_BSS
294 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
295   asm_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
296
297 /* Output function declarations at the end of the file.  */
298 #undef TARGET_ASM_FILE_END
299 #define TARGET_ASM_FILE_END i386_pe_file_end
300
301 #undef ASM_COMMENT_START
302 #define ASM_COMMENT_START " #"
303
304 /* DWARF2 Unwinding doesn't work with exception handling yet.  To make
305    it work, we need to build a libgcc_s.dll, and dcrt0.o should be
306    changed to call __register_frame_info/__deregister_frame_info.  */
307 #define DWARF2_UNWIND_INFO 0
308
309 /* Don't assume anything about the header files.  */
310 #define NO_IMPLICIT_EXTERN_C
311
312 #undef PROFILE_HOOK
313 #define PROFILE_HOOK(LABEL)                                             \
314   if (MAIN_NAME_P (DECL_NAME (current_function_decl)))                  \
315     {                                                                   \
316       emit_call_insn (gen_rtx_CALL (VOIDmode,                           \
317         gen_rtx_MEM (FUNCTION_MODE,                                     \
318                      gen_rtx_SYMBOL_REF (Pmode, "_monstartup")),        \
319         const0_rtx));                                                   \
320     }
321
322 /* Java Native Interface (JNI) methods on Win32 are invoked using the
323    stdcall calling convention.  */
324 #undef MODIFY_JNI_METHOD_CALL
325 #define MODIFY_JNI_METHOD_CALL(MDECL)                                         \
326   build_type_attribute_variant ((MDECL),                                      \
327                                build_tree_list (get_identifier ("stdcall"),   \
328                                                 NULL))
329
330 /* External function declarations.  */
331
332 extern void i386_pe_record_external_function (tree, const char *);
333 extern void i386_pe_declare_function_type (FILE *, const char *, int);
334 extern void i386_pe_record_exported_symbol (const char *, int);
335 extern void i386_pe_file_end (void);
336 extern int i386_pe_dllexport_name_p (const char *);
337 extern int i386_pe_dllimport_name_p (const char *);
338
339 /* For Win32 ABI compatibility */
340 #undef DEFAULT_PCC_STRUCT_RETURN
341 #define DEFAULT_PCC_STRUCT_RETURN 0
342
343 /* MSVC returns aggregate types of up to 8 bytes via registers.
344    See i386.c:ix86_return_in_memory.  */
345 #undef MS_AGGREGATE_RETURN
346 #define MS_AGGREGATE_RETURN 1
347
348 /* No data type wants to be aligned rounder than this.  */
349 #undef  BIGGEST_ALIGNMENT
350 #define BIGGEST_ALIGNMENT 128
351
352 /* Native complier aligns internal doubles in structures on dword boundaries.  */
353 #undef  BIGGEST_FIELD_ALIGNMENT
354 #define BIGGEST_FIELD_ALIGNMENT 64
355
356 /* A bit-field declared as `int' forces `int' alignment for the struct.  */
357 #undef PCC_BITFIELD_TYPE_MATTERS
358 #define PCC_BITFIELD_TYPE_MATTERS 1
359 #define GROUP_BITFIELDS_BY_ALIGN TYPE_NATIVE(rec)
360
361 /* Enable alias attribute support.  */
362 #ifndef SET_ASM_OP
363 #define SET_ASM_OP "\t.set\t"
364 #endif
365 /* This implements the `alias' attribute, keeping any stdcall or
366    fastcall decoration.  */
367 #undef  ASM_OUTPUT_DEF_FROM_DECLS
368 #define ASM_OUTPUT_DEF_FROM_DECLS(STREAM, DECL, TARGET)                 \
369   do                                                                    \
370     {                                                                   \
371       const char *alias;                                                \
372       rtx rtlname = XEXP (DECL_RTL (DECL), 0);                          \
373       if (GET_CODE (rtlname) == SYMBOL_REF)                             \
374         alias = XSTR (rtlname, 0);                                      \
375       else                                                              \
376         abort ();                                                       \
377       if (TREE_CODE (DECL) == FUNCTION_DECL)                            \
378         i386_pe_declare_function_type (STREAM, alias,                   \
379                                        TREE_PUBLIC (DECL));             \
380       ASM_OUTPUT_DEF (STREAM, alias, IDENTIFIER_POINTER (TARGET));      \
381     } while (0)
382
383 /* GNU as supports weak symbols on PECOFF. */
384 #ifdef HAVE_GAS_WEAK
385 #define ASM_WEAKEN_LABEL(FILE, NAME)  \
386   do                                  \
387     {                                 \
388       fputs ("\t.weak\t", (FILE));    \
389       assemble_name ((FILE), (NAME)); \
390       fputc ('\n', (FILE));           \
391     }                                 \
392   while (0)
393 #endif /* HAVE_GAS_WEAK */
394
395 /* FIXME: SUPPORTS_WEAK && TARGET_HAVE_NAMED_SECTIONS is true,
396    but for .jcr section to work we also need crtbegin and crtend
397    objects.  */
398 #define TARGET_USE_JCR_SECTION 0
399
400 /* Decide whether it is safe to use a local alias for a virtual function
401    when constructing thunks.  */
402 #undef TARGET_USE_LOCAL_THUNK_ALIAS_P
403 #define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) (!DECL_ONE_ONLY (DECL))
404
405 #define SUBTARGET_ATTRIBUTE_TABLE \
406   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ \
407   { "selectany", 0, 0, true, false, false, ix86_handle_selectany_attribute }
408
409 /*  mcount() does not need a counter variable.  */
410 #undef NO_PROFILE_COUNTERS
411 #define NO_PROFILE_COUNTERS 1
412
413 #define TARGET_VALID_DLLIMPORT_ATTRIBUTE_P i386_pe_valid_dllimport_attribute_p
414 #define TARGET_CXX_ADJUST_CLASS_AT_DEFINITION i386_pe_adjust_class_at_definition
415
416 #undef TREE
417
418 #ifndef BUFSIZ
419 # undef FILE
420 #endif