1/* Operating system specific defines to be used when targeting GCC for
2   hosting on Windows32, using GNU tools and the Windows32 API Library.
3   Copyright (C) 1997-2015 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3.  If not see
19<http://www.gnu.org/licenses/>.  */
20
21#undef DEFAULT_ABI
22#define DEFAULT_ABI MS_ABI
23
24/* By default, target has a 80387, uses IEEE compatible arithmetic,
25   returns float values in the 387 and needs stack probes.
26   We also align doubles to 64-bits for MSVC default compatibility.
27   Additionally we enable MS_BITFIELD_LAYOUT by default.  */
28
29#undef TARGET_SUBTARGET_DEFAULT
30#define TARGET_SUBTARGET_DEFAULT \
31	(MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS \
32	 | MASK_STACK_PROBE | MASK_ALIGN_DOUBLE \
33	 | MASK_MS_BITFIELD_LAYOUT)
34
35/* See i386/crtdll.h for an alternative definition. _INTEGRAL_MAX_BITS
36   is for compatibility with native compiler.  */
37#define EXTRA_OS_CPP_BUILTINS()					\
38  do								\
39    {								\
40      builtin_define ("__MSVCRT__");				\
41      builtin_define ("__MINGW32__");			   	\
42      builtin_define ("_WIN32");				\
43      builtin_define_std ("WIN32");				\
44      builtin_define_std ("WINNT");				\
45      builtin_define_with_int_value ("_INTEGRAL_MAX_BITS",	\
46				     TYPE_PRECISION (intmax_type_node));\
47      if (TARGET_64BIT && ix86_abi == MS_ABI)			\
48	{							\
49	  builtin_define ("__MINGW64__");			\
50	  builtin_define_std ("WIN64");				\
51	  builtin_define ("_WIN64");				\
52	}							\
53    }								\
54  while (0)
55
56#ifndef TARGET_USE_PTHREAD_BY_DEFAULT
57#define SPEC_PTHREAD1 "pthread"
58#define SPEC_PTHREAD2 "!no-pthread"
59#else
60#define SPEC_PTHREAD1 "!no-pthread"
61#define SPEC_PTHREAD2 "pthread"
62#endif
63
64#undef SUB_LINK_ENTRY32
65#undef SUB_LINK_ENTRY64
66#define SUB_LINK_ENTRY32 "-e _DllMainCRTStartup@12"
67#if defined(USE_MINGW64_LEADING_UNDERSCORES)
68#define SUB_LINK_ENTRY64 "-e _DllMainCRTStartup"
69#else
70#define SUB_LINK_ENTRY64 "-e DllMainCRTStartup"
71#endif
72
73#undef SUB_LINK_ENTRY
74#if TARGET_64BIT_DEFAULT
75#define SUB_LINK_ENTRY SUB_LINK_ENTRY64
76#else
77#define SUB_LINK_ENTRY SUB_LINK_ENTRY32
78#endif
79
80#undef NATIVE_SYSTEM_HEADER_COMPONENT
81#define NATIVE_SYSTEM_HEADER_COMPONENT "MINGW"
82
83#undef CPP_SPEC
84#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} " \
85		 "%{" SPEC_PTHREAD1 ":-D_REENTRANT} " \
86		 "%{" SPEC_PTHREAD2 ": } "
87
88/* For Windows applications, include more libraries, but always include
89   kernel32.  */
90#undef LIB_SPEC
91#define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \
92		 "%{" SPEC_PTHREAD2 ": } " \
93		 "%{mwindows:-lgdi32 -lcomdlg32} " \
94     "%{fvtable-verify=preinit:-lvtv -lpsapi; \
95        fvtable-verify=std:-lvtv -lpsapi} " \
96                 "-ladvapi32 -lshell32 -luser32 -lkernel32"
97
98/* Weak symbols do not get resolved if using a Windows dll import lib.
99   Make the unwind registration references strong undefs.  */
100#if DWARF2_UNWIND_INFO
101/* DW2-unwind is just available for 32-bit mode.  */
102#if TARGET_64BIT_DEFAULT
103#error DW2 unwind is not available for 64-bit.
104#endif
105#define SHARED_LIBGCC_UNDEFS_SPEC \
106 "%{shared-libgcc: -u ___register_frame_info -u ___deregister_frame_info}"
107#else
108#define SHARED_LIBGCC_UNDEFS_SPEC ""
109#endif
110
111#undef  SUBTARGET_EXTRA_SPECS
112#define SUBTARGET_EXTRA_SPECS						\
113  { "shared_libgcc_undefs", SHARED_LIBGCC_UNDEFS_SPEC }
114
115#define LINK_SPEC "%{mwindows:--subsystem windows} \
116  %{mconsole:--subsystem console} \
117  %{shared: %{mdll: %eshared and mdll are not compatible}} \
118  %{shared: --shared} %{mdll:--dll} \
119  %{static:-Bstatic} %{!static:-Bdynamic} \
120  %{shared|mdll: " SUB_LINK_ENTRY " --enable-auto-image-base} \
121  %(shared_libgcc_undefs)"
122
123/* Include in the mingw32 libraries with libgcc */
124#ifdef ENABLE_SHARED_LIBGCC
125#define SHARED_LIBGCC_SPEC " \
126 %{static|static-libgcc:-lgcc -lgcc_eh} \
127 %{!static: \
128   %{!static-libgcc: \
129     %{!shared: \
130       %{!shared-libgcc:-lgcc -lgcc_eh} \
131       %{shared-libgcc:-lgcc_s -lgcc} \
132      } \
133     %{shared:-lgcc_s -lgcc} \
134    } \
135  } "
136#else
137#define SHARED_LIBGCC_SPEC " -lgcc "
138#endif
139#undef REAL_LIBGCC_SPEC
140#define REAL_LIBGCC_SPEC \
141  "%{mthreads:-lmingwthrd} -lmingw32 \
142   "SHARED_LIBGCC_SPEC" \
143   -lmoldname -lmingwex -lmsvcrt"
144
145#undef STARTFILE_SPEC
146#define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \
147  %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \
148  crtbegin.o%s \
149  %{fvtable-verify=none:%s; \
150    fvtable-verify=preinit:vtv_start.o%s; \
151    fvtable-verify=std:vtv_start.o%s}"
152
153#undef ENDFILE_SPEC
154#define ENDFILE_SPEC \
155  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
156   %{!shared:%:if-exists(default-manifest.o%s)}\
157   %{fvtable-verify=none:%s; \
158    fvtable-verify=preinit:vtv_end.o%s; \
159    fvtable-verify=std:vtv_end.o%s} \
160  crtend.o%s"
161
162/* Override startfile prefix defaults.  */
163#ifndef STANDARD_STARTFILE_PREFIX_1
164#define STANDARD_STARTFILE_PREFIX_1 "/mingw/lib/"
165#endif
166#ifndef STANDARD_STARTFILE_PREFIX_2
167#define STANDARD_STARTFILE_PREFIX_2 ""
168#endif
169
170/* For native mingw-version we need to take care that NATIVE_SYSTEM_HEADER_DIR
171   macro contains POSIX-style path.  See bug 52947.  */
172#undef NATIVE_SYSTEM_HEADER_DIR
173#define NATIVE_SYSTEM_HEADER_DIR "/mingw/include"
174
175/* Output STRING, a string representing a filename, to FILE.
176   We canonicalize it to be in Unix format (backslashes are replaced
177   forward slashes.  */
178#undef OUTPUT_QUOTED_STRING
179#define OUTPUT_QUOTED_STRING(FILE, STRING)               \
180do {						         \
181  const char *_string = (const char *) (STRING);	 \
182  char c;					         \
183						         \
184  putc ('\"', (FILE));				         \
185						         \
186  while ((c = *_string++) != 0)			         \
187    {						         \
188      if (c == '\\')				         \
189	c = '/';				         \
190						         \
191      if (ISPRINT (c))                                   \
192        {                                                \
193          if (c == '\"')			         \
194	    putc ('\\', (FILE));		         \
195          putc (c, (FILE));			         \
196        }                                                \
197      else                                               \
198        fprintf ((FILE), "\\%03o", (unsigned char) c);	 \
199    }						         \
200						         \
201  putc ('\"', (FILE));					 \
202} while (0)
203
204/* Define as short unsigned for compatibility with MS runtime.  */
205#undef WINT_TYPE
206#define WINT_TYPE "short unsigned int"
207
208/* mingw32 uses the  -mthreads option to enable thread support.  */
209#undef GOMP_SELF_SPECS
210#define GOMP_SELF_SPECS "%{fopenacc|fopenmp|ftree-parallelize-loops=*: " \
211			"-mthreads -pthread}"
212#undef GTM_SELF_SPECS
213#define GTM_SELF_SPECS "%{fgnu-tm:-mthreads -pthread}"
214
215/* mingw32 atexit function is safe to use in shared libraries.  Use it
216   to register C++ static destructors.  */
217#define TARGET_CXX_USE_ATEXIT_FOR_CXA_ATEXIT hook_bool_void_true
218
219/* Contains a pointer to type target_ovr_attr defining the target specific
220   overrides of format attributes.  See c-format.h for structure
221   definition.  */
222#undef TARGET_OVERRIDES_FORMAT_ATTRIBUTES
223#define TARGET_OVERRIDES_FORMAT_ATTRIBUTES mingw_format_attribute_overrides
224
225/* Specify the count of elements in TARGET_OVERRIDES_ATTRIBUTE.  */
226#undef TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT
227#define TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT 3
228
229/* Custom initialization for warning -Wpedantic-ms-format for c-format.  */
230#undef TARGET_OVERRIDES_FORMAT_INIT
231#define TARGET_OVERRIDES_FORMAT_INIT msformat_init
232
233/* MS specific format attributes for ms_printf, ms_scanf, ms_strftime.  */
234#undef TARGET_FORMAT_TYPES
235#define TARGET_FORMAT_TYPES mingw_format_attributes
236
237#undef TARGET_N_FORMAT_TYPES
238#define TARGET_N_FORMAT_TYPES 3
239
240/* Let defaults.h definition of TARGET_USE_JCR_SECTION apply. */
241#undef TARGET_USE_JCR_SECTION
242
243#define HAVE_ENABLE_EXECUTE_STACK
244#undef  CHECK_EXECUTE_STACK_ENABLED
245#define CHECK_EXECUTE_STACK_ENABLED flag_setstackexecutable
246
247/* This matches SHLIB_SONAME and SHLIB_SOVERSION in t-cygming. */
248/* This matches SHLIB_SONAME and SHLIB_SOVERSION in t-cygwin. */
249#if DWARF2_UNWIND_INFO
250#define LIBGCC_EH_EXTN "_dw2"
251#else
252#define LIBGCC_EH_EXTN "_sjlj"
253#endif
254#define LIBGCC_SONAME "libgcc_s" LIBGCC_EH_EXTN "-1.dll"
255
256/* We should find a way to not have to update this manually.  */
257#define LIBGCJ_SONAME "libgcj" /*LIBGCC_EH_EXTN*/ "-16.dll"
258