xref: /openbsd/gnu/usr.bin/gcc/gcc/config/i386/win32.h (revision c87b03e5)
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, 2002
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 /* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop).  */
26 #define HANDLE_PRAGMA_PACK_PUSH_POP 1
27 
28 #define DBX_DEBUGGING_INFO 1
29 #define SDB_DEBUGGING_INFO 1
30 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
31 
32 #include "i386/unix.h"
33 #include "i386/bsd.h"
34 #include "i386/gas.h"
35 #include "dbxcoff.h"
36 
37 /* Augment TARGET_SWITCHES with the cygwin/win32 options.  */
38 #define MASK_WIN32 0x40000000 /* Use -lming32 interface */
39 #define MASK_CYGWIN  0x20000000 /* Use -lcygwin interface */
40 #define MASK_WINDOWS 0x10000000 /* Use windows interface */
41 #define MASK_DLL     0x08000000 /* Use dll interface    */
42 #define MASK_NOP_FUN_DLLIMPORT 0x20000 /* Ignore dllimport for functions */
43 
44 #define TARGET_WIN32             (target_flags & MASK_WIN32)
45 #define TARGET_CYGWIN            (target_flags & MASK_CYGWIN)
46 #define TARGET_WINDOWS           (target_flags & MASK_WINDOWS)
47 #define TARGET_DLL               (target_flags & MASK_DLL)
48 #define TARGET_NOP_FUN_DLLIMPORT (target_flags & MASK_NOP_FUN_DLLIMPORT)
49 
50 #undef  SUBTARGET_SWITCHES
51 #define SUBTARGET_SWITCHES						\
52     { "win32",			MASK_WIN32,				\
53       N_("Use Mingw32 interface") },					\
54     { "cygwin",			MASK_CYGWIN,				\
55       N_("Use Cygwin interface")  },					\
56     { "windows",		MASK_WINDOWS,				\
57       N_("Use bare Windows interface") },				\
58     { "dll",			MASK_DLL,				\
59       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 
64 
65 #define TARGET_OS_CPP_BUILTINS()					\
66   do									\
67     {									\
68 	builtin_define ("_WIN32");					\
69 	builtin_define_std ("WINNT");					\
70 	builtin_define ("_X86_");					\
71 	builtin_define ("__stdcall=__attribute__((__stdcall__))");	\
72 	builtin_define ("__cdecl=__attribute__((__cdecl__))");		\
73 	builtin_assert ("system=winnt");				\
74 	if (TARGET_CYGWIN)						\
75 	  {								\
76 	    builtin_define ("__CYGWIN32__");				\
77 	    builtin_define ("__CYGWIN__");				\
78 	  }								\
79 	else								\
80 	  builtin_define ("__MINGW32__");				\
81     }									\
82   while (0)
83 
84 #undef STARTFILE_SPEC
85 
86 #define STARTFILE_SPEC "%{mdll:dllcrt0%O%s} %{!mdll: %{!mcygwin:mcrt0%O%s} \
87                         %{mcygwin:crt0%O%s} %{pg:gcrt0%O%s}}"
88 
89 #undef CPP_SPEC
90 #define CPP_SPEC "%{posix:-D_POSIX_SOURCE} \
91   %{!mcygwin:-iwithprefixbefore include/mingw32}"
92 
93 /* We have to dynamic link to get to the system DLLs.  All of libc, libm and
94    the Unix stuff is in cygwin.dll.  The import library is called
95    'libcygwin.a'.  For Windows applications, include more libraries, but
96    always include kernel32.  We'd like to specific subsystem windows to
97    ld, but that doesn't work just yet.  */
98 
99 #undef LIB_SPEC
100 #define LIB_SPEC "%{pg:-lgmon}						\
101 		  %{!mcygwin:-lmingw32 -lmoldname -lmsvcrt -lcrtdll}	\
102                   %{mcygwin:-lcygwin} %{mwindows:-luser32 -lgdi32 -lcomdlg32} \
103                   -lkernel32 -ladvapi32 -lshell32"
104 
105 #define LINK_SPEC "%{mwindows:--subsystem windows} \
106   %{mdll:--dll -e _DllMainCRTStartup@12}"
107 
108 #define SIZE_TYPE "unsigned int"
109 #define PTRDIFF_TYPE "int"
110 #define WCHAR_TYPE_SIZE 16
111 #define WCHAR_TYPE "short unsigned int"
112 /* Currently we do not have the atexit() function,
113    so take that from libgcc2.c */
114 
115 #define NEED_ATEXIT 1
116 
117 #undef TARGET_ENCODE_SECTION_INFO
118 #define TARGET_ENCODE_SECTION_INFO  i386_pe_encode_section_info
119 #undef  TARGET_STRIP_NAME_ENCODING
120 #define TARGET_STRIP_NAME_ENCODING  i386_pe_strip_name_encoding_full
121 
122 /* Emit code to check the stack when allocating more that 4000
123    bytes in one go.  */
124 
125 #define CHECK_STACK_LIMIT 4000
126 
127 /* By default, target has a 80387, uses IEEE compatible arithmetic,
128    and returns float values in the 387 and needs stack probes */
129 #undef TARGET_SUBTARGET_DEFAULT
130 
131 #define TARGET_SUBTARGET_DEFAULT \
132    (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE)
133 
134 /* This is how to output an assembler line
135    that says to advance the location counter
136    to a multiple of 2**LOG bytes.  */
137 
138 #undef ASM_OUTPUT_ALIGN
139 #define ASM_OUTPUT_ALIGN(FILE,LOG)	\
140     if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
141 
142 /* Define this macro if in some cases global symbols from one translation
143    unit may not be bound to undefined symbols in another translation unit
144    without user intervention.  For instance, under Microsoft Windows
145    symbols must be explicitly imported from shared libraries (DLLs).  */
146 #define MULTIPLE_SYMBOL_SPACES
147 
148 extern void i386_pe_unique_section PARAMS ((tree, int));
149 #define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
150 
151 #define SUPPORTS_ONE_ONLY 1
152 
153 /* Switch into a generic section.  */
154 #define TARGET_ASM_NAMED_SECTION  i386_pe_asm_named_section
155 
156 /* Select attributes for named sections.  */
157 #define TARGET_SECTION_TYPE_FLAGS  i386_pe_section_type_flags
158 
159 #undef ASM_COMMENT_START
160 #define ASM_COMMENT_START " #"
161 
162 /* Don't assume anything about the header files.  */
163 #define NO_IMPLICIT_EXTERN_C
164 
165 #define SUBTARGET_PROLOGUE						\
166   if (current_function_profile						\
167       && MAIN_NAME_P (DECL_NAME (current_function_decl))		\
168      {									\
169       rtx xops[1];							\
170       xops[0] = gen_rtx_MEM (FUNCTION_MODE,				\
171 			 gen_rtx (SYMBOL_REF, Pmode, "_monstartup"));	\
172       emit_call_insn (gen_rtx (CALL, VOIDmode, xops[0], const0_rtx));	\
173      }
174