Re: [Mingw-w64-public] [PATCH] ctime inline wrapper is also needed for msvcrt 0x1200

2019-03-08 Thread Johannes Pfau


Am 08.03.19 um 22:27 schrieb Johannes Pfau:

Am 07.03.19 um 15:48 schrieb Liu Hao:

在 2019/3/7 17:45, Jacek Caban 写道:

Note that when doing 32-bit builds, _USE_32BIT_TIME_T will be most
likely defined so this code path will not be used. Currently (although
it might be improved in the future), one has to define
__MINGW_USE_VC2005_COMPAT to use 64-bit time_t, and it's the only 
config

that would break on XP.


Current code, instead of load failure, will call a function with wrong
arguments and will likely corrupt stack. I don't think that's something
we want to preserve. If we really want to support this case properly,
we'd need _mkgmtime64 compat implementation inside libmsvcrt.a.



Indeed, the actual `ctime()` etc. exported from the DLL are always
32-bit or 64-bit, so we can't support both without tampering with the
source code rather than the library.

I pushed these three patches.


Thanks a lot! I can confirm that this fixes the GCC bootstrap problems.


Sorry, this was supposed to go to the mailing list


Best regards,

Johannes



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] ctime inline wrapper is also needed for msvcrt 0x1200

2019-03-07 Thread Liu Hao
在 2019/3/7 17:45, Jacek Caban 写道:
> Note that when doing 32-bit builds, _USE_32BIT_TIME_T will be most
> likely defined so this code path will not be used. Currently (although
> it might be improved in the future), one has to define
> __MINGW_USE_VC2005_COMPAT to use 64-bit time_t, and it's the only config
> that would break on XP.
> 
> 
> Current code, instead of load failure, will call a function with wrong
> arguments and will likely corrupt stack. I don't think that's something
> we want to preserve. If we really want to support this case properly,
> we'd need _mkgmtime64 compat implementation inside libmsvcrt.a.
> 
> 

Indeed, the actual `ctime()` etc. exported from the DLL are always
32-bit or 64-bit, so we can't support both without tampering with the
source code rather than the library.

I pushed these three patches.


-- 
Best regards,
LH_Mouse



signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] ctime inline wrapper is also needed for msvcrt 0x1200

2019-03-07 Thread Jacek Caban


On 07/03/2019 03:22, Liu Hao wrote:

在 2019/3/7 上午5:11, Martin Storsjö 写道:

On Wed, 6 Mar 2019, Jacek Caban wrote:


It exists in msvcrt.dll that I checked (I think it's from win10). The
patch looks good to me.

_mkgmtime64 appeared in msvcrt.dll in Vista, it's missing in XP.

// Martin

I think it might be safer to keep the condition but have 0x1200 in place
of 0x1400.



Note that when doing 32-bit builds, _USE_32BIT_TIME_T will be most 
likely defined so this code path will not be used. Currently (although 
it might be improved in the future), one has to define 
__MINGW_USE_VC2005_COMPAT to use 64-bit time_t, and it's the only config 
that would break on XP.



Current code, instead of load failure, will call a function with wrong 
arguments and will likely corrupt stack. I don't think that's something 
we want to preserve. If we really want to support this case properly, 
we'd need _mkgmtime64 compat implementation inside libmsvcrt.a.



Jacek



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] ctime inline wrapper is also needed for msvcrt 0x1200

2019-03-06 Thread Liu Hao
在 2019/3/7 上午5:11, Martin Storsjö 写道:
> On Wed, 6 Mar 2019, Jacek Caban wrote:
> 
>>
>> It exists in msvcrt.dll that I checked (I think it's from win10). The
>> patch looks good to me.
> 
> _mkgmtime64 appeared in msvcrt.dll in Vista, it's missing in XP.
> 
> // Martin

I think it might be safer to keep the condition but have 0x1200 in place
of 0x1400.

-- 
Best regards,
LH_Mouse



signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] ctime inline wrapper is also needed for msvcrt 0x1200

2019-03-06 Thread Jacek Caban

On 3/6/19 3:53 PM, Liu Hao wrote:

在 2019/3/6 22:44, Jacek Caban 写道:

Looks good to me, but it needs msvcrt.def.in adjustment first.
_mkgmtime64 is not available on i386, but it should.



An additional patch has been attached.

But anyway, I think these conditions existed for a reason. I can verify
that they all exist on my Win7, but I am not sure whether they exist
elsewhere.



It exists in msvcrt.dll that I checked (I think it's from win10). The 
patch looks good to me.



Thanks,

Jacek



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] ctime inline wrapper is also needed for msvcrt 0x1200

2019-03-06 Thread Liu Hao
在 2019/3/6 22:44, Jacek Caban 写道:
> Looks good to me, but it needs msvcrt.def.in adjustment first.
> _mkgmtime64 is not available on i386, but it should.
> 
>

An additional patch has been attached.

But anyway, I think these conditions existed for a reason. I can verify
that they all exist on my Win7, but I am not sure whether they exist
elsewhere.


-- 
Best regards,
LH_Mouse
From 5e7a3a990407cbd0d51c226d13dcff724e2d1958 Mon Sep 17 00:00:00 2001
From: Liu Hao 
Date: Wed, 6 Mar 2019 22:50:23 +0800
Subject: [PATCH] crt/msvcrt.def.in: Always declare `_mkgmtime{32,64}`.

Signed-off-by: Liu Hao 
---
 mingw-w64-crt/lib-common/msvcrt.def.in | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/mingw-w64-crt/lib-common/msvcrt.def.in 
b/mingw-w64-crt/lib-common/msvcrt.def.in
index 13115412..449beb0a 100644
--- a/mingw-w64-crt/lib-common/msvcrt.def.in
+++ b/mingw-w64-crt/lib-common/msvcrt.def.in
@@ -869,9 +869,8 @@ _memicmp
 _memicmp_l
 _mkdir
 _mkgmtime
-F_I386(_mkgmtime32)
-F_ARM_ANY(_mkgmtime32)
-F_NON_I386(_mkgmtime64)
+_mkgmtime32
+_mkgmtime64
 _mktemp
 ; _mktemp_s replaced by emu
 F_I386(_mktime32 == mktime)
-- 
2.21.0

___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] ctime inline wrapper is also needed for msvcrt 0x1200

2019-03-06 Thread Liu Hao
在 2019/3/4 22:54, Jacek Caban 写道:
> Hi Johannes,
> 
> On 3/3/19 2:48 PM, Johannes Pfau wrote:
>> When building GCC for msvcrt120, there's a undefined reference to
>> ctime. It needs to be defined as a wrapper for msvcrt120 as well.
>> The if condition is slightly complex, but I do not know if I can
>> modify the if !defined(__CRT__NO_INLINE) || __MSVCRT_VERSION__ >= 0x1400
>> block instead: This would also change difftime, localtime and so on and
>> I'm not sure if these should be changed.
> 
> 
> I think we should have a single place with inline wrappers for all
> versions. Even plain msvcrt.dll could use such inline wrapper. I'd
> suggest to move UCRT variant out of #ifdef f__MSVCRT_VERSION__ instead.
> 
> 

Do the attached patches look okay?

-- 
Best regards,
LH_Mouse
From 6680efafce500453a68276108d166c034eb8dc53 Mon Sep 17 00:00:00 2001
From: Liu Hao 
Date: Wed, 6 Mar 2019 22:30:38 +0800
Subject: [PATCH 1/2] crt/time.h: Always provide overridden time functions,
 even for MSVCRT.

Signed-off-by: Liu Hao 
---
 mingw-w64-headers/crt/time.h | 12 
 1 file changed, 12 deletions(-)

diff --git a/mingw-w64-headers/crt/time.h b/mingw-w64-headers/crt/time.h
index 73f6264a..447c6b03 100644
--- a/mingw-w64-headers/crt/time.h
+++ b/mingw-w64-headers/crt/time.h
@@ -214,18 +214,7 @@ extern "C" {
 #endif
 
 #ifndef RC_INVOKED
-#if __MSVCRT_VERSION__ < 0x1400
-double __cdecl difftime(time_t _Time1,time_t _Time2);
-char *__cdecl ctime(const time_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-struct tm *__cdecl gmtime(const time_t *_Time) 
__MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-struct tm *__cdecl localtime(const time_t *_Time) 
__MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-
-time_t __cdecl mktime(struct tm *_Tm);
-time_t __cdecl _mkgmtime(struct tm *_Tm);
-time_t __cdecl time(time_t *_Time);
-#endif
 
-#if !defined(__CRT__NO_INLINE) || __MSVCRT_VERSION__ >= 0x1400
 #if __MSVCRT_VERSION__ >= 0x1400
 #define __TIME_INLINE __mingw_static_ovr
 #else
@@ -250,7 +239,6 @@ __TIME_INLINE struct tm *__cdecl gmtime(const time_t 
*_Time) { return _gmtime32(
 __TIME_INLINE time_t __cdecl _mkgmtime(struct tm *_Tm) { return 
_mkgmtime32(_Tm); }
 __TIME_INLINE time_t __cdecl time(time_t *_Time) { return _time32(_Time); }
 #endif /* !_USE_32BIT_TIME_T */
-#endif /* !__CRT__NO_INLINE */
 
 #ifdef _USE_32BIT_TIME_T
 __forceinline errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) 
{ return _localtime32_s(_Tm,_Time); }
-- 
2.21.0

From 50a771fda5c9924b7bfb6ab7349cb4a661612dc8 Mon Sep 17 00:00:00 2001
From: Liu Hao 
Date: Wed, 6 Mar 2019 22:31:33 +0800
Subject: [PATCH 2/2] crt/time.h: Adjust a blank line.

Signed-off-by: Liu Hao 
---
 mingw-w64-headers/crt/time.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mingw-w64-headers/crt/time.h b/mingw-w64-headers/crt/time.h
index 447c6b03..f0a83797 100644
--- a/mingw-w64-headers/crt/time.h
+++ b/mingw-w64-headers/crt/time.h
@@ -244,12 +244,12 @@ __TIME_INLINE time_t __cdecl time(time_t *_Time) { return 
_time32(_Time); }
 __forceinline errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) 
{ return _localtime32_s(_Tm,_Time); }
 __forceinline errno_t __cdecl gmtime_s(struct tm *_Tm, const time_t *_Time)   
{ return _gmtime32_s(_Tm, _Time); }
 __forceinline errno_t __cdecl ctime_s(char *_Buf,size_t _SizeInBytes,const 
time_t *_Time) { return _ctime32_s(_Buf,_SizeInBytes,_Time); }
-
 #else
 __forceinline errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) 
{ return _localtime64_s(_Tm,_Time); }
 __forceinline errno_t __cdecl gmtime_s(struct tm *_Tm, const time_t *_Time) { 
return _gmtime64_s(_Tm, _Time); }
 __forceinline errno_t __cdecl ctime_s(char *_Buf,size_t _SizeInBytes,const 
time_t *_Time) { return _ctime64_s(_Buf,_SizeInBytes,_Time); }
 #endif
+
 #endif /* !RC_INVOKED */
 
 #if !defined(NO_OLDNAMES) || defined(_POSIX)
-- 
2.21.0

___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] ctime inline wrapper is also needed for msvcrt 0x1200

2019-03-04 Thread Liu Hao
在 2019/3/3 21:48, Johannes Pfau 写道:
> When building GCC for msvcrt120, there's a undefined reference to
> ctime. It needs to be defined as a wrapper for msvcrt120 as well.
> The if condition is slightly complex, but I do not know if I can
> modify the if !defined(__CRT__NO_INLINE) || __MSVCRT_VERSION__ >= 0x1400
> block instead: This would also change difftime, localtime and so on and
> I'm not sure if these should be changed.
> 
> Best regards,
> Johannes
> 
> ---
>  mingw-w64-headers/crt/time.h | 12 +++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 

>  
> +#if defined(__CRT__NO_INLINE) && __MSVCRT_VERSION__ >= 0x1200 && 
> __MSVCRT_VERSION__ < 0x1400

At my first glance I thought the `defined(__CRT__NO_INLINE)` was wrong -
it isn't. It is necessary there to prevent a duplicate definition when
`__CRT__NO_INLINE` is defined.

However, this results in consistency, which would be eliminated by
removing the original inline definitions, just like what you did with
the declaration. The condition would be simplified as a consistent
`#if !defined(__CRT__NO_INLINE) || __MSVCRT_VERSION__ >= 0x1200`
thereafter.


> +#if !defined(_USE_32BIT_TIME_T)
> +__mingw_static_ovr char *__cdecl ctime(const time_t *_Time) { return 
> _ctime64(_Time); }
> +#else
> +__mingw_static_ovr char *__cdecl ctime(const time_t *_Time) { return 
> _ctime32(_Time); }
> +#endif
> +#endif
> +
>  #ifdef _USE_32BIT_TIME_T
>  __forceinline errno_t __cdecl localtime_s(struct tm *_Tm,const time_t 
> *_Time) { return _localtime32_s(_Tm,_Time); }
>  __forceinline errno_t __cdecl gmtime_s(struct tm *_Tm, const time_t *_Time)  
>  { return _gmtime32_s(_Tm, _Time); }
> 


-- 
Best regards,
LH_Mouse



signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] ctime inline wrapper is also needed for msvcrt 0x1200

2019-03-04 Thread Jacek Caban

Hi Johannes,

On 3/3/19 2:48 PM, Johannes Pfau wrote:

When building GCC for msvcrt120, there's a undefined reference to
ctime. It needs to be defined as a wrapper for msvcrt120 as well.
The if condition is slightly complex, but I do not know if I can
modify the if !defined(__CRT__NO_INLINE) || __MSVCRT_VERSION__ >= 0x1400
block instead: This would also change difftime, localtime and so on and
I'm not sure if these should be changed.



I think we should have a single place with inline wrappers for all 
versions. Even plain msvcrt.dll could use such inline wrapper. I'd 
suggest to move UCRT variant out of #ifdef f__MSVCRT_VERSION__ instead.



Thanks,

Jacek



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public