| 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-2025 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 |
#if !defined (TARGET_AARCH64_MS_ABI) |
| 23 |
# define DEFAULT_ABI MS_ABI |
| 24 |
#endif |
| 25 |
|
| 26 |
/* By default, target has a 80387, uses IEEE compatible arithmetic, |
| 27 |
returns float values in the 387 and needs stack probes. |
| 28 |
We also align doubles to 64-bits for MSVC default compatibility. |
| 29 |
Additionally we enable MS_BITFIELD_LAYOUT by default. */ |
| 30 |
|
| 31 |
#undef TARGET_SUBTARGET_DEFAULT |
| 32 |
#define TARGET_SUBTARGET_DEFAULT \ |
| 33 |
(MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS \ |
| 34 |
| MASK_STACK_PROBE | MASK_ALIGN_DOUBLE \ |
| 35 |
| MASK_MS_BITFIELD_LAYOUT) |
| 36 |
|
| 37 |
#ifdef TARGET_USING_MCFGTHREAD |
| 38 |
#define DEFINE_THREAD_MODEL builtin_define ("__USING_MCFGTHREAD__"); |
| 39 |
#elif defined(TARGET_USE_PTHREAD_BY_DEFAULT) |
| 40 |
#define DEFINE_THREAD_MODEL builtin_define ("__USING_POSIXTHREAD__"); |
| 41 |
#else |
| 42 |
#define DEFINE_THREAD_MODEL |
| 43 |
#endif |
| 44 |
|
| 45 |
/* See i386/crtdll.h for an alternative definition. _INTEGRAL_MAX_BITS |
| 46 |
is for compatibility with native compiler. */ |
| 47 |
#define EXTRA_OS_CPP_BUILTINS() \ |
| 48 |
do \ |
| 49 |
{ \ |
| 50 |
builtin_define ("__MSVCRT__"); \ |
| 51 |
builtin_define ("__MINGW32__"); \ |
| 52 |
builtin_define ("_WIN32"); \ |
| 53 |
builtin_define_std ("WIN32"); \ |
| 54 |
builtin_define_std ("WINNT"); \ |
| 55 |
builtin_define_with_int_value ("_INTEGRAL_MAX_BITS", \ |
| 56 |
TYPE_PRECISION (intmax_type_node));\ |
| 57 |
if (TARGET_64BIT && ix86_abi == MS_ABI) \ |
| 58 |
{ \ |
| 59 |
builtin_define ("__MINGW64__"); \ |
| 60 |
builtin_define_std ("WIN64"); \ |
| 61 |
builtin_define ("_WIN64"); \ |
| 62 |
} \ |
| 63 |
DEFINE_THREAD_MODEL \ |
| 64 |
} \ |
| 65 |
while (0) |
| 66 |
|
| 67 |
#ifndef TARGET_USE_PTHREAD_BY_DEFAULT |
| 68 |
#define SPEC_PTHREAD1 "pthread" |
| 69 |
#define SPEC_PTHREAD2 "!no-pthread" |
| 70 |
#else |
| 71 |
#define SPEC_PTHREAD1 "!no-pthread" |
| 72 |
#define SPEC_PTHREAD2 "pthread" |
| 73 |
#endif |
| 74 |
|
| 75 |
#undef SUB_LINK_ENTRY32 |
| 76 |
#undef SUB_LINK_ENTRY64 |
| 77 |
#define SUB_LINK_ENTRY32 "-e _DllMainCRTStartup@12" |
| 78 |
#if defined(USE_MINGW64_LEADING_UNDERSCORES) |
| 79 |
#define SUB_LINK_ENTRY64 "-e _DllMainCRTStartup" |
| 80 |
#else |
| 81 |
#define SUB_LINK_ENTRY64 "-e DllMainCRTStartup" |
| 82 |
#endif |
| 83 |
|
| 84 |
#undef SUB_LINK_ENTRY |
| 85 |
#if HAVE_64BIT_POINTERS |
| 86 |
#define SUB_LINK_ENTRY SUB_LINK_ENTRY64 |
| 87 |
#else |
| 88 |
#define SUB_LINK_ENTRY SUB_LINK_ENTRY32 |
| 89 |
#endif |
| 90 |
|
| 91 |
#undef NATIVE_SYSTEM_HEADER_COMPONENT |
| 92 |
#define NATIVE_SYSTEM_HEADER_COMPONENT "MINGW" |
| 93 |
|
| 94 |
#undef CPP_SPEC |
| 95 |
#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} " \ |
| 96 |
"%{" SPEC_PTHREAD1 ":-D_REENTRANT} " \ |
| 97 |
"%{" SPEC_PTHREAD2 ": } " \ |
| 98 |
"%{mcrtdll=crtdll*:-U__MSVCRT__ -D__CRTDLL__} " \ |
| 99 |
"%{mcrtdll=msvcrt10*:-D__MSVCRT_VERSION__=0x100} " \ |
| 100 |
"%{mcrtdll=msvcrt20*:-D__MSVCRT_VERSION__=0x200} " \ |
| 101 |
"%{mcrtdll=msvcrt40*:-D__MSVCRT_VERSION__=0x400} " \ |
| 102 |
"%{mcrtdll=msvcr40*:-D__MSVCRT_VERSION__=0x400} " \ |
| 103 |
"%{mcrtdll=msvcrtd*:-D__MSVCRT_VERSION__=0x600} " \ |
| 104 |
"%{mcrtdll=msvcrt-os*:-D__MSVCRT_VERSION__=0x700} " \ |
| 105 |
"%{mcrtdll=msvcr70*:-D__MSVCRT_VERSION__=0x700} " \ |
| 106 |
"%{mcrtdll=msvcr71*:-D__MSVCRT_VERSION__=0x701} " \ |
| 107 |
"%{mcrtdll=msvcr80*:-D__MSVCRT_VERSION__=0x800} " \ |
| 108 |
"%{mcrtdll=msvcr90*:-D__MSVCRT_VERSION__=0x900} " \ |
| 109 |
"%{mcrtdll=msvcr100*:-D__MSVCRT_VERSION__=0xA00} " \ |
| 110 |
"%{mcrtdll=msvcr110*:-D__MSVCRT_VERSION__=0xB00} " \ |
| 111 |
"%{mcrtdll=msvcr120*:-D__MSVCRT_VERSION__=0xC00} " \ |
| 112 |
"%{mcrtdll=ucrt*:-D_UCRT} " |
| 113 |
|
| 114 |
/* For Windows applications, include more libraries, but always include |
| 115 |
kernel32. */ |
| 116 |
#undef LIB_SPEC |
| 117 |
#define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ |
| 118 |
"%{" SPEC_PTHREAD2 ": } " \ |
| 119 |
"%{mwindows:-lgdi32 -lcomdlg32} " \ |
| 120 |
"%{fvtable-verify=preinit:-lvtv -lpsapi; \ |
| 121 |
fvtable-verify=std:-lvtv -lpsapi} " \ |
| 122 |
"-ladvapi32 -lshell32 -luser32 -lkernel32" |
| 123 |
|
| 124 |
/* Weak symbols do not get resolved if using a Windows dll import lib. |
| 125 |
Make the unwind registration references strong undefs. */ |
| 126 |
#if DWARF2_UNWIND_INFO |
| 127 |
/* DW2-unwind is just available for 32-bit mode. */ |
| 128 |
#if TARGET_64BIT_DEFAULT |
| 129 |
#define SHARED_LIBGCC_UNDEFS_SPEC \ |
| 130 |
"%{m32: %{shared-libgcc: -u ___register_frame_info -u ___deregister_frame_info}}" |
| 131 |
#else |
| 132 |
#define SHARED_LIBGCC_UNDEFS_SPEC \ |
| 133 |
"%{shared-libgcc: -u ___register_frame_info -u ___deregister_frame_info}" |
| 134 |
#endif |
| 135 |
#else |
| 136 |
#define SHARED_LIBGCC_UNDEFS_SPEC "" |
| 137 |
#endif |
| 138 |
|
| 139 |
#undef SUBTARGET_EXTRA_SPECS |
| 140 |
#define SUBTARGET_EXTRA_SPECS \ |
| 141 |
{ "shared_libgcc_undefs", SHARED_LIBGCC_UNDEFS_SPEC } |
| 142 |
|
| 143 |
#if ! MINGW_DEFAULT_LARGE_ADDR_AWARE |
| 144 |
/* This is used without --enable-large-address-aware. */ |
| 145 |
# define LINK_SPEC_LARGE_ADDR_AWARE "" |
| 146 |
#elif ! TARGET_BI_ARCH |
| 147 |
/* This is used on i686-pc-mingw32 with --enable-large-address-aware. */ |
| 148 |
# define LINK_SPEC_LARGE_ADDR_AWARE \ |
| 149 |
"%{!shared:%{!mdll:--large-address-aware}}" |
| 150 |
#elif TARGET_64BIT_DEFAULT |
| 151 |
/* This is used on x86_64-pc-mingw32 with --enable-large-address-aware. |
| 152 |
??? It probably doesn't work, because the linker emulation defaults |
| 153 |
to i386pep, the 64-bit mode that does not support |
| 154 |
--large-address-aware, and x86_64-pc-mingw32 does not override the |
| 155 |
emulation to i386pe for -m32, unlike x86_64-w64-mingw32. */ |
| 156 |
# define LINK_SPEC_LARGE_ADDR_AWARE \ |
| 157 |
"%{!shared:%{!mdll:%{m32:--large-address-aware}}}" |
| 158 |
#else |
| 159 |
/* This would only be used if someone introduced a biarch |
| 160 |
configuration that defaulted to 32-bit. */ |
| 161 |
# define LINK_SPEC_LARGE_ADDR_AWARE \ |
| 162 |
"%{!shared:%{!mdll:%{!m64:--large-address-aware}}}" |
| 163 |
#endif |
| 164 |
|
| 165 |
#if HAVE_LD_PE_DISABLE_DYNAMICBASE |
| 166 |
# define LINK_SPEC_DISABLE_DYNAMICBASE \ |
| 167 |
"%{!shared:%{!mdll:%{no-pie:--disable-dynamicbase}}}" |
| 168 |
#else |
| 169 |
# define LINK_SPEC_DISABLE_DYNAMICBASE "" |
| 170 |
#endif |
| 171 |
|
| 172 |
#define LINK_SPEC "%{mwindows:--subsystem windows} \ |
| 173 |
%{mconsole:--subsystem console} \ |
| 174 |
%{shared: %{mdll: %eshared and mdll are not compatible}} \ |
| 175 |
%{shared: --shared} %{mdll:--dll} \ |
| 176 |
%{static:-Bstatic} %{!static:-Bdynamic} \ |
| 177 |
%{shared|mdll: " SUB_LINK_ENTRY " --enable-auto-image-base} \ |
| 178 |
" LINK_SPEC_LARGE_ADDR_AWARE "\ |
| 179 |
" LINK_SPEC_DISABLE_DYNAMICBASE "\ |
| 180 |
%(shared_libgcc_undefs)" |
| 181 |
|
| 182 |
/* Include in the mingw32 libraries with libgcc */ |
| 183 |
#ifdef ENABLE_SHARED_LIBGCC |
| 184 |
#define SHARED_LIBGCC_SPEC " \ |
| 185 |
%{static|static-libgcc:-lgcc -lgcc_eh} \ |
| 186 |
%{!static: \ |
| 187 |
%{!static-libgcc: \ |
| 188 |
%{!shared: \ |
| 189 |
%{!shared-libgcc:-lgcc -lgcc_eh} \ |
| 190 |
%{shared-libgcc:-lgcc_s -lgcc} \ |
| 191 |
} \ |
| 192 |
%{shared:-lgcc_s -lgcc} \ |
| 193 |
} \ |
| 194 |
} " |
| 195 |
#else |
| 196 |
#define SHARED_LIBGCC_SPEC " -lgcc " |
| 197 |
#endif |
| 198 |
#ifdef TARGET_USING_MCFGTHREAD |
| 199 |
#define MCFGTHREAD_SPEC " -lmcfgthread -lkernel32 -lntdll " |
| 200 |
#else |
| 201 |
#define MCFGTHREAD_SPEC "" |
| 202 |
#endif |
| 203 |
#undef REAL_LIBGCC_SPEC |
| 204 |
#define REAL_LIBGCC_SPEC \ |
| 205 |
"%{mthreads:-lmingwthrd} -lmingw32 \ |
| 206 |
" SHARED_LIBGCC_SPEC " \ |
| 207 |
%{mcrtdll=crtdll*:-lcoldname} %{!mcrtdll=crtdll*:-lmoldname} \ |
| 208 |
-lmingwex %{!mcrtdll=*:-lmsvcrt} %{mcrtdll=*:-l%*} \ |
| 209 |
-lkernel32 " MCFGTHREAD_SPEC |
| 210 |
|
| 211 |
#undef STARTFILE_SPEC |
| 212 |
#define STARTFILE_SPEC " \ |
| 213 |
%{shared|mdll:%{mcrtdll=crtdll*:dllcrt1%O%s}} \ |
| 214 |
%{shared|mdll:%{!mcrtdll=crtdll*:dllcrt2%O%s}} \ |
| 215 |
%{!shared:%{!mdll:%{mcrtdll=crtdll*:crt1%O%s}}} \ |
| 216 |
%{!shared:%{!mdll:%{!mcrtdll=crtdll*:crt2%O%s}}} \ |
| 217 |
%{pg:%{mcrtdll=crtdll*:gcrt1%O%s}} \ |
| 218 |
%{pg:%{!mcrtdll=crtdll*:gcrt2%O%s}} \ |
| 219 |
crtbegin.o%s \ |
| 220 |
%{fvtable-verify=none:%s; \ |
| 221 |
fvtable-verify=preinit:vtv_start.o%s; \ |
| 222 |
fvtable-verify=std:vtv_start.o%s}" |
| 223 |
|
| 224 |
#undef ENDFILE_SPEC |
| 225 |
#define ENDFILE_SPEC \ |
| 226 |
"%{mdaz-ftz:crtfastmath.o%s;Ofast|ffast-math|funsafe-math-optimizations:%{!shared:%{!mno-daz-ftz:crtfastmath.o%s}}} \ |
| 227 |
%{!shared:%:if-exists(default-manifest.o%s)}\ |
| 228 |
%{fvtable-verify=none:%s; \ |
| 229 |
fvtable-verify=preinit:vtv_end.o%s; \ |
| 230 |
fvtable-verify=std:vtv_end.o%s} \ |
| 231 |
crtend.o%s" |
| 232 |
|
| 233 |
/* Override startfile prefix defaults. */ |
| 234 |
#ifndef STANDARD_STARTFILE_PREFIX_1 |
| 235 |
#define STANDARD_STARTFILE_PREFIX_1 "/mingw/lib/" |
| 236 |
#endif |
| 237 |
#ifndef STANDARD_STARTFILE_PREFIX_2 |
| 238 |
#define STANDARD_STARTFILE_PREFIX_2 "" |
| 239 |
#endif |
| 240 |
|
| 241 |
/* For native mingw-version we need to take care that NATIVE_SYSTEM_HEADER_DIR |
| 242 |
macro contains POSIX-style path. See bug 52947. */ |
| 243 |
#undef NATIVE_SYSTEM_HEADER_DIR |
| 244 |
#define NATIVE_SYSTEM_HEADER_DIR "/mingw/include" |
| 245 |
|
| 246 |
/* Output STRING, a string representing a filename, to FILE. |
| 247 |
We canonicalize it to be in Unix format (backslashes are replaced |
| 248 |
forward slashes. */ |
| 249 |
#undef OUTPUT_QUOTED_STRING |
| 250 |
#define OUTPUT_QUOTED_STRING(FILE, STRING) \ |
| 251 |
do { \ |
| 252 |
const char *_string = (const char *) (STRING); \ |
| 253 |
char c; \ |
| 254 |
\ |
| 255 |
putc ('\"', (FILE)); \ |
| 256 |
\ |
| 257 |
while ((c = *_string++) != 0) \ |
| 258 |
{ \ |
| 259 |
if (c == '\\') \ |
| 260 |
c = '/'; \ |
| 261 |
\ |
| 262 |
if (ISPRINT (c)) \ |
| 263 |
{ \ |
| 264 |
if (c == '\"') \ |
| 265 |
putc ('\\', (FILE)); \ |
| 266 |
putc (c, (FILE)); \ |
| 267 |
} \ |
| 268 |
else \ |
| 269 |
fprintf ((FILE), "\\%03o", (unsigned char) c); \ |
| 270 |
} \ |
| 271 |
\ |
| 272 |
putc ('\"', (FILE)); \ |
| 273 |
} while (0) |
| 274 |
|
| 275 |
/* Define as short unsigned for compatibility with MS runtime. */ |
| 276 |
#undef WINT_TYPE |
| 277 |
#define WINT_TYPE "short unsigned int" |
| 278 |
|
| 279 |
/* mingw32 uses the -mthreads option to enable thread support. */ |
| 280 |
#undef GOMP_SELF_SPECS |
| 281 |
#define GOMP_SELF_SPECS "%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): " \ |
| 282 |
"-mthreads -pthread}" |
| 283 |
#undef GTM_SELF_SPECS |
| 284 |
#define GTM_SELF_SPECS "%{fgnu-tm:-mthreads -pthread}" |
| 285 |
|
| 286 |
/* mingw32 atexit function is safe to use in shared libraries. Use it |
| 287 |
to register C++ static destructors. */ |
| 288 |
#define TARGET_CXX_USE_ATEXIT_FOR_CXA_ATEXIT hook_bool_void_true |
| 289 |
|
| 290 |
/* Contains a pointer to type target_ovr_attr defining the target specific |
| 291 |
overrides of format attributes. See c-format.h for structure |
| 292 |
definition. */ |
| 293 |
#undef TARGET_OVERRIDES_FORMAT_ATTRIBUTES |
| 294 |
#define TARGET_OVERRIDES_FORMAT_ATTRIBUTES mingw_format_attribute_overrides |
| 295 |
|
| 296 |
/* Specify the count of elements in TARGET_OVERRIDES_ATTRIBUTE. */ |
| 297 |
#undef TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT |
| 298 |
#define TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT 3 |
| 299 |
|
| 300 |
/* Custom initialization for warning -Wpedantic-ms-format for c-format. */ |
| 301 |
#undef TARGET_OVERRIDES_FORMAT_INIT |
| 302 |
#define TARGET_OVERRIDES_FORMAT_INIT msformat_init |
| 303 |
|
| 304 |
/* MS specific format attributes for ms_printf, ms_scanf, ms_strftime. */ |
| 305 |
#undef TARGET_FORMAT_TYPES |
| 306 |
#define TARGET_FORMAT_TYPES mingw_format_attributes |
| 307 |
|
| 308 |
#undef TARGET_N_FORMAT_TYPES |
| 309 |
#define TARGET_N_FORMAT_TYPES 3 |
| 310 |
|
| 311 |
#define HAVE_ENABLE_EXECUTE_STACK |
| 312 |
#undef CHECK_EXECUTE_STACK_ENABLED |
| 313 |
#define CHECK_EXECUTE_STACK_ENABLED flag_setstackexecutable |
| 314 |
|
| 315 |
/* This matches SHLIB_SONAME and SHLIB_SOVERSION in t-cygming. */ |
| 316 |
/* This matches SHLIB_SONAME and SHLIB_SOVERSION in t-cygwin. */ |
| 317 |
#if DWARF2_UNWIND_INFO |
| 318 |
#define LIBGCC_EH_EXTN "_dw2" |
| 319 |
#else |
| 320 |
#define LIBGCC_EH_EXTN "_sjlj" |
| 321 |
#endif |
| 322 |
#define LIBGCC_SONAME "libgcc_s" LIBGCC_EH_EXTN "-1.dll" |
| 323 |
|