Skip to content

Commit 879bc2e

Browse files
committed
mingw: Update MinGW-w64 sources to 38c8142f660b6ba11e7c408f2de1e9f8bfaf839e.
1 parent 0979e56 commit 879bc2e

File tree

143 files changed

+1796
-1487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+1796
-1487
lines changed

lib/libc/mingw/cfguard/mingw_cfguard_support.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@
1717
// really matter here because this is a no-op anyway.
1818
static void __guard_check_icall_dummy(void) {}
1919

20-
// When CFGuard is not active, directly tail-call the target address, which
21-
// is passed via %rax.
22-
__asm__(
23-
".globl __guard_dispatch_icall_dummy\n"
24-
"__guard_dispatch_icall_dummy:\n"
25-
" jmp *%rax\n"
26-
);
27-
2820
// This is intentionally declared as _not_ a function pointer, so that the
2921
// jmp instruction is not included as a valid call target for CFGuard.
3022
extern void *__guard_dispatch_icall_dummy;

lib/libc/mingw/crt/CRT_fp10.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,11 @@ void _fpreset (void);
88

99
void _fpreset (void)
1010
{
11-
#if defined(_ARM_) || defined(__arm__)
12-
__asm__ __volatile__ (
13-
"vmsr fpscr, %0\n\t" : : "r"(0 /* INITIAL_FPSCR */));
14-
#elif defined(_ARM64_) || defined(__aarch64__)
15-
__asm__ __volatile__ (
16-
"msr fpcr, %0\n\t" : : "r"(0LL /* INITIAL_FPSCR */));
17-
#else
1811
#ifdef __GNUC__
1912
__asm__ ("fninit");
2013
#else /* msvc: */
2114
__asm fninit;
2215
#endif
23-
#endif
2416
}
2517

2618
#ifdef __GNUC__

lib/libc/mingw/crt/crtdll.c

Lines changed: 47 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
55
*/
66

7-
#ifdef CRTDLL
8-
#undef CRTDLL
9-
#ifndef _DLL
10-
#define _DLL
11-
#endif
12-
137
#include <oscalls.h>
148
#include <internal.h>
159
#include <stdlib.h>
@@ -19,20 +13,14 @@
1913
#include <crtdbg.h>
2014

2115
#ifndef _CRTIMP
22-
#ifdef CRTDLL
23-
#define _CRTIMP __declspec(dllexport)
24-
#else
25-
#ifdef _DLL
2616
#define _CRTIMP __declspec(dllimport)
27-
#else
28-
#define _CRTIMP
29-
#endif
30-
#endif
3117
#endif
3218
#include <sect_attribs.h>
3319
#include <locale.h>
3420

35-
extern void __cdecl _initterm(_PVFV *,_PVFV *);
21+
#if defined(__x86_64__) && !defined(__SEH__)
22+
extern int __mingw_init_ehandler (void);
23+
#endif
3624
extern void __main ();
3725
extern void _pei386_runtime_relocator (void);
3826
extern _PIFV __xi_a[];
@@ -50,20 +38,6 @@ static _onexit_table_t atexit_table;
5038

5139
extern int __mingw_app_type;
5240

53-
extern WINBOOL WINAPI DllMain (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved);
54-
55-
extern WINBOOL WINAPI DllEntryPoint (HANDLE, DWORD, LPVOID);
56-
57-
static int pre_c_init (void);
58-
59-
_CRTALLOC(".CRT$XIAA") _PIFV pcinit = pre_c_init;
60-
61-
static int
62-
pre_c_init (void)
63-
{
64-
return _initialize_onexit_table(&atexit_table);
65-
}
66-
6741
WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
6842
{
6943
if (dwReason == DLL_PROCESS_DETACH)
@@ -77,10 +51,11 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
7751
{
7852
void *lock_free = NULL;
7953
void *fiberid = ((PNT_TIB)NtCurrentTeb ())->StackBase;
80-
int nested = FALSE;
54+
BOOL nested = FALSE;
55+
int ret = 0;
8156

82-
while ((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,
83-
fiberid, 0)) != 0)
57+
while ((lock_free = InterlockedCompareExchangePointer (&__native_startup_lock,
58+
fiberid, NULL)) != 0)
8459
{
8560
if (lock_free == fiberid)
8661
{
@@ -89,25 +64,37 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
8964
}
9065
Sleep(1000);
9166
}
92-
if (__native_startup_state == __initializing)
67+
if (__native_startup_state != __uninitialized)
9368
{
9469
_amsg_exit (31);
9570
}
96-
else if (__native_startup_state == __uninitialized)
71+
else
9772
{
9873
__native_startup_state = __initializing;
9974

100-
if (_initterm_e (__xi_a, __xi_z) != 0)
101-
return FALSE;
102-
}
103-
if (__native_startup_state == __initializing)
104-
{
75+
_pei386_runtime_relocator ();
76+
#if defined(__x86_64__) && !defined(__SEH__)
77+
__mingw_init_ehandler ();
78+
#endif
79+
ret = _initialize_onexit_table (&atexit_table);
80+
if (ret != 0)
81+
goto i__leave;
82+
ret = _initterm_e (__xi_a, __xi_z);
83+
if (ret != 0)
84+
goto i__leave;
10585
_initterm (__xc_a, __xc_z);
86+
__main ();
87+
10688
__native_startup_state = __initialized;
10789
}
90+
i__leave:
10891
if (! nested)
10992
{
110-
(void) InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0);
93+
(void) InterlockedExchangePointer (&__native_startup_lock, NULL);
94+
}
95+
if (ret != 0)
96+
{
97+
return FALSE;
11198
}
11299
if (__dyn_tls_init_callback != NULL)
113100
{
@@ -118,8 +105,16 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
118105
else if (dwReason == DLL_PROCESS_DETACH)
119106
{
120107
void *lock_free = NULL;
121-
while ((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,(PVOID) 1, 0)) != 0)
108+
void *fiberid = ((PNT_TIB)NtCurrentTeb ())->StackBase;
109+
BOOL nested = FALSE;
110+
111+
while ((lock_free = InterlockedCompareExchangePointer (&__native_startup_lock, fiberid, NULL)) != 0)
122112
{
113+
if (lock_free == fiberid)
114+
{
115+
nested = TRUE;
116+
break;
117+
}
123118
Sleep(1000);
124119
}
125120
if (__native_startup_state != __initialized)
@@ -130,84 +125,56 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
130125
{
131126
_execute_onexit_table(&atexit_table);
132127
__native_startup_state = __uninitialized;
133-
(void) InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0);
128+
}
129+
if (! nested)
130+
{
131+
(void) InterlockedExchangePointer (&__native_startup_lock, NULL);
134132
}
135133
}
136134
return TRUE;
137135
}
138136

139-
static WINBOOL __DllMainCRTStartup (HANDLE, DWORD, LPVOID);
140-
141137
WINBOOL WINAPI DllMainCRTStartup (HANDLE, DWORD, LPVOID);
142-
#if defined(__x86_64__) && !defined(__SEH__)
143-
int __mingw_init_ehandler (void);
144-
#endif
145138

146-
__attribute__((used)) /* required due to GNU LD bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30300 */
147-
WINBOOL WINAPI
148-
DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
149-
{
150-
__mingw_app_type = 0;
151-
return __DllMainCRTStartup (hDllHandle, dwReason, lpreserved);
152-
}
153-
154-
static
155139
#if defined(__i386__) || defined(_X86_)
156140
/* We need to make sure that we align the stack to 16 bytes for the sake of SSE
157-
opts in DllMain/DllEntryPoint or in functions called from DllMain/DllEntryPoint. */
141+
opts in DllMain or in functions called from DllMain. */
158142
__attribute__((force_align_arg_pointer))
159143
#endif
160-
__declspec(noinline) WINBOOL
161-
__DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
144+
__attribute__((used)) /* required due to GNU LD bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30300 */
145+
WINBOOL WINAPI
146+
DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
162147
{
163148
WINBOOL retcode = TRUE;
164149

150+
__mingw_app_type = 0;
165151
__native_dllmain_reason = dwReason;
166-
if (dwReason == DLL_PROCESS_DETACH && __proc_attached == 0)
152+
if (dwReason == DLL_PROCESS_DETACH && __proc_attached <= 0)
167153
{
168154
retcode = FALSE;
169155
goto i__leave;
170156
}
171-
_pei386_runtime_relocator ();
172-
173-
#if defined(__x86_64__) && !defined(__SEH__)
174-
if (dwReason == DLL_PROCESS_ATTACH)
175-
__mingw_init_ehandler ();
176-
#endif
177157

178158
if (dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH)
179159
{
180160
retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved);
181161
if (!retcode)
182162
goto i__leave;
183-
retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved);
184-
if (! retcode)
185-
{
186-
if (dwReason == DLL_PROCESS_ATTACH)
187-
_CRT_INIT (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
188-
goto i__leave;
189-
}
190163
}
191-
if (dwReason == DLL_PROCESS_ATTACH)
192-
__main ();
193164
retcode = DllMain(hDllHandle,dwReason,lpreserved);
194165
if (dwReason == DLL_PROCESS_ATTACH && ! retcode)
195166
{
196167
DllMain (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
197-
DllEntryPoint (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
198168
_CRT_INIT (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
199169
}
200170
if (dwReason == DLL_PROCESS_DETACH || dwReason == DLL_THREAD_DETACH)
201171
{
202-
retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved);
203-
if (_CRT_INIT (hDllHandle, dwReason, lpreserved) == FALSE)
204-
retcode = FALSE;
172+
retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved);
205173
}
206174
i__leave:
207175
__native_dllmain_reason = UINT_MAX;
208176
return retcode ;
209177
}
210-
#endif
211178

212179
int __cdecl atexit (_PVFV func)
213180
{

lib/libc/mingw/crt/crtexe.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
55
*/
66

7-
#undef CRTDLL
8-
#ifndef _DLL
9-
#define _DLL
10-
#endif
11-
12-
#define SPECIAL_CRTEXE
13-
147
#include <oscalls.h>
158
#include <internal.h>
169
#include <process.h>
@@ -211,9 +204,9 @@ __tmainCRTStartup (void)
211204
{
212205
void *lock_free = NULL;
213206
void *fiberid = ((PNT_TIB)NtCurrentTeb())->StackBase;
214-
int nested = FALSE;
215-
while((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,
216-
fiberid, 0)) != 0)
207+
BOOL nested = FALSE;
208+
while((lock_free = InterlockedCompareExchangePointer (&__native_startup_lock,
209+
fiberid, NULL)) != 0)
217210
{
218211
if (lock_free == fiberid)
219212
{
@@ -242,7 +235,7 @@ __tmainCRTStartup (void)
242235
}
243236
_ASSERTE(__native_startup_state == __initialized);
244237
if (! nested)
245-
(VOID)InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0);
238+
(VOID)InterlockedExchangePointer (&__native_startup_lock, NULL);
246239

247240
if (__dyn_tls_init_callback != NULL)
248241
__dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL);

lib/libc/mingw/crt/crtexewin.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ int _tmain (int __UNUSED_PARAM(argc),
5656

5757
{
5858
STARTUPINFO StartupInfo;
59-
memset (&StartupInfo, 0, sizeof (STARTUPINFO));
6059
GetStartupInfo (&StartupInfo);
6160
if (StartupInfo.dwFlags & STARTF_USESHOWWINDOW)
6261
nShowCmd = StartupInfo.wShowWindow;

lib/libc/mingw/crt/dll_argv.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
55
*/
66

7-
#ifdef CRTDLL
8-
#undef CRTDLL
9-
#endif
10-
117
#include <internal.h>
128

139
extern int _dowildcard;

lib/libc/mingw/crt/dllargv.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
55
*/
66

7-
#ifdef CRTDLL
8-
#undef CRTDLL
9-
#endif
10-
117
#include <internal.h>
128

139
int __CRTDECL

lib/libc/mingw/crt/natstart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
_PGLOBAL
1111
volatile unsigned int __native_dllmain_reason = UINT_MAX;
1212
volatile unsigned int __native_vcclrit_reason = UINT_MAX;
13-
volatile __enative_startup_state __native_startup_state;
14-
volatile void *__native_startup_lock;
13+
volatile __enative_startup_state __native_startup_state = __uninitialized;
14+
void *volatile __native_startup_lock = NULL;

lib/libc/mingw/crt/tlssup.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
* Written by Kai Tietz <kai.tietz@onevision.com>
77
*/
88

9-
#ifdef CRTDLL
10-
#undef CRTDLL
11-
#endif
12-
139
#include <sect_attribs.h>
1410

1511
#ifndef WIN32_LEAN_AND_MEAN

lib/libc/mingw/gdtoa/strtodnrp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ double __cdecl
8585
__mingw_strtod (const char * __restrict__ src, char ** __restrict__ endptr)
8686
__attribute__((alias("__strtod")));
8787

88-
#if !(defined(_AMD64_) || defined(__x86_64__) || \
89-
defined(_X86_) || defined(__i386__))
88+
#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
9089
/* For systems other than x86, where long double == double, provide the
9190
* long double functions as aliases to __strtod. */
9291

lib/libc/mingw/gdtoa/strtopx.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,19 @@ THIS SOFTWARE.
5353
#define _4 0
5454
#endif
5555

56+
#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
57+
/* For ARM, where long double == double, provide the long double function as
58+
* an alias for __strtod. Do this in a separate object file from other
59+
* functions, to avoid linker conflicts if object files import both 'strtold'
60+
* from libucrt*.a and the object file providing '__strtod'. */
61+
long double __cdecl
62+
strtold (const char * __restrict__ src, char ** __restrict__ endptr)
63+
{
64+
return __mingw_strtod(src, endptr);
65+
}
66+
5667
/* This is specific to the x86 80 bit long doubles. */
57-
#if defined(_AMD64_) || defined(__x86_64__) || \
68+
#elif defined(_AMD64_) || defined(__x86_64__) || \
5869
defined(_X86_) || defined(__i386__)
5970

6071
typedef union lD {
@@ -133,14 +144,4 @@ long double __cdecl
133144
strtold (const char * __restrict__ src, char ** __restrict__ endptr)
134145
__attribute__((alias("__strtold")));
135146

136-
#elif defined(__arm__) || defined(__aarch64__) || defined(_ARM_) || defined(_ARM64_)
137-
/* For ARM, where long double == double, provide the long double function as
138-
* an alias for __strtod. Do this in a separate object file from other
139-
* functions, to avoid linker conflicts if object files import both 'strtold'
140-
* from libucrt*.a and the object file providing '__strtod'. */
141-
long double __cdecl
142-
strtold (const char * __restrict__ src, char ** __restrict__ endptr)
143-
{
144-
return __mingw_strtod(src, endptr);
145-
}
146147
#endif

0 commit comments

Comments
 (0)