From be79ec008e8ef292fa1e770d2e87bcb40861f3ea Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Mon, 29 Apr 2019 05:42:36 +0000 Subject: [PATCH] libphobos: Backport minimal MinGW support patches. Merges upstream druntime 1ca80e4e, phobos b5e9661a0. Reviewed-on: https://github.com/dlang/druntime/pull/2587 https://github.com/dlang/phobos/pull/6981 From-SVN: r270638 --- libphobos/libdruntime/MERGE | 2 +- libphobos/libdruntime/core/stdc/stdio.d | 48 ++++++++------------ libphobos/libdruntime/core/sys/windows/dll.d | 4 +- libphobos/libdruntime/core/thread.d | 17 ++++--- libphobos/libdruntime/rt/dmain2.d | 10 +++- libphobos/src/MERGE | 2 +- libphobos/src/std/math.d | 14 ++++-- 7 files changed, 53 insertions(+), 44 deletions(-) diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE index d815647f969..d947097ec65 100644 --- a/libphobos/libdruntime/MERGE +++ b/libphobos/libdruntime/MERGE @@ -1,4 +1,4 @@ -e03164b5259a9f116eb91dfa5a18c192fa72e575 +1ca80e4e0cf460575752a0c157ca52c184f4b982 The first line of this file holds the git revision number of the last merge done from the dlang/druntime repository. diff --git a/libphobos/libdruntime/core/stdc/stdio.d b/libphobos/libdruntime/core/stdc/stdio.d index 6ce3f9d13e5..3cdfa6a4ac5 100644 --- a/libphobos/libdruntime/core/stdc/stdio.d +++ b/libphobos/libdruntime/core/stdc/stdio.d @@ -1291,35 +1291,7 @@ size_t fwrite(scope const void* ptr, size_t size, size_t nmemb, FILE* stream); c_long ftell(FILE* stream); } -version (MinGW) -{ - // No unsafe pointer manipulation. - extern (D) @trusted - { - /// - void rewind()(FILE* stream) { fseek(stream,0L,SEEK_SET); stream._flag = stream._flag & ~_IOERR; } - /// - pure void clearerr()(FILE* stream) { stream._flag = stream._flag & ~(_IOERR|_IOEOF); } - /// - pure int feof()(FILE* stream) { return stream._flag&_IOEOF; } - /// - pure int ferror()(FILE* stream) { return stream._flag&_IOERR; } - } - /// - int __mingw_snprintf(scope char* s, size_t n, scope const char* fmt, ...); - /// - alias __mingw_snprintf _snprintf; - /// - alias __mingw_snprintf snprintf; - - /// - int __mingw_vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg); - /// - alias __mingw_vsnprintf _vsnprintf; - /// - alias __mingw_vsnprintf vsnprintf; -} -else version (CRuntime_DigitalMars) +version (CRuntime_DigitalMars) { // No unsafe pointer manipulation. extern (D) @trusted @@ -1362,6 +1334,23 @@ else version (CRuntime_Microsoft) pure int fileno(FILE* stream); } + version (MinGW) + { + int __mingw_snprintf(scope char* s, size_t n, scope const char* fmt, ...); + /// + alias __mingw_snprintf _snprintf; + /// + alias __mingw_snprintf snprintf; + + /// + int __mingw_vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg); + /// + alias __mingw_vsnprintf _vsnprintf; + /// + alias __mingw_vsnprintf vsnprintf; + } + else + { /// int _snprintf(scope char* s, size_t n, scope const char* format, ...); /// @@ -1371,6 +1360,7 @@ else version (CRuntime_Microsoft) int _vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg); /// int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg); + } /// int _fputc_nolock(int c, FILE *fp); diff --git a/libphobos/libdruntime/core/sys/windows/dll.d b/libphobos/libdruntime/core/sys/windows/dll.d index 3d6a15c834c..c3c4db37c42 100644 --- a/libphobos/libdruntime/core/sys/windows/dll.d +++ b/libphobos/libdruntime/core/sys/windows/dll.d @@ -328,7 +328,9 @@ public: */ bool dll_fixTLS( HINSTANCE hInstance, void* tlsstart, void* tlsend, void* tls_callbacks_a, int* tlsindex ) nothrow { - version (Win64) + version (GNU_EMUTLS) + return true; + else version (Win64) return true; // fixed else version (Win32) { diff --git a/libphobos/libdruntime/core/thread.d b/libphobos/libdruntime/core/thread.d index 3d2cd287a2e..3e9802d7dc6 100644 --- a/libphobos/libdruntime/core/thread.d +++ b/libphobos/libdruntime/core/thread.d @@ -49,9 +49,17 @@ version (Solaris) import core.sys.solaris.sys.types; } -// this should be true for most architectures -version (GNU_StackGrowsDown) +version (GNU) +{ + import gcc.builtins; + version (GNU_StackGrowsDown) + version = StackGrowsDown; +} +else +{ + // this should be true for most architectures version = StackGrowsDown; +} /** * Returns the process ID of the calling process, which is guaranteed to be @@ -301,11 +309,6 @@ else version (Posix) import core.sys.darwin.pthread : pthread_mach_thread_np; } - version (GNU) - { - import gcc.builtins; - } - // // Entry point for POSIX threads // diff --git a/libphobos/libdruntime/rt/dmain2.d b/libphobos/libdruntime/rt/dmain2.d index f45565c971a..32635c460b3 100644 --- a/libphobos/libdruntime/rt/dmain2.d +++ b/libphobos/libdruntime/rt/dmain2.d @@ -340,7 +340,15 @@ extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc) version (CRuntime_Microsoft) { // enable full precision for reals - version (Win64) + version (GNU) + { + size_t fpu_cw; + asm { "fstcw %0" : "=m" (fpu_cw); } + fpu_cw |= 0b11_00_111111; // 11: use 64 bit extended-precision + // 111111: mask all FP exceptions + asm { "fldcw %0" : "=m" (fpu_cw); } + } + else version (Win64) asm { push RAX; diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE index e4807fbf437..685b4e65d24 100644 --- a/libphobos/src/MERGE +++ b/libphobos/src/MERGE @@ -1,4 +1,4 @@ -b538f758a4d274b64751f80564b0207845cd018c +b5e9661a089b6514e01fa5195c0f2bc9cc06eddd The first line of this file holds the git revision number of the last merge done from the dlang/phobos repository. diff --git a/libphobos/src/std/math.d b/libphobos/src/std/math.d index 6dec9cee9a0..062b57035ca 100644 --- a/libphobos/src/std/math.d +++ b/libphobos/src/std/math.d @@ -174,6 +174,12 @@ else version (D_InlineAsm_X86_64) version = InlineAsm_X86_Any; } +version (CRuntime_Microsoft) +{ + version (InlineAsm_X86_Any) + version = MSVC_InlineAsm; +} + version (X86_64) version = StaticallyHaveSSE; version (X86) version (OSX) version = StaticallyHaveSSE; @@ -3692,7 +3698,7 @@ real logb(real x) @trusted nothrow @nogc ret ; } } - else version (CRuntime_Microsoft) + else version (MSVC_InlineAsm) { asm pure nothrow @nogc { @@ -3979,7 +3985,7 @@ real ceil(real x) @trusted pure nothrow @nogc ret ; } } - else version (CRuntime_Microsoft) + else version (MSVC_InlineAsm) { short cw; asm pure nothrow @nogc @@ -4107,7 +4113,7 @@ real floor(real x) @trusted pure nothrow @nogc ret ; } } - else version (CRuntime_Microsoft) + else version (MSVC_InlineAsm) { short cw; asm pure nothrow @nogc @@ -4607,7 +4613,7 @@ real trunc(real x) @trusted nothrow @nogc ret ; } } - else version (CRuntime_Microsoft) + else version (MSVC_InlineAsm) { short cw; asm pure nothrow @nogc -- 2.30.2