1 /* Operating system specific defines to be used when targeting GCC for
2    hosting on Windows32, using a Unix style C library and tools.
3    Copyright (C) 1995-2021 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 #define EXTRA_OS_CPP_BUILTINS()					\
22   do								\
23     {								\
24       builtin_define ("__CYGWIN__");				\
25       if (!TARGET_64BIT)					\
26 	builtin_define ("__CYGWIN32__");			\
27       builtin_define ("__unix__");				\
28       builtin_define ("__unix");				\
29     }								\
30   while (0)
31 
32 #define EXTRA_TARGET_D_OS_VERSIONS()				\
33   do								\
34     {								\
35       builtin_version ("Cygwin");				\
36       builtin_version ("Posix");				\
37       builtin_version ("CRuntime_Newlib");			\
38     }								\
39   while (0)
40 
41 #undef CPP_SPEC
42 #define CPP_SPEC "%(cpp_cpu) %{posix:-D_POSIX_SOURCE} \
43   %{!ansi:-Dunix} \
44   %{pthread:-D_REENTRANT} \
45   %{mwin32:-DWIN32 -D_WIN32 -D__WIN32 -D__WIN32__ %{!ansi:-DWINNT}} \
46   %{!nostdinc:%{!mno-win32:-idirafter ../include/w32api%s -idirafter ../../include/w32api%s}}\
47 "
48 
49 #undef STARTFILE_SPEC
50 #define STARTFILE_SPEC "\
51   %{!shared: %{!mdll: crt0%O%s \
52   %{pg:gcrt0%O%s}}}\
53   %{shared:crtbeginS.o%s;:crtbegin.o%s} \
54   %{fvtable-verify=none:%s; \
55     fvtable-verify=preinit:vtv_start.o%s; \
56     fvtable-verify=std:vtv_start.o%s}"
57 
58 #undef ENDFILE_SPEC
59 #define ENDFILE_SPEC \
60   "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}\
61    %{!shared:%:if-exists(default-manifest.o%s)}\
62    %{fvtable-verify=none:%s; \
63     fvtable-verify=preinit:vtv_end.o%s; \
64     fvtable-verify=std:vtv_end.o%s} \
65    crtend.o%s"
66 
67 /* Normally, -lgcc is not needed since everything in it is in the DLL, but we
68    want to allow things to be added to it when installing new versions of
69    GCC without making a new CYGWIN.DLL, so we leave it.  Profiling is handled
70    by calling the init function from main.  */
71 
72 #ifdef ENABLE_SHARED_LIBGCC
73 #define SHARED_LIBGCC_SPEC " \
74  %{static|static-libgcc:-lgcc -lgcc_eh} \
75  %{!static: \
76    %{!static-libgcc: \
77      -lgcc_s -lgcc \
78     } \
79   } "
80 #else
81 #define SHARED_LIBGCC_SPEC " -lgcc "
82 #endif
83 
84 #undef REAL_LIBGCC_SPEC
85 #define REAL_LIBGCC_SPEC SHARED_LIBGCC_SPEC
86 
87 /* We have to dynamic link to get to the system DLLs.  All of libc, libm and
88    the Unix stuff is in cygwin.dll.  The import library is called
89    'libcygwin.a'.  For Windows applications, include more libraries, but
90    always include kernel32.  We'd like to specific subsystem windows to
91    ld, but that doesn't work just yet.  */
92 
93 #undef LIB_SPEC
94 #define LIB_SPEC "\
95   %{pg:-lgmon} \
96   %{pthread: } \
97   -lcygwin \
98   %{mwindows:-lgdi32 -lcomdlg32} \
99   %{fvtable-verify=preinit:-lvtv -lpsapi; \
100     fvtable-verify=std:-lvtv -lpsapi} \
101   -ladvapi32 -lshell32 -luser32 -lkernel32"
102 
103 /* To implement C++ function replacement we always wrap the cxx
104    malloc-like operators.  See N2800 #17.6.4.6 [replacement.functions] */
105 #define CXX_WRAP_SPEC_LIST " \
106   --wrap _Znwj \
107   --wrap _Znaj \
108   --wrap _ZdlPv \
109   --wrap _ZdaPv \
110   --wrap _ZnwjRKSt9nothrow_t \
111   --wrap _ZnajRKSt9nothrow_t \
112   --wrap _ZdlPvRKSt9nothrow_t \
113   --wrap _ZdaPvRKSt9nothrow_t \
114 "
115 
116 #if defined (USE_CYGWIN_LIBSTDCXX_WRAPPERS)
117 
118 #if USE_CYGWIN_LIBSTDCXX_WRAPPERS
119 /* Default on, only explict -mno disables.  */
120 #define CXX_WRAP_SPEC_OPT "!mno-use-libstdc-wrappers"
121 #else
122 /* Default off, only explict -m enables.  */
123 #define CXX_WRAP_SPEC_OPT "muse-libstdc-wrappers"
124 #endif
125 
126 #define CXX_WRAP_SPEC "%{" CXX_WRAP_SPEC_OPT ":" CXX_WRAP_SPEC_LIST "}"
127 
128 #else /* !defined (USE_CYGWIN_LIBSTDCXX_WRAPPERS)  */
129 
130 #define CXX_WRAP_SPEC ""
131 
132 #endif /* ?defined (USE_CYGWIN_LIBSTDCXX_WRAPPERS) */
133 
134 #define LINK_SPEC "\
135   %{mwindows:--subsystem windows} \
136   %{mconsole:--subsystem console} \
137   " CXX_WRAP_SPEC " \
138   %{shared: %{mdll: %eshared and mdll are not compatible}} \
139   %{shared: --shared} %{mdll:--dll} \
140   %{static:-Bstatic} %{!static:-Bdynamic} \
141   %{shared|mdll: --enable-auto-image-base -e __cygwin_dll_entry@12} \
142   --dll-search-prefix=cyg \
143   %{!shared: %{!mdll: --large-address-aware --tsaware}}"
144 
145 /* Binutils does not handle weak symbols from dlls correctly.  For now,
146    do not use them unnecessarily in gthr-posix.h.  */
147 #define GTHREAD_USE_WEAK 0
148 
149 /* Every program on cygwin links against cygwin1.dll which contains
150    the pthread routines.  There is no need to explicitly link them
151    and the -pthread flag is accepted only for compatibility.  */
152 #undef GOMP_SELF_SPECS
153 #define GOMP_SELF_SPECS ""
154 #undef GTM_SELF_SPECS
155 #define GTM_SELF_SPECS ""
156 
157 /* This matches SHLIB_SONAME and SHLIB_SOVERSION in t-cygwin. */
158 #if DWARF2_UNWIND_INFO
159 #define LIBGCC_EH_EXTN ""
160 #else
161 #define LIBGCC_EH_EXTN "-sjlj"
162 #endif
163 #define LIBGCC_SONAME "cyggcc_s" LIBGCC_EH_EXTN "-1.dll"
164 
165 /* Make stack executable to avoid DEP problems with trampolines.  */
166 #define HAVE_ENABLE_EXECUTE_STACK
167 #undef  CHECK_EXECUTE_STACK_ENABLED
168 #define CHECK_EXECUTE_STACK_ENABLED flag_setstackexecutable
169