WinMain() entry point provided by the application is called by mingw-w64
startup code, more precisely by function main() from crtexewin.c file.

mingw-w64 startup code in file crtexewin.c calls _ismbblead() function.
Function _ismbblead() is not available in some versions of crtdll.dll
and is completely missing in msvcrt10.dll library.

Version of crtdll.dll library stored in its PE resource directory is not
meaningful as two different libraries, one with _ismbblead symbol and one
without _ismbblead symbol has same version.

Seems that there are MBCS aware crtdll.dll versions with _ismbblead symbol
and versions which are not MBCS aware without _ismbblead symbol.

All checked msvcrt10.dll files do not have _ismbblead symbols, so
msvcrt10.dll is not MBCS awre.

For msvcrt10.dll import library provides simple dummy _ismbblead() function
which always returns false to satisfy mingw-w64 startup file crtexewin.c.

For crtdll.dll import library provides _ismbblead() wrapper function and
disable the real function in the def file to prevent symbol conflicts. The
wrapper function via GetProcAddress() checks if the real crtdll.dll
provides _ismbblead() function. If real function exists then it is called.
If not then wrapper function returns false like the msvcrt10.dll one.

This fixes linking WinMain() entry point with msvcrt10.dll.

  ld: /usr/local/lib/libmingw32.a(lib32_libmingw32_a-crtexewin.o): in function 
`main':
  mingw-w64/mingw-w64-crt/crt/crtexewin.c:43: undefined reference to 
`_ismbblead'
  collect2: error: ld returned 1 exit status

And fixes runtime error about missing _ismbblead symbol with some versions of 
crtdll.dll.

  Entry Point Not Found
  The procedure entry point _ismbblead could not be located in the
  dynamic link library CRTDLL.dll.
---
 mingw-w64-crt/Makefile.am              |  2 ++
 mingw-w64-crt/crt/crtdll_ismbblead.c   | 45 ++++++++++++++++++++++++++
 mingw-w64-crt/crt/msvcrt10_ismbblead.c | 14 ++++++++
 mingw-w64-crt/lib32/crtdll.def.in      |  2 +-
 4 files changed, 62 insertions(+), 1 deletion(-)
 create mode 100644 mingw-w64-crt/crt/crtdll_ismbblead.c
 create mode 100644 mingw-w64-crt/crt/msvcrt10_ismbblead.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 21fc94605207..6b9f5f7b0f77 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -575,6 +575,7 @@ src_msvcrtarm64=\
 
 src_crtdll=\
   crt/crtdll_getmainargs.c \
+  crt/crtdll_ismbblead.c \
   math/x86/_copysignf.c \
   misc/___mb_cur_max_func.c \
   misc/__initenv.c \
@@ -599,6 +600,7 @@ src_crtdll=\
 
 src_msvcrt10=\
   crt/crtdll_getmainargs.c \
+  crt/msvcrt10_ismbblead.c \
   misc/___mb_cur_max_func.c \
   misc/__initenv.c \
   misc/__p___argv.c \
diff --git a/mingw-w64-crt/crt/crtdll_ismbblead.c 
b/mingw-w64-crt/crt/crtdll_ismbblead.c
new file mode 100644
index 000000000000..4854c43bf20d
--- /dev/null
+++ b/mingw-w64-crt/crt/crtdll_ismbblead.c
@@ -0,0 +1,45 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <internal.h>
+#include <windows.h>
+
+/**
+ * Implementation of _ismbblead() function called by crtexewin.c startup code
+ * for crtdll.dll library which in some versions does not contain this 
function.
+ */
+
+static int __cdecl emu_ismbblead(unsigned int __UNUSED_PARAM(_C))
+{
+    /* Fallback implementation for crtdll.dll version which is not MBCS aware. 
*/
+    return 0;
+}
+
+static int __cdecl init_ismbblead(unsigned int _C);
+
+int (__cdecl *__MINGW_IMP_SYMBOL(_ismbblead))(unsigned int _C) = 
init_ismbblead;
+
+static int __cdecl init_ismbblead(unsigned int _C)
+{
+    HMODULE crtdll;
+    int (__cdecl *func)(unsigned int _C) = NULL;
+
+    crtdll = GetModuleHandleA("crtdll.dll");
+
+    if (crtdll)
+        func = (int (__cdecl *)(unsigned int _C))GetProcAddress(crtdll, 
"_ismbblead");
+
+    if (!func)
+        func = emu_ismbblead;
+
+    return (__MINGW_IMP_SYMBOL(_ismbblead) = func)(_C);
+}
+
+int __cdecl _ismbblead(unsigned int _C);
+int __cdecl _ismbblead(unsigned int _C)
+{
+    return __MINGW_IMP_SYMBOL(_ismbblead)(_C);
+}
diff --git a/mingw-w64-crt/crt/msvcrt10_ismbblead.c 
b/mingw-w64-crt/crt/msvcrt10_ismbblead.c
new file mode 100644
index 000000000000..e38fe439d1c2
--- /dev/null
+++ b/mingw-w64-crt/crt/msvcrt10_ismbblead.c
@@ -0,0 +1,14 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <internal.h>
+
+/**
+ * Implementation of _ismbblead() function called by crtexewin.c startup code
+ * for msvcrt10.dll library which does not contain this function and is not 
MBCS aware.
+ */
+int __cdecl _ismbblead(unsigned int _C);
+int __cdecl _ismbblead(unsigned int __UNUSED_PARAM(_C)) { return 0; }
diff --git a/mingw-w64-crt/lib32/crtdll.def.in 
b/mingw-w64-crt/lib32/crtdll.def.in
index 57e722b9d22a..068a285ccebd 100644
--- a/mingw-w64-crt/lib32/crtdll.def.in
+++ b/mingw-w64-crt/lib32/crtdll.def.in
@@ -227,7 +227,7 @@ _ismbbgraph
 _ismbbkalnum
 _ismbbkana
 _ismbbkpunct
-_ismbblead
+; _ismbblead is replaced by emu
 _ismbbprint
 _ismbbpunct
 _ismbbtrail
-- 
2.20.1



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

Reply via email to