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-2022 Free Software Foundation, Inc.
4 
5 This file is part of GCC.
6 
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11 
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along 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 #define EXTRA_TARGET_D_OS_VERSIONS()				\
57   do								\
58     {								\
59       builtin_version ("MinGW");				\
60       if (TARGET_64BIT && ix86_abi == MS_ABI)			\
61 	builtin_version ("Win64");				\
62       else if (!TARGET_64BIT)					\
63 	builtin_version ("Win32");				\
64       builtin_version ("CRuntime_Microsoft");			\
65     }								\
66   while (0)
67 
68 #ifndef TARGET_USE_PTHREAD_BY_DEFAULT
69 #define SPEC_PTHREAD1 "pthread"
70 #define SPEC_PTHREAD2 "!no-pthread"
71 #else
72 #define SPEC_PTHREAD1 "!no-pthread"
73 #define SPEC_PTHREAD2 "pthread"
74 #endif
75 
76 #undef SUB_LINK_ENTRY32
77 #undef SUB_LINK_ENTRY64
78 #define SUB_LINK_ENTRY32 "-e _DllMainCRTStartup@12"
79 #if defined(USE_MINGW64_LEADING_UNDERSCORES)
80 #define SUB_LINK_ENTRY64 "-e _DllMainCRTStartup"
81 #else
82 #define SUB_LINK_ENTRY64 "-e DllMainCRTStartup"
83 #endif
84 
85 #undef SUB_LINK_ENTRY
86 #if TARGET_64BIT_DEFAULT
87 #define SUB_LINK_ENTRY SUB_LINK_ENTRY64
88 #else
89 #define SUB_LINK_ENTRY SUB_LINK_ENTRY32
90 #endif
91 
92 #undef NATIVE_SYSTEM_HEADER_COMPONENT
93 #define NATIVE_SYSTEM_HEADER_COMPONENT "MINGW"
94 
95 #undef CPP_SPEC
96 #define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} " \
97 		 "%{" SPEC_PTHREAD1 ":-D_REENTRANT} " \
98 		 "%{" SPEC_PTHREAD2 ": } "
99 
100 /* For Windows applications, include more libraries, but always include
101    kernel32.  */
102 #undef LIB_SPEC
103 #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \
104 		 "%{" SPEC_PTHREAD2 ": } " \
105 		 "%{mwindows:-lgdi32 -lcomdlg32} " \
106      "%{fvtable-verify=preinit:-lvtv -lpsapi; \
107         fvtable-verify=std:-lvtv -lpsapi} " \
108                  "-ladvapi32 -lshell32 -luser32 -lkernel32"
109 
110 /* Weak symbols do not get resolved if using a Windows dll import lib.
111    Make the unwind registration references strong undefs.  */
112 #if DWARF2_UNWIND_INFO
113 /* DW2-unwind is just available for 32-bit mode.  */
114 #if TARGET_64BIT_DEFAULT
115 #define SHARED_LIBGCC_UNDEFS_SPEC \
116   "%{m32: %{shared-libgcc: -u ___register_frame_info -u ___deregister_frame_info}}"
117 #else
118 #define SHARED_LIBGCC_UNDEFS_SPEC \
119  "%{shared-libgcc: -u ___register_frame_info -u ___deregister_frame_info}"
120 #endif
121 #else
122 #define SHARED_LIBGCC_UNDEFS_SPEC ""
123 #endif
124 
125 #undef  SUBTARGET_EXTRA_SPECS
126 #define SUBTARGET_EXTRA_SPECS						\
127   { "shared_libgcc_undefs", SHARED_LIBGCC_UNDEFS_SPEC }
128 
129 #if ! MINGW_DEFAULT_LARGE_ADDR_AWARE
130 /* This is used without --enable-large-address-aware.  */
131 # define LINK_SPEC_LARGE_ADDR_AWARE ""
132 #elif ! TARGET_BI_ARCH
133 /* This is used on i686-pc-mingw32 with --enable-large-address-aware.  */
134 # define LINK_SPEC_LARGE_ADDR_AWARE \
135   "%{!shared:%{!mdll:--large-address-aware}}"
136 #elif TARGET_64BIT_DEFAULT
137 /* This is used on x86_64-pc-mingw32 with --enable-large-address-aware.
138    ??? It probably doesn't work, because the linker emulation defaults
139    to i386pep, the 64-bit mode that does not support
140    --large-address-aware, and x86_64-pc-mingw32 does not override the
141    emulation to i386pe for -m32, unlike x86_64-w64-mingw32.  */
142 # define LINK_SPEC_LARGE_ADDR_AWARE \
143   "%{!shared:%{!mdll:%{m32:--large-address-aware}}}"
144 #else
145 /* This would only be used if someone introduced a biarch
146    configuration that defaulted to 32-bit.  */
147 # define LINK_SPEC_LARGE_ADDR_AWARE \
148   "%{!shared:%{!mdll:%{!m64:--large-address-aware}}}"
149 #endif
150 
151 #if HAVE_LD_PE_DISABLE_DYNAMICBASE
152 # define LINK_SPEC_DISABLE_DYNAMICBASE \
153   "%{!shared:%{!mdll:%{no-pie:--disable-dynamicbase}}}"
154 #else
155 # define LINK_SPEC_DISABLE_DYNAMICBASE ""
156 #endif
157 
158 #define LINK_SPEC "%{mwindows:--subsystem windows} \
159   %{mconsole:--subsystem console} \
160   %{shared: %{mdll: %eshared and mdll are not compatible}} \
161   %{shared: --shared} %{mdll:--dll} \
162   %{static:-Bstatic} %{!static:-Bdynamic} \
163   %{shared|mdll: " SUB_LINK_ENTRY " --enable-auto-image-base} \
164   " LINK_SPEC_LARGE_ADDR_AWARE "\
165   " LINK_SPEC_DISABLE_DYNAMICBASE "\
166   %(shared_libgcc_undefs)"
167 
168 /* Include in the mingw32 libraries with libgcc */
169 #ifdef ENABLE_SHARED_LIBGCC
170 #define SHARED_LIBGCC_SPEC " \
171  %{static|static-libgcc:-lgcc -lgcc_eh} \
172  %{!static: \
173    %{!static-libgcc: \
174      %{!shared: \
175        %{!shared-libgcc:-lgcc -lgcc_eh} \
176        %{shared-libgcc:-lgcc_s -lgcc} \
177       } \
178      %{shared:-lgcc_s -lgcc} \
179     } \
180   } "
181 #else
182 #define SHARED_LIBGCC_SPEC " -lgcc "
183 #endif
184 #undef REAL_LIBGCC_SPEC
185 #define REAL_LIBGCC_SPEC \
186   "%{mthreads:-lmingwthrd} -lmingw32 \
187    " SHARED_LIBGCC_SPEC " \
188    -lmoldname -lmingwex -lmsvcrt -lkernel32"
189 
190 #undef STARTFILE_SPEC
191 #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \
192   %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \
193   crtbegin.o%s \
194   %{fvtable-verify=none:%s; \
195     fvtable-verify=preinit:vtv_start.o%s; \
196     fvtable-verify=std:vtv_start.o%s}"
197 
198 #undef ENDFILE_SPEC
199 #define ENDFILE_SPEC \
200   "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
201    %{!shared:%:if-exists(default-manifest.o%s)}\
202    %{fvtable-verify=none:%s; \
203     fvtable-verify=preinit:vtv_end.o%s; \
204     fvtable-verify=std:vtv_end.o%s} \
205   crtend.o%s"
206 
207 /* Override startfile prefix defaults.  */
208 #ifndef STANDARD_STARTFILE_PREFIX_1
209 #define STANDARD_STARTFILE_PREFIX_1 "/mingw/lib/"
210 #endif
211 #ifndef STANDARD_STARTFILE_PREFIX_2
212 #define STANDARD_STARTFILE_PREFIX_2 ""
213 #endif
214 
215 /* For native mingw-version we need to take care that NATIVE_SYSTEM_HEADER_DIR
216    macro contains POSIX-style path.  See bug 52947.  */
217 #undef NATIVE_SYSTEM_HEADER_DIR
218 #define NATIVE_SYSTEM_HEADER_DIR "/mingw/include"
219 
220 /* Output STRING, a string representing a filename, to FILE.
221    We canonicalize it to be in Unix format (backslashes are replaced
222    forward slashes.  */
223 #undef OUTPUT_QUOTED_STRING
224 #define OUTPUT_QUOTED_STRING(FILE, STRING)               \
225 do {						         \
226   const char *_string = (const char *) (STRING);	 \
227   char c;					         \
228 						         \
229   putc ('\"', (FILE));				         \
230 						         \
231   while ((c = *_string++) != 0)			         \
232     {						         \
233       if (c == '\\')				         \
234 	c = '/';				         \
235 						         \
236       if (ISPRINT (c))                                   \
237         {                                                \
238           if (c == '\"')			         \
239 	    putc ('\\', (FILE));		         \
240           putc (c, (FILE));			         \
241         }                                                \
242       else                                               \
243         fprintf ((FILE), "\\%03o", (unsigned char) c);	 \
244     }						         \
245 						         \
246   putc ('\"', (FILE));					 \
247 } while (0)
248 
249 /* Define as short unsigned for compatibility with MS runtime.  */
250 #undef WINT_TYPE
251 #define WINT_TYPE "short unsigned int"
252 
253 /* mingw32 uses the  -mthreads option to enable thread support.  */
254 #undef GOMP_SELF_SPECS
255 #define GOMP_SELF_SPECS "%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): " \
256 			"-mthreads -pthread}"
257 #undef GTM_SELF_SPECS
258 #define GTM_SELF_SPECS "%{fgnu-tm:-mthreads -pthread}"
259 
260 /* mingw32 atexit function is safe to use in shared libraries.  Use it
261    to register C++ static destructors.  */
262 #define TARGET_CXX_USE_ATEXIT_FOR_CXA_ATEXIT hook_bool_void_true
263 
264 /* Contains a pointer to type target_ovr_attr defining the target specific
265    overrides of format attributes.  See c-format.h for structure
266    definition.  */
267 #undef TARGET_OVERRIDES_FORMAT_ATTRIBUTES
268 #define TARGET_OVERRIDES_FORMAT_ATTRIBUTES mingw_format_attribute_overrides
269 
270 /* Specify the count of elements in TARGET_OVERRIDES_ATTRIBUTE.  */
271 #undef TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT
272 #define TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT 3
273 
274 /* Custom initialization for warning -Wpedantic-ms-format for c-format.  */
275 #undef TARGET_OVERRIDES_FORMAT_INIT
276 #define TARGET_OVERRIDES_FORMAT_INIT msformat_init
277 
278 /* MS specific format attributes for ms_printf, ms_scanf, ms_strftime.  */
279 #undef TARGET_FORMAT_TYPES
280 #define TARGET_FORMAT_TYPES mingw_format_attributes
281 
282 #undef TARGET_N_FORMAT_TYPES
283 #define TARGET_N_FORMAT_TYPES 3
284 
285 #define HAVE_ENABLE_EXECUTE_STACK
286 #undef  CHECK_EXECUTE_STACK_ENABLED
287 #define CHECK_EXECUTE_STACK_ENABLED flag_setstackexecutable
288 
289 /* This matches SHLIB_SONAME and SHLIB_SOVERSION in t-cygming. */
290 /* This matches SHLIB_SONAME and SHLIB_SOVERSION in t-cygwin. */
291 #if DWARF2_UNWIND_INFO
292 #define LIBGCC_EH_EXTN "_dw2"
293 #else
294 #define LIBGCC_EH_EXTN "_sjlj"
295 #endif
296 #define LIBGCC_SONAME "libgcc_s" LIBGCC_EH_EXTN "-1.dll"
297 
298