cygming.h revision 169690
1119815Smarcel/* Operating system specific defines to be used when targeting GCC for
2119815Smarcel   hosting on Windows32, using a Unix style C library and tools.
3119815Smarcel   Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4119815Smarcel   2004, 2005
5119815Smarcel   Free Software Foundation, Inc.
6119815Smarcel
7119815SmarcelThis file is part of GCC.
8119815Smarcel
9119815SmarcelGCC is free software; you can redistribute it and/or modify
10119815Smarcelit under the terms of the GNU General Public License as published by
11119815Smarcelthe Free Software Foundation; either version 2, or (at your option)
12119815Smarcelany later version.
13119815Smarcel
14119815SmarcelGCC is distributed in the hope that it will be useful,
15119815Smarcelbut WITHOUT ANY WARRANTY; without even the implied warranty of
16119815SmarcelMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17119815SmarcelGNU General Public License for more details.
18119815Smarcel
19119815SmarcelYou should have received a copy of the GNU General Public License
20119815Smarcelalong with GCC; see the file COPYING.  If not, write to
21119815Smarcelthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
22119815SmarcelBoston, MA 02110-1301, USA.  */
23119815Smarcel
24119815Smarcel#define DBX_DEBUGGING_INFO 1
25119815Smarcel#define SDB_DEBUGGING_INFO 1
26119815Smarcel#undef PREFERRED_DEBUGGING_TYPE
27119815Smarcel#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
28119815Smarcel
29119815Smarcel#ifdef HAVE_GAS_PE_SECREL32_RELOC
30119815Smarcel#define DWARF2_DEBUGGING_INFO 1
31119815Smarcel
32119815Smarcel#undef DBX_REGISTER_NUMBER
33119815Smarcel#define DBX_REGISTER_NUMBER(n) (write_symbols == DWARF2_DEBUG   \
34119815Smarcel                                ? svr4_dbx_register_map[n]      \
35119815Smarcel                                : dbx_register_map[n])
36119815Smarcel
37119815Smarcel/* Use section relative relocations for debugging offsets.  Unlike
38119815Smarcel   other targets that fake this by putting the section VMA at 0, PE
39119815Smarcel   won't allow it.  */
40119866Smarcel#define ASM_OUTPUT_DWARF_OFFSET(FILE, SIZE, LABEL, SECTION)	\
41119866Smarcel  do {								\
42119866Smarcel    if (SIZE != 4)						\
43119866Smarcel      abort ();							\
44119866Smarcel								\
45119866Smarcel    fputs ("\t.secrel32\t", FILE);				\
46119866Smarcel    assemble_name (FILE, LABEL);				\
47119815Smarcel  } while (0)
48119815Smarcel#endif
49119815Smarcel
50119815Smarcel#define TARGET_EXECUTABLE_SUFFIX ".exe"
51119815Smarcel
52119815Smarcel#include <stdio.h>
53119815Smarcel
54119815Smarcel#define MAYBE_UWIN_CPP_BUILTINS() /* Nothing.  */
55119815Smarcel
56119815Smarcel#define TARGET_OS_CPP_BUILTINS()					\
57119815Smarcel  do									\
58119815Smarcel    {									\
59119815Smarcel	builtin_define ("_X86_=1");					\
60119815Smarcel	builtin_assert ("system=winnt");				\
61119815Smarcel	builtin_define ("__stdcall=__attribute__((__stdcall__))");	\
62119815Smarcel	builtin_define ("__fastcall=__attribute__((__fastcall__))");	\
63119815Smarcel	builtin_define ("__cdecl=__attribute__((__cdecl__))");		\
64119815Smarcel	if (!flag_iso)							\
65119815Smarcel	  {								\
66119815Smarcel	    builtin_define ("_stdcall=__attribute__((__stdcall__))");	\
67119815Smarcel	    builtin_define ("_fastcall=__attribute__((__fastcall__))");	\
68119815Smarcel	    builtin_define ("_cdecl=__attribute__((__cdecl__))");	\
69119815Smarcel	  }								\
70119815Smarcel	/* Even though linkonce works with static libs, this is needed 	\
71119815Smarcel	    to compare typeinfo symbols across dll boundaries.  */	\
72119815Smarcel	builtin_define ("__GXX_MERGED_TYPEINFO_NAMES=0");		\
73119815Smarcel	MAYBE_UWIN_CPP_BUILTINS ();					\
74119815Smarcel	EXTRA_OS_CPP_BUILTINS ();					\
75119815Smarcel  }									\
76119815Smarcel  while (0)
77119815Smarcel
78120378Snyan/* Get tree.c to declare a target-specific specialization of
79119815Smarcel   merge_decl_attributes.  */
80120376Snyan#define TARGET_DLLIMPORT_DECL_ATTRIBUTES 1
81120381Snyan
82119815Smarcel/* This macro defines names of additional specifications to put in the specs
83119815Smarcel   that can be used in various specifications like CC1_SPEC.  Its definition
84119815Smarcel   is an initializer with a subgrouping for each command option.
85119815Smarcel
86119815Smarcel   Each subgrouping contains a string constant, that defines the
87119815Smarcel   specification name, and a string constant that used by the GCC driver
88119815Smarcel   program.
89119815Smarcel
90119815Smarcel   Do not define this macro if it does not need to do anything.  */
91119815Smarcel
92119815Smarcel#undef  SUBTARGET_EXTRA_SPECS
93119815Smarcel#define SUBTARGET_EXTRA_SPECS						\
94119815Smarcel  { "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
105/* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop).  */
106#define HANDLE_PRAGMA_PACK_PUSH_POP 1
107
108union tree_node;
109#define TREE union tree_node *
110
111#define drectve_section() \
112  (fprintf (asm_out_file, "\t.section .drectve\n"), \
113   in_section = NULL)
114
115/* Older versions of gas don't handle 'r' as data.
116   Explicitly set data flag with 'd'.  */
117#define READONLY_DATA_SECTION_ASM_OP "\t.section .rdata,\"dr\""
118
119/* Don't allow flag_pic to propagate since gas may produce invalid code
120   otherwise.  */
121
122#undef  SUBTARGET_OVERRIDE_OPTIONS
123#define SUBTARGET_OVERRIDE_OPTIONS					\
124do {									\
125  if (flag_pic)								\
126    {									\
127      warning (0, "-f%s ignored for target (all code is position independent)",\
128	       (flag_pic > 1) ? "PIC" : "pic");				\
129      flag_pic = 0;							\
130    }									\
131} while (0)								\
132
133/* Define this macro if references to a symbol must be treated
134   differently depending on something about the variable or
135   function named by the symbol (such as what section it is in).
136
137   On i386 running Windows NT, modify the assembler name with a suffix
138   consisting of an atsign (@) followed by string of digits that represents
139   the number of bytes of arguments passed to the function, if it has the
140   attribute STDCALL.
141
142   In addition, we must mark dll symbols specially. Definitions of
143   dllexport'd objects install some info in the .drectve section.
144   References to dllimport'd objects are fetched indirectly via
145   _imp__.  If both are declared, dllexport overrides.  This is also
146   needed to implement one-only vtables: they go into their own
147   section and we need to set DECL_SECTION_NAME so we do that here.
148   Note that we can be called twice on the same decl.  */
149
150#undef SUBTARGET_ENCODE_SECTION_INFO
151#define SUBTARGET_ENCODE_SECTION_INFO  i386_pe_encode_section_info
152#undef  TARGET_STRIP_NAME_ENCODING
153#define TARGET_STRIP_NAME_ENCODING  i386_pe_strip_name_encoding_full
154
155/* Output a reference to a label.  */
156#undef ASM_OUTPUT_LABELREF
157#define ASM_OUTPUT_LABELREF  i386_pe_output_labelref
158
159#undef  COMMON_ASM_OP
160#define COMMON_ASM_OP	"\t.comm\t"
161
162/* Output a common block.  */
163#undef ASM_OUTPUT_COMMON
164#define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED)	\
165do {							\
166  if (i386_pe_dllexport_name_p (NAME))			\
167    i386_pe_record_exported_symbol (NAME, 1);		\
168  if (! i386_pe_dllimport_name_p (NAME))		\
169    {							\
170      fprintf ((STREAM), "\t.comm\t");			\
171      assemble_name ((STREAM), (NAME));			\
172      fprintf ((STREAM), ", %d\t%s %d\n",		\
173	       (int)(ROUNDED), ASM_COMMENT_START, (int)(SIZE));	\
174    }							\
175} while (0)
176
177/* Output the label for an initialized variable.  */
178#undef ASM_DECLARE_OBJECT_NAME
179#define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL)	\
180do {							\
181  if (i386_pe_dllexport_name_p (NAME))			\
182    i386_pe_record_exported_symbol (NAME, 1);		\
183  ASM_OUTPUT_LABEL ((STREAM), (NAME));			\
184} while (0)
185
186
187/* Emit code to check the stack when allocating more that 4000
188   bytes in one go.  */
189
190#define CHECK_STACK_LIMIT 4000
191
192/* By default, target has a 80387, uses IEEE compatible arithmetic,
193   returns float values in the 387 and needs stack probes.
194   We also align doubles to 64-bits for MSVC default compatibility.  */
195
196#undef TARGET_SUBTARGET_DEFAULT
197#define TARGET_SUBTARGET_DEFAULT \
198   (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE \
199    | MASK_ALIGN_DOUBLE)
200
201/* This is how to output an assembler line
202   that says to advance the location counter
203   to a multiple of 2**LOG bytes.  */
204
205#undef ASM_OUTPUT_ALIGN
206#define ASM_OUTPUT_ALIGN(FILE,LOG)	\
207    if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
208
209/* Windows uses explicit import from shared libraries.  */
210#define MULTIPLE_SYMBOL_SPACES 1
211
212extern void i386_pe_unique_section (TREE, int);
213#define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
214#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
215
216#define SUPPORTS_ONE_ONLY 1
217
218/* Switch into a generic section.  */
219#define TARGET_ASM_NAMED_SECTION  i386_pe_asm_named_section
220
221/* Select attributes for named sections.  */
222#define TARGET_SECTION_TYPE_FLAGS  i386_pe_section_type_flags
223
224/* Write the extra assembler code needed to declare a function
225   properly.  If we are generating SDB debugging information, this
226   will happen automatically, so we only need to handle other cases.  */
227#undef ASM_DECLARE_FUNCTION_NAME
228#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)			\
229  do									\
230    {									\
231      if (i386_pe_dllexport_name_p (NAME))				\
232	i386_pe_record_exported_symbol (NAME, 0);			\
233      if (write_symbols != SDB_DEBUG)					\
234	i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL));	\
235      ASM_OUTPUT_LABEL (FILE, NAME);					\
236    }									\
237  while (0)
238
239/* Add an external function to the list of functions to be declared at
240   the end of the file.  */
241#define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)				\
242  do									\
243    {									\
244      if (TREE_CODE (DECL) == FUNCTION_DECL)				\
245	i386_pe_record_external_function ((DECL), (NAME));		\
246    }									\
247  while (0)
248
249/* Declare the type properly for any external libcall.  */
250#define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
251  i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
252
253/* This says out to put a global symbol in the BSS section.  */
254#undef ASM_OUTPUT_ALIGNED_BSS
255#define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
256  asm_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
257
258/* Output function declarations at the end of the file.  */
259#undef TARGET_ASM_FILE_END
260#define TARGET_ASM_FILE_END i386_pe_file_end
261
262#undef ASM_COMMENT_START
263#define ASM_COMMENT_START " #"
264
265/* DWARF2 Unwinding doesn't work with exception handling yet.  To make
266   it work, we need to build a libgcc_s.dll, and dcrt0.o should be
267   changed to call __register_frame_info/__deregister_frame_info.  */
268#define DWARF2_UNWIND_INFO 0
269
270/* Don't assume anything about the header files.  */
271#define NO_IMPLICIT_EXTERN_C
272
273#undef PROFILE_HOOK
274#define PROFILE_HOOK(LABEL)						\
275  if (MAIN_NAME_P (DECL_NAME (current_function_decl)))			\
276    {									\
277      emit_call_insn (gen_rtx_CALL (VOIDmode,				\
278	gen_rtx_MEM (FUNCTION_MODE,					\
279		     gen_rtx_SYMBOL_REF (Pmode, "_monstartup")),	\
280	const0_rtx));							\
281    }
282
283/* Java Native Interface (JNI) methods on Win32 are invoked using the
284   stdcall calling convention.  */
285#undef MODIFY_JNI_METHOD_CALL
286#define MODIFY_JNI_METHOD_CALL(MDECL)					      \
287  build_type_attribute_variant ((MDECL),				      \
288			       build_tree_list (get_identifier ("stdcall"),   \
289						NULL))
290
291/* External function declarations.  */
292
293extern void i386_pe_record_external_function (tree, const char *);
294extern void i386_pe_declare_function_type (FILE *, const char *, int);
295extern void i386_pe_record_exported_symbol (const char *, int);
296extern void i386_pe_file_end (void);
297extern int i386_pe_dllexport_name_p (const char *);
298extern int i386_pe_dllimport_name_p (const char *);
299
300/* For Win32 ABI compatibility */
301#undef DEFAULT_PCC_STRUCT_RETURN
302#define DEFAULT_PCC_STRUCT_RETURN 0
303
304/* MSVC returns aggregate types of up to 8 bytes via registers.
305   See i386.c:ix86_return_in_memory.  */
306#undef MS_AGGREGATE_RETURN
307#define MS_AGGREGATE_RETURN 1
308
309/* No data type wants to be aligned rounder than this.  */
310#undef	BIGGEST_ALIGNMENT
311#define BIGGEST_ALIGNMENT 128
312
313/* Biggest alignment supported by the object file format of this
314   machine.  Use this macro to limit the alignment which can be
315   specified using the `__attribute__ ((aligned (N)))' construct.  If
316   not defined, the default value is `BIGGEST_ALIGNMENT'.  */
317#undef MAX_OFILE_ALIGNMENT
318/* IMAGE_SCN_ALIGN_8192BYTES is the largest section alignment flag
319   specified in the PECOFF60 spec.  Native MS compiler also limits
320   user-specified alignment to 8192 bytes.  */
321#define MAX_OFILE_ALIGNMENT (8192 * 8)
322
323/* Native complier aligns internal doubles in structures on dword boundaries.  */
324#undef	BIGGEST_FIELD_ALIGNMENT
325#define BIGGEST_FIELD_ALIGNMENT 64
326
327/* A bit-field declared as `int' forces `int' alignment for the struct.  */
328#undef PCC_BITFIELD_TYPE_MATTERS
329#define PCC_BITFIELD_TYPE_MATTERS 1
330#define GROUP_BITFIELDS_BY_ALIGN TYPE_NATIVE(rec)
331
332/* Enable alias attribute support.  */
333#ifndef SET_ASM_OP
334#define SET_ASM_OP "\t.set\t"
335#endif
336/* This implements the `alias' attribute, keeping any stdcall or
337   fastcall decoration.  */
338#undef	ASM_OUTPUT_DEF_FROM_DECLS
339#define	ASM_OUTPUT_DEF_FROM_DECLS(STREAM, DECL, TARGET) 		\
340  do									\
341    {									\
342      const char *alias;						\
343      rtx rtlname = XEXP (DECL_RTL (DECL), 0);				\
344      if (GET_CODE (rtlname) == SYMBOL_REF)				\
345	alias = XSTR (rtlname, 0);					\
346      else								\
347	abort ();							\
348      if (TREE_CODE (DECL) == FUNCTION_DECL)				\
349	i386_pe_declare_function_type (STREAM, alias,			\
350				       TREE_PUBLIC (DECL));		\
351      ASM_OUTPUT_DEF (STREAM, alias, IDENTIFIER_POINTER (TARGET));	\
352    } while (0)
353
354/* GNU as supports weak symbols on PECOFF. */
355#ifdef HAVE_GAS_WEAK
356#define ASM_WEAKEN_LABEL(FILE, NAME)  \
357  do                                  \
358    {                                 \
359      fputs ("\t.weak\t", (FILE));    \
360      assemble_name ((FILE), (NAME)); \
361      fputc ('\n', (FILE));           \
362    }                                 \
363  while (0)
364#endif /* HAVE_GAS_WEAK */
365
366/* FIXME: SUPPORTS_WEAK && TARGET_HAVE_NAMED_SECTIONS is true,
367   but for .jcr section to work we also need crtbegin and crtend
368   objects.  */
369#define TARGET_USE_JCR_SECTION 0
370
371/* Decide whether it is safe to use a local alias for a virtual function
372   when constructing thunks.  */
373#undef TARGET_USE_LOCAL_THUNK_ALIAS_P
374#define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) (!DECL_ONE_ONLY (DECL))
375
376#define SUBTARGET_ATTRIBUTE_TABLE \
377  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ \
378  { "selectany", 0, 0, true, false, false, ix86_handle_selectany_attribute }
379
380/*  mcount() does not need a counter variable.  */
381#undef NO_PROFILE_COUNTERS
382#define NO_PROFILE_COUNTERS 1
383
384#define TARGET_VALID_DLLIMPORT_ATTRIBUTE_P i386_pe_valid_dllimport_attribute_p
385#define TARGET_CXX_ADJUST_CLASS_AT_DEFINITION i386_pe_adjust_class_at_definition
386
387#undef TREE
388
389#ifndef BUFSIZ
390# undef FILE
391#endif
392