Import library libcrtdll.a (for crtdll.dll runtime library) compiled during
mingw-w64 build process is currently broken and cannot be used for linking
executable applications.
Trying to do it results in following linker errors:
/usr/bin/i686-w64-mingw32-ld: .../i686-w64-mingw32/lib/crt2.o: in function
`pre_c_init':
.../mingw-w64-crt/crt/crtexe.c:142: undefined reference to `__set_app_type'
/usr/bin/i686-w64-mingw32-ld: .../mingw-w64-crt/crt/crtexe.c:146: undefined
reference to `__p__fmode'
/usr/bin/i686-w64-mingw32-ld: .../mingw-w64-crt/crt/crtexe.c:144: undefined
reference to `__set_app_type'
/usr/bin/i686-w64-mingw32-ld: .../i686-w64-mingw32/lib/crt2.o: in function
`pre_cpp_init':
.../mingw-w64-crt/crt/crtexe.c:173: undefined reference to `__getmainargs'
/usr/bin/i686-w64-mingw32-ld: .../i686-w64-mingw32/lib/crt2.o: in function
`_tmainCRTStartup':
.../mingw-w64-crt/crt/crtexe.c:290: undefined reference to
`_set_invalid_parameter_handler'
/usr/bin/i686-w64-mingw32-ld: .../mingw-w64-crt/crt/crtexe.c:299: undefined
reference to `__p__acmdln'
/usr/bin/i686-w64-mingw32-ld: .../mingw-w64-crt/crt/crtexe.c:337: undefined
reference to `_imp____initenv'
/usr/bin/i686-w64-mingw32-ld:
.../i686-w64-mingw32/lib/libmingw32.a(lib32_libmingw32_a-charmax.o): in
function `my_lconv_init':
.../mingw-w64-crt/crt/charmax.c:19: undefined reference to
`_imp____lconv_init'
/usr/bin/i686-w64-mingw32-ld:
.../i686-w64-mingw32/lib/libmingw32.a(lib32_libmingw32_a-merr.o): in function
`_mingw_setusermatherr':
.../mingw-w64-crt/crt/merr.c:33: undefined reference to `__setusermatherr'
/usr/bin/i686-w64-mingw32-ld:
.../i686-w64-mingw32/lib/libmingwex.a(lib32_libmingwex_a-getopt.o): in function
`vwarnx':
.../mingw-w64-crt/misc/getopt.c:119: undefined reference to `__p___argv'
Reason is that this crtdll.dll library has some symbols with _dll suffix as
opposite of the msvcrt.dll library which has it without any suffix.
mingw-w64 startup code expects that these symbols are without any suffix
too. And some symbols are not present in crtdll.dll at all.
Most required functions are already provided by mingw-w64 in misc/
subdirectory and they are already linked into msvcrt import library.
But they are compiled into into crtdll import library yet.
This patch fixes all thse issues. Add required misc/ files into import
library and adds a new helper file crtdll_32_compat.c with all required
symbols for mingw-w64 startup and links it into libcrtdll.a import library.
This allows to produce working 32-bit executable binaries by
i686-w64-mingw32-gcc compiler and mingw-w64 which will use crtdll.dll
runtime library.
---
mingw-w64-crt/Makefile.am | 18 ++++-
mingw-w64-crt/crt/crtdll_32_compat.c | 100 +++++++++++++++++++++++++++
mingw-w64-crt/lib-common/crtdll.mri | 1 +
3 files changed, 117 insertions(+), 2 deletions(-)
create mode 100644 mingw-w64-crt/crt/crtdll_32_compat.c
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index e6b644ec1d44..7a1e0e8c5955 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -411,6 +411,18 @@ src_msvcr80_64=\
misc/__p__fmode.c \
misc/__p__wcmdln.c
+src_crtdll_32=\
+ crt/crtdll_32_compat.c \
+ misc/___mb_cur_max_func.c \
+ misc/__p___argv.c \
+ misc/__p__acmdln.c \
+ misc/__p__commode.c \
+ misc/__p__fmode.c \
+ misc/__set_app_type.c \
+ misc/invalid_parameter_handler.c \
+ misc/lc_locale_func.c \
+ stdio/mingw_lock.c
+
src_msvcr120_app=\
misc/__set_app_type.c \
misc/_getpid.c
@@ -847,7 +859,7 @@ if !W32API
lib32_DATA += lib32/libglut.a lib32/libmsvcp60.a lib32/libmsvcp120_app.a
lib32_DATA += lib32/libcrtdll.a
-lib32/libcrtdll.a: lib-common/crtdll.mri lib32/libcrtdll_def.a
lib32/libmsvcrt_common.a
+lib32/libcrtdll.a: lib-common/crtdll.mri lib32/libcrtdll_def.a
lib32/libmsvcrt_common.a lib32/libcrtdll_extra.a
cd $(dir $@) && $(AR) -M < $(abspath $<)
lib32_DATA += lib32/libmsvcr80.a
@@ -887,7 +899,9 @@ lib32/libucrtbase.a: lib-common/ucrtbase.mri
lib32/libucrtbase_def.a lib32/libuc
cd $(dir $@) && $(AR) -M < $(abspath $<)
lib32_DATA += lib32/libucrt.a lib32/libucrtapp.a
-noinst_LIBRARIES += lib32/libmsvcrt_common.a lib32/libmsvcrt_extra.a
lib32/libmsvcr120_app_extra.a lib32/libucrt_extra.a lib32/libucrtapp_extra.a
+noinst_LIBRARIES += lib32/libcrtdll_extra.a lib32/libmsvcrt_common.a
lib32/libmsvcrt_extra.a lib32/libmsvcr120_app_extra.a lib32/libucrt_extra.a
lib32/libucrtapp_extra.a
+lib32_libcrtdll_extra_a_SOURCES = $(src_crtdll_32)
+lib32_libcrtdll_extra_a_CPPFLAGS = $(CPPFLAGS32) -D__LIBMSVCRT__
$(extra_include) $(sysincludes)
lib32_libmsvcrt_common_a_SOURCES = $(src_msvcrt_common)
lib32_libmsvcrt_common_a_CPPFLAGS=$(CPPFLAGS32) -D__LIBMSVCRT__
$(extra_include) $(sysincludes)
lib32_libmsvcrt_extra_a_SOURCES = $(src_msvcrt32)
diff --git a/mingw-w64-crt/crt/crtdll_32_compat.c
b/mingw-w64-crt/crt/crtdll_32_compat.c
new file mode 100644
index 000000000000..98ed946a84b5
--- /dev/null
+++ b/mingw-w64-crt/crt/crtdll_32_compat.c
@@ -0,0 +1,100 @@
+/**
+ * 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 <math.h>
+
+/* Define __initenv and __winitenv as crtdll.dll does not provide them */
+static char ** local__initenv;
+static wchar_t ** local__winitenv;
+char *** __MINGW_IMP_SYMBOL(__initenv) = &local__initenv;
+wchar_t *** __MINGW_IMP_SYMBOL(__winitenv) = &local__winitenv;
+
+/* Define dummy __setusermatherr() function as crtdll.dll does not provide it
*/
+#undef __setusermatherr
+void __setusermatherr(__UNUSED_PARAM(int (__cdecl *f)(struct _exception *))) {
}
+
+/* Define dummy _lock() and _unlock() functions as crtdll.dll does not provide
them */
+void __cdecl _lock(int locknum);
+void __cdecl _unlock(int locknum);
+void __cdecl _lock(__UNUSED_PARAM(int locknum)) { }
+void __cdecl _unlock(__UNUSED_PARAM(int locknum)) { }
+
+/* Define __getmainargs() function via crtdll.dll __GetMainArgs() function */
+extern void __GetMainArgs(int *argc, char ***argv, char ***envp, int
expand_wildcards);
+int __cdecl __getmainargs(int *argc, char ***argv, char ***envp, int
expand_wildcards, __UNUSED_PARAM(_startupinfo *startup_info))
+{
+ __GetMainArgs(argc, argv, envp, expand_wildcards);
+ return 0;
+}
+
+/* Define __argc as alias for crtdll.dll __argc_dll variable */
+extern int __argc_dll;
+int *__MINGW_IMP_SYMBOL(__argc) = &__argc_dll;
+
+/* Define __argv as alias for crtdll.dll __argv_dll variable */
+extern char **__argv_dll;
+char ***__MINGW_IMP_SYMBOL(__argv) = &__argv_dll;
+
+/* Define __mb_cur_max as alias for crtdll.dll __mb_cur_max_dll variable */
+extern int __mb_cur_max_dll;
+int *__MINGW_IMP_SYMBOL(__mb_cur_max) = &__mb_cur_max_dll;
+
+/* Define _acmdln as alias for crtdll.dll _acmdln_dll variable */
+extern char *_acmdln_dll;
+char **__MINGW_IMP_SYMBOL(_acmdln) = &_acmdln_dll;
+
+/* Define _commode as alias for crtdll.dll _commode_dll variable */
+extern int _commode_dll;
+int *__MINGW_IMP_SYMBOL(_commode) = &_commode_dll;
+
+/* Define _daylight as alias for crtdll.dll _daylight_dll variable */
+extern int _daylight_dll;
+int *__MINGW_IMP_SYMBOL(_daylight) = &_daylight_dll;
+
+/* Define _environ as alias for crtdll.dll _environ_dll variable */
+extern char **_environ_dll;
+char ***__MINGW_IMP_SYMBOL(_environ) = &_environ_dll;
+
+/* Define _fmode as alias for crtdll.dll _fmode_dll variable */
+extern int _fmode_dll;
+int *__MINGW_IMP_SYMBOL(_fmode) = &_fmode_dll;
+
+/* Define _osver as alias for crtdll.dll _osver_dll variable */
+extern unsigned int _osver_dll;
+unsigned int *__MINGW_IMP_SYMBOL(_osver) = &_osver_dll;
+
+/* Define _pctype as alias for crtdll.dll _pctype_dll variable */
+extern unsigned short *_pctype_dll;
+unsigned short **__MINGW_IMP_SYMBOL(_pctype) = &_pctype_dll;
+
+/* Define _pgmptr as alias for crtdll.dll _pgmptr_dll variable */
+extern char *_pgmptr_dll;
+char **__MINGW_IMP_SYMBOL(_pgmptr) = &_pgmptr_dll;
+
+/* Define _pwctype as alias for crtdll.dll _pwctype_dll variable */
+extern unsigned short *_pwctype_dll;
+unsigned short **__MINGW_IMP_SYMBOL(_pwctype) = &_pwctype_dll;
+
+/* Define _sys_nerr as alias for crtdll.dll _sys_nerr_dll variable */
+extern int _sys_nerr_dll;
+int *__MINGW_IMP_SYMBOL(_sys_nerr) = &_sys_nerr_dll;
+
+/* Define _timezone as alias for crtdll.dll _timezone_dll variable */
+extern long _timezone_dll;
+long *__MINGW_IMP_SYMBOL(_timezone) = &_timezone_dll;
+
+/* Define _winmajor as alias for crtdll.dll _winmajor_dll variable */
+extern unsigned int _winmajor_dll;
+unsigned int *__MINGW_IMP_SYMBOL(_winmajor) = &_winmajor_dll;
+
+/* Define _winminor as alias for crtdll.dll _winminor_dll variable */
+extern unsigned int _winminor_dll;
+unsigned int *__MINGW_IMP_SYMBOL(_winminor) = &_winminor_dll;
+
+/* Define _winver as alias for crtdll.dll _winver_dll variable */
+extern unsigned int _winver_dll;
+unsigned int *__MINGW_IMP_SYMBOL(_winver) = &_winver_dll;
diff --git a/mingw-w64-crt/lib-common/crtdll.mri
b/mingw-w64-crt/lib-common/crtdll.mri
index 7ad3b777b041..8cf2ccf889e3 100644
--- a/mingw-w64-crt/lib-common/crtdll.mri
+++ b/mingw-w64-crt/lib-common/crtdll.mri
@@ -1,5 +1,6 @@
CREATE libcrtdll.a
ADDLIB libcrtdll_def.a
ADDLIB libmsvcrt_common.a
+ADDLIB libcrtdll_extra.a
SAVE
END
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public