crt: Provide __p__winver() function also for ARM msvcrt.dll import library

ARM32 and ARM64 OS system version of msvcrt.dll do not have neither _winver
global variable, nor __p__winver() function. But they have _winmajor and
_winminor global variables.

Provide __p__winver() function emulation for ARM msvcrt import library via
via values of _winmajor and _winminor global variables.

Signed-off-by: Martin Storsjö <martin@martin.st>
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 2d19185..a6488f8 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -540,6 +540,7 @@
   misc/__p__wcmdln.c \
   misc/__p__winmajor.c \
   misc/__p__winminor.c \
+  misc/__p__winver.c \
   misc/__p__wpgmptr.c \
   misc/_getpid.c \
   misc/__initenv.c \
@@ -653,6 +654,7 @@
   misc/__p__wcmdln.c \
   misc/__p__winmajor.c \
   misc/__p__winminor.c \
+  misc/__p__winver.c \
   misc/__p__wpgmptr.c \
   misc/_getpid.c \
   misc/__initenv.c \
diff --git a/mingw-w64-crt/lib-common/msvcrt.def.in b/mingw-w64-crt/lib-common/msvcrt.def.in
index 63be398..51e1425 100644
--- a/mingw-w64-crt/lib-common/msvcrt.def.in
+++ b/mingw-w64-crt/lib-common/msvcrt.def.in
@@ -494,7 +494,7 @@
 F_I386(__p__wenviron) ; x64 __p__wenviron provided by emu
 F_I386(__p__winmajor) ; x64, arm32 and arm64 __p__winmajor provided by emu
 F_I386(__p__winminor) ; x64, arm32 and arm64 __p__winminor provided by emu
-F_I386(__p__winver) ; x64 __p__winver provided by emu
+F_I386(__p__winver) ; x64, arm32 and arm64 __p__winver provided by emu
 F_I386(__p__wpgmptr) ; x64, arm32 and arm64 __p__wpgmptr provided by emu
 __pioinfo DATA
 __pxcptinfoptrs
diff --git a/mingw-w64-crt/misc/__p__winver.c b/mingw-w64-crt/misc/__p__winver.c
index 40f65b4..6bcc430 100644
--- a/mingw-w64-crt/misc/__p__winver.c
+++ b/mingw-w64-crt/misc/__p__winver.c
@@ -6,6 +6,33 @@
 
 #include <_mingw.h>
 
+#if defined(__arm__) || defined(__aarch64__) || defined(_ARM_) || defined(_ARM64_)
+
+/*
+ * ARM versions of msvcrt.dll do not provide _winver global variable, so emulate
+ * __p__winver() pointer via private variable and fill _winver variable value
+ * from _winmajor and _winminor global variables. All ARM versions provide
+ * _winmajor and _winminor global variables, but do not provide __p__winmajor()
+ * and __p__winminor() functions. To avoid referencing mingw-w64 emulations of
+ * these __p_ functions, access global variables directly.
+ */
+
+extern unsigned int* __MINGW_IMP_SYMBOL(_winmajor);
+extern unsigned int* __MINGW_IMP_SYMBOL(_winminor);
+
+static unsigned int _winver;
+
+unsigned int* __cdecl __p__winver(void);
+unsigned int* __cdecl __p__winver(void)
+{
+    if (!_winver)
+        _winver = (*__MINGW_IMP_SYMBOL(_winmajor) << 8) | *__MINGW_IMP_SYMBOL(_winminor);
+    return &_winver;
+}
+unsigned int* (__cdecl *__MINGW_IMP_SYMBOL(__p__winver))(void) = __p__winver;
+
+#else
+
 extern unsigned int* __MINGW_IMP_SYMBOL(_winver);
 
 unsigned int* __cdecl __p__winver(void);
@@ -14,3 +41,5 @@
     return __MINGW_IMP_SYMBOL(_winver);
 }
 unsigned int* (__cdecl *__MINGW_IMP_SYMBOL(__p__winver))(void) = __p__winver;
+
+#endif