1132718Skan/* Operating system specific defines to be used when targeting GCC for
2132718Skan   hosting on Windows32, using a Unix style C library and tools.
3169689Skan   Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4169689Skan   2004, 2005
5132718Skan   Free Software Foundation, Inc.
6132718Skan
7132718SkanThis file is part of GCC.
8132718Skan
9132718SkanGCC is free software; you can redistribute it and/or modify
10132718Skanit under the terms of the GNU General Public License as published by
11132718Skanthe Free Software Foundation; either version 2, or (at your option)
12132718Skanany later version.
13132718Skan
14132718SkanGCC is distributed in the hope that it will be useful,
15132718Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of
16132718SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17132718SkanGNU General Public License for more details.
18132718Skan
19132718SkanYou should have received a copy of the GNU General Public License
20132718Skanalong with GCC; see the file COPYING.  If not, write to
21169689Skanthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
22169689SkanBoston, MA 02110-1301, USA.  */
23132718Skan
24132718Skan#define DBX_DEBUGGING_INFO 1
25132718Skan#define SDB_DEBUGGING_INFO 1
26132718Skan#undef PREFERRED_DEBUGGING_TYPE
27132718Skan#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
28132718Skan
29169689Skan#ifdef HAVE_GAS_PE_SECREL32_RELOC
30169689Skan#define DWARF2_DEBUGGING_INFO 1
31132718Skan
32169689Skan#undef DBX_REGISTER_NUMBER
33169689Skan#define DBX_REGISTER_NUMBER(n) (write_symbols == DWARF2_DEBUG   \
34169689Skan                                ? svr4_dbx_register_map[n]      \
35169689Skan                                : dbx_register_map[n])
36132718Skan
37169689Skan/* Use section relative relocations for debugging offsets.  Unlike
38169689Skan   other targets that fake this by putting the section VMA at 0, PE
39169689Skan   won't allow it.  */
40169689Skan#define ASM_OUTPUT_DWARF_OFFSET(FILE, SIZE, LABEL, SECTION)	\
41169689Skan  do {								\
42169689Skan    if (SIZE != 4)						\
43169689Skan      abort ();							\
44169689Skan								\
45169689Skan    fputs ("\t.secrel32\t", FILE);				\
46169689Skan    assemble_name (FILE, LABEL);				\
47169689Skan  } while (0)
48169689Skan#endif
49132718Skan
50169689Skan#define TARGET_EXECUTABLE_SUFFIX ".exe"
51132718Skan
52169689Skan#include <stdio.h>
53132718Skan
54132718Skan#define MAYBE_UWIN_CPP_BUILTINS() /* Nothing.  */
55132718Skan
56132718Skan#define TARGET_OS_CPP_BUILTINS()					\
57132718Skan  do									\
58132718Skan    {									\
59132718Skan	builtin_define ("_X86_=1");					\
60132718Skan	builtin_assert ("system=winnt");				\
61132718Skan	builtin_define ("__stdcall=__attribute__((__stdcall__))");	\
62132718Skan	builtin_define ("__fastcall=__attribute__((__fastcall__))");	\
63132718Skan	builtin_define ("__cdecl=__attribute__((__cdecl__))");		\
64132718Skan	if (!flag_iso)							\
65132718Skan	  {								\
66132718Skan	    builtin_define ("_stdcall=__attribute__((__stdcall__))");	\
67132718Skan	    builtin_define ("_fastcall=__attribute__((__fastcall__))");	\
68132718Skan	    builtin_define ("_cdecl=__attribute__((__cdecl__))");	\
69132718Skan	  }								\
70169689Skan	/* Even though linkonce works with static libs, this is needed 	\
71169689Skan	    to compare typeinfo symbols across dll boundaries.  */	\
72169689Skan	builtin_define ("__GXX_MERGED_TYPEINFO_NAMES=0");		\
73132718Skan	MAYBE_UWIN_CPP_BUILTINS ();					\
74132718Skan	EXTRA_OS_CPP_BUILTINS ();					\
75132718Skan  }									\
76132718Skan  while (0)
77132718Skan
78132718Skan/* Get tree.c to declare a target-specific specialization of
79132718Skan   merge_decl_attributes.  */
80169689Skan#define TARGET_DLLIMPORT_DECL_ATTRIBUTES 1
81132718Skan
82132718Skan/* This macro defines names of additional specifications to put in the specs
83132718Skan   that can be used in various specifications like CC1_SPEC.  Its definition
84132718Skan   is an initializer with a subgrouping for each command option.
85132718Skan
86132718Skan   Each subgrouping contains a string constant, that defines the
87132718Skan   specification name, and a string constant that used by the GCC driver
88132718Skan   program.
89132718Skan
90132718Skan   Do not define this macro if it does not need to do anything.  */
91132718Skan
92132718Skan#undef  SUBTARGET_EXTRA_SPECS
93132718Skan#define SUBTARGET_EXTRA_SPECS						\
94132718Skan  { "mingw_include_path", DEFAULT_TARGET_MACHINE }
95132718Skan
96132718Skan#undef MATH_LIBRARY
97132718Skan#define MATH_LIBRARY ""
98132718Skan
99132718Skan#define SIZE_TYPE "unsigned int"
100132718Skan#define PTRDIFF_TYPE "int"
101132718Skan#define WCHAR_TYPE_SIZE 16
102132718Skan#define WCHAR_TYPE "short unsigned int"
103132718Skan
104132718Skan
105132718Skan/* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop).  */
106132718Skan#define HANDLE_PRAGMA_PACK_PUSH_POP 1
107132718Skan
108132718Skanunion tree_node;
109132718Skan#define TREE union tree_node *
110132718Skan
111169689Skan#define drectve_section() \
112169689Skan  (fprintf (asm_out_file, "\t.section .drectve\n"), \
113169689Skan   in_section = NULL)
114132718Skan
115132718Skan/* Older versions of gas don't handle 'r' as data.
116132718Skan   Explicitly set data flag with 'd'.  */
117132718Skan#define READONLY_DATA_SECTION_ASM_OP "\t.section .rdata,\"dr\""
118132718Skan
119132718Skan/* Don't allow flag_pic to propagate since gas may produce invalid code
120132718Skan   otherwise.  */
121132718Skan
122132718Skan#undef  SUBTARGET_OVERRIDE_OPTIONS
123132718Skan#define SUBTARGET_OVERRIDE_OPTIONS					\
124132718Skando {									\
125132718Skan  if (flag_pic)								\
126132718Skan    {									\
127169689Skan      warning (0, "-f%s ignored for target (all code is position independent)",\
128132718Skan	       (flag_pic > 1) ? "PIC" : "pic");				\
129132718Skan      flag_pic = 0;							\
130132718Skan    }									\
131132718Skan} while (0)								\
132132718Skan
133132718Skan/* Define this macro if references to a symbol must be treated
134132718Skan   differently depending on something about the variable or
135132718Skan   function named by the symbol (such as what section it is in).
136132718Skan
137132718Skan   On i386 running Windows NT, modify the assembler name with a suffix
138132718Skan   consisting of an atsign (@) followed by string of digits that represents
139132718Skan   the number of bytes of arguments passed to the function, if it has the
140132718Skan   attribute STDCALL.
141132718Skan
142132718Skan   In addition, we must mark dll symbols specially. Definitions of
143132718Skan   dllexport'd objects install some info in the .drectve section.
144132718Skan   References to dllimport'd objects are fetched indirectly via
145132718Skan   _imp__.  If both are declared, dllexport overrides.  This is also
146132718Skan   needed to implement one-only vtables: they go into their own
147132718Skan   section and we need to set DECL_SECTION_NAME so we do that here.
148132718Skan   Note that we can be called twice on the same decl.  */
149132718Skan
150169689Skan#undef SUBTARGET_ENCODE_SECTION_INFO
151169689Skan#define SUBTARGET_ENCODE_SECTION_INFO  i386_pe_encode_section_info
152132718Skan#undef  TARGET_STRIP_NAME_ENCODING
153132718Skan#define TARGET_STRIP_NAME_ENCODING  i386_pe_strip_name_encoding_full
154132718Skan
155132718Skan/* Output a reference to a label.  */
156132718Skan#undef ASM_OUTPUT_LABELREF
157132718Skan#define ASM_OUTPUT_LABELREF  i386_pe_output_labelref
158132718Skan
159169689Skan#undef  COMMON_ASM_OP
160169689Skan#define COMMON_ASM_OP	"\t.comm\t"
161169689Skan
162132718Skan/* Output a common block.  */
163132718Skan#undef ASM_OUTPUT_COMMON
164132718Skan#define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED)	\
165132718Skando {							\
166132718Skan  if (i386_pe_dllexport_name_p (NAME))			\
167132718Skan    i386_pe_record_exported_symbol (NAME, 1);		\
168132718Skan  if (! i386_pe_dllimport_name_p (NAME))		\
169132718Skan    {							\
170132718Skan      fprintf ((STREAM), "\t.comm\t");			\
171132718Skan      assemble_name ((STREAM), (NAME));			\
172132718Skan      fprintf ((STREAM), ", %d\t%s %d\n",		\
173132718Skan	       (int)(ROUNDED), ASM_COMMENT_START, (int)(SIZE));	\
174132718Skan    }							\
175132718Skan} while (0)
176132718Skan
177132718Skan/* Output the label for an initialized variable.  */
178132718Skan#undef ASM_DECLARE_OBJECT_NAME
179132718Skan#define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL)	\
180132718Skando {							\
181132718Skan  if (i386_pe_dllexport_name_p (NAME))			\
182132718Skan    i386_pe_record_exported_symbol (NAME, 1);		\
183132718Skan  ASM_OUTPUT_LABEL ((STREAM), (NAME));			\
184132718Skan} while (0)
185132718Skan
186132718Skan
187132718Skan/* Emit code to check the stack when allocating more that 4000
188132718Skan   bytes in one go.  */
189132718Skan
190132718Skan#define CHECK_STACK_LIMIT 4000
191132718Skan
192132718Skan/* By default, target has a 80387, uses IEEE compatible arithmetic,
193132718Skan   returns float values in the 387 and needs stack probes.
194132718Skan   We also align doubles to 64-bits for MSVC default compatibility.  */
195132718Skan
196132718Skan#undef TARGET_SUBTARGET_DEFAULT
197132718Skan#define TARGET_SUBTARGET_DEFAULT \
198132718Skan   (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE \
199132718Skan    | MASK_ALIGN_DOUBLE)
200132718Skan
201132718Skan/* This is how to output an assembler line
202132718Skan   that says to advance the location counter
203132718Skan   to a multiple of 2**LOG bytes.  */
204132718Skan
205132718Skan#undef ASM_OUTPUT_ALIGN
206132718Skan#define ASM_OUTPUT_ALIGN(FILE,LOG)	\
207132718Skan    if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
208132718Skan
209169689Skan/* Windows uses explicit import from shared libraries.  */
210169689Skan#define MULTIPLE_SYMBOL_SPACES 1
211132718Skan
212132718Skanextern void i386_pe_unique_section (TREE, int);
213132718Skan#define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
214169689Skan#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
215132718Skan
216132718Skan#define SUPPORTS_ONE_ONLY 1
217132718Skan
218132718Skan/* Switch into a generic section.  */
219132718Skan#define TARGET_ASM_NAMED_SECTION  i386_pe_asm_named_section
220132718Skan
221132718Skan/* Select attributes for named sections.  */
222132718Skan#define TARGET_SECTION_TYPE_FLAGS  i386_pe_section_type_flags
223132718Skan
224132718Skan/* Write the extra assembler code needed to declare a function
225132718Skan   properly.  If we are generating SDB debugging information, this
226132718Skan   will happen automatically, so we only need to handle other cases.  */
227132718Skan#undef ASM_DECLARE_FUNCTION_NAME
228132718Skan#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)			\
229132718Skan  do									\
230132718Skan    {									\
231132718Skan      if (i386_pe_dllexport_name_p (NAME))				\
232132718Skan	i386_pe_record_exported_symbol (NAME, 0);			\
233132718Skan      if (write_symbols != SDB_DEBUG)					\
234132718Skan	i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL));	\
235132718Skan      ASM_OUTPUT_LABEL (FILE, NAME);					\
236132718Skan    }									\
237132718Skan  while (0)
238132718Skan
239132718Skan/* Add an external function to the list of functions to be declared at
240132718Skan   the end of the file.  */
241132718Skan#define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)				\
242132718Skan  do									\
243132718Skan    {									\
244132718Skan      if (TREE_CODE (DECL) == FUNCTION_DECL)				\
245169689Skan	i386_pe_record_external_function ((DECL), (NAME));		\
246132718Skan    }									\
247132718Skan  while (0)
248132718Skan
249132718Skan/* Declare the type properly for any external libcall.  */
250132718Skan#define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
251132718Skan  i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
252132718Skan
253132718Skan/* This says out to put a global symbol in the BSS section.  */
254132718Skan#undef ASM_OUTPUT_ALIGNED_BSS
255132718Skan#define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
256132718Skan  asm_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
257132718Skan
258132718Skan/* Output function declarations at the end of the file.  */
259132718Skan#undef TARGET_ASM_FILE_END
260132718Skan#define TARGET_ASM_FILE_END i386_pe_file_end
261132718Skan
262132718Skan#undef ASM_COMMENT_START
263132718Skan#define ASM_COMMENT_START " #"
264132718Skan
265132718Skan/* DWARF2 Unwinding doesn't work with exception handling yet.  To make
266132718Skan   it work, we need to build a libgcc_s.dll, and dcrt0.o should be
267132718Skan   changed to call __register_frame_info/__deregister_frame_info.  */
268132718Skan#define DWARF2_UNWIND_INFO 0
269132718Skan
270132718Skan/* Don't assume anything about the header files.  */
271132718Skan#define NO_IMPLICIT_EXTERN_C
272132718Skan
273132718Skan#undef PROFILE_HOOK
274132718Skan#define PROFILE_HOOK(LABEL)						\
275132718Skan  if (MAIN_NAME_P (DECL_NAME (current_function_decl)))			\
276132718Skan    {									\
277169689Skan      emit_call_insn (gen_rtx_CALL (VOIDmode,				\
278132718Skan	gen_rtx_MEM (FUNCTION_MODE,					\
279132718Skan		     gen_rtx_SYMBOL_REF (Pmode, "_monstartup")),	\
280132718Skan	const0_rtx));							\
281132718Skan    }
282132718Skan
283132718Skan/* Java Native Interface (JNI) methods on Win32 are invoked using the
284132718Skan   stdcall calling convention.  */
285132718Skan#undef MODIFY_JNI_METHOD_CALL
286132718Skan#define MODIFY_JNI_METHOD_CALL(MDECL)					      \
287132718Skan  build_type_attribute_variant ((MDECL),				      \
288132718Skan			       build_tree_list (get_identifier ("stdcall"),   \
289132718Skan						NULL))
290132718Skan
291132718Skan/* External function declarations.  */
292132718Skan
293169689Skanextern void i386_pe_record_external_function (tree, const char *);
294132718Skanextern void i386_pe_declare_function_type (FILE *, const char *, int);
295132718Skanextern void i386_pe_record_exported_symbol (const char *, int);
296132718Skanextern void i386_pe_file_end (void);
297132718Skanextern int i386_pe_dllexport_name_p (const char *);
298132718Skanextern int i386_pe_dllimport_name_p (const char *);
299132718Skan
300132718Skan/* For Win32 ABI compatibility */
301132718Skan#undef DEFAULT_PCC_STRUCT_RETURN
302132718Skan#define DEFAULT_PCC_STRUCT_RETURN 0
303132718Skan
304132718Skan/* MSVC returns aggregate types of up to 8 bytes via registers.
305132718Skan   See i386.c:ix86_return_in_memory.  */
306132718Skan#undef MS_AGGREGATE_RETURN
307132718Skan#define MS_AGGREGATE_RETURN 1
308132718Skan
309132718Skan/* No data type wants to be aligned rounder than this.  */
310132718Skan#undef	BIGGEST_ALIGNMENT
311132718Skan#define BIGGEST_ALIGNMENT 128
312132718Skan
313169689Skan/* Biggest alignment supported by the object file format of this
314169689Skan   machine.  Use this macro to limit the alignment which can be
315169689Skan   specified using the `__attribute__ ((aligned (N)))' construct.  If
316169689Skan   not defined, the default value is `BIGGEST_ALIGNMENT'.  */
317169689Skan#undef MAX_OFILE_ALIGNMENT
318169689Skan/* IMAGE_SCN_ALIGN_8192BYTES is the largest section alignment flag
319169689Skan   specified in the PECOFF60 spec.  Native MS compiler also limits
320169689Skan   user-specified alignment to 8192 bytes.  */
321169689Skan#define MAX_OFILE_ALIGNMENT (8192 * 8)
322169689Skan
323132718Skan/* Native complier aligns internal doubles in structures on dword boundaries.  */
324132718Skan#undef	BIGGEST_FIELD_ALIGNMENT
325132718Skan#define BIGGEST_FIELD_ALIGNMENT 64
326132718Skan
327132718Skan/* A bit-field declared as `int' forces `int' alignment for the struct.  */
328132718Skan#undef PCC_BITFIELD_TYPE_MATTERS
329132718Skan#define PCC_BITFIELD_TYPE_MATTERS 1
330132718Skan#define GROUP_BITFIELDS_BY_ALIGN TYPE_NATIVE(rec)
331132718Skan
332132718Skan/* Enable alias attribute support.  */
333132718Skan#ifndef SET_ASM_OP
334132718Skan#define SET_ASM_OP "\t.set\t"
335132718Skan#endif
336132718Skan/* This implements the `alias' attribute, keeping any stdcall or
337132718Skan   fastcall decoration.  */
338132718Skan#undef	ASM_OUTPUT_DEF_FROM_DECLS
339132718Skan#define	ASM_OUTPUT_DEF_FROM_DECLS(STREAM, DECL, TARGET) 		\
340132718Skan  do									\
341132718Skan    {									\
342132718Skan      const char *alias;						\
343132718Skan      rtx rtlname = XEXP (DECL_RTL (DECL), 0);				\
344132718Skan      if (GET_CODE (rtlname) == SYMBOL_REF)				\
345132718Skan	alias = XSTR (rtlname, 0);					\
346132718Skan      else								\
347132718Skan	abort ();							\
348132718Skan      if (TREE_CODE (DECL) == FUNCTION_DECL)				\
349132718Skan	i386_pe_declare_function_type (STREAM, alias,			\
350132718Skan				       TREE_PUBLIC (DECL));		\
351132718Skan      ASM_OUTPUT_DEF (STREAM, alias, IDENTIFIER_POINTER (TARGET));	\
352132718Skan    } while (0)
353132718Skan
354169689Skan/* GNU as supports weak symbols on PECOFF. */
355169689Skan#ifdef HAVE_GAS_WEAK
356169689Skan#define ASM_WEAKEN_LABEL(FILE, NAME)  \
357169689Skan  do                                  \
358169689Skan    {                                 \
359169689Skan      fputs ("\t.weak\t", (FILE));    \
360169689Skan      assemble_name ((FILE), (NAME)); \
361169689Skan      fputc ('\n', (FILE));           \
362169689Skan    }                                 \
363169689Skan  while (0)
364169689Skan#endif /* HAVE_GAS_WEAK */
365169689Skan
366169689Skan/* FIXME: SUPPORTS_WEAK && TARGET_HAVE_NAMED_SECTIONS is true,
367169689Skan   but for .jcr section to work we also need crtbegin and crtend
368169689Skan   objects.  */
369169689Skan#define TARGET_USE_JCR_SECTION 0
370169689Skan
371169689Skan/* Decide whether it is safe to use a local alias for a virtual function
372169689Skan   when constructing thunks.  */
373169689Skan#undef TARGET_USE_LOCAL_THUNK_ALIAS_P
374169689Skan#define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) (!DECL_ONE_ONLY (DECL))
375169689Skan
376169689Skan#define SUBTARGET_ATTRIBUTE_TABLE \
377169689Skan  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ \
378169689Skan  { "selectany", 0, 0, true, false, false, ix86_handle_selectany_attribute }
379169689Skan
380169689Skan/*  mcount() does not need a counter variable.  */
381169689Skan#undef NO_PROFILE_COUNTERS
382169689Skan#define NO_PROFILE_COUNTERS 1
383169689Skan
384169689Skan#define TARGET_VALID_DLLIMPORT_ATTRIBUTE_P i386_pe_valid_dllimport_attribute_p
385169689Skan#define TARGET_CXX_ADJUST_CLASS_AT_DEFINITION i386_pe_adjust_class_at_definition
386169689Skan
387132718Skan#undef TREE
388132718Skan
389132718Skan#ifndef BUFSIZ
390132718Skan# undef FILE
391132718Skan#endif
392