From 746e4a776bf188e03b487e4290e0df8ff8be4ff7 Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Wed, 6 Jan 2016 04:06:17 -0800 Subject: [PATCH 1/4] Partial workaround bootstrapping from newer Visual C++ toolset to older. - Be sure to use _assert and not _wassert. Newer runtimes have both. Older runtimes only have _assert. - Redirect _ftol2_sse to _ftol or _ftol2. - Keep various symbols out of exports in mklib. However this still isn't enough: m3core.lib.sa(TimeWin32.obj) : error LNK2019: unresolved external symbol __dtol3 referenced in function _TimeWin32__ToFileTime m3core.lib.sa(TimeWin32.obj) : error LNK2019: unresolved external symbol __ltod3 referenced in function _TimeWin32__FromFileTime m3core.lib.sa(ThreadWin32C.obj) : error LNK2019: unresolved external symbol @__security_check_cookie@4 referenced in function _ThreadWin32__ProcessLive m3core.lib.sa(dtoa.obj) : error LNK2019: unresolved external symbol __imp____fpe_flt_rounds referenced in function _m3_strtod m3core.lib.sa(dtoa.obj) : error LNK2019: unresolved external symbol __dtoui3 referenced in function _m3_strtod at which point give up. --- m3-libs/m3core/src/m3core.h | 15 +++++ .../m3core/src/thread/WIN32/ThreadWin32C.c | 15 +++++ m3-libs/sysutils/src/LibcCompatC.c | 60 ++++++++++++++++++- m3-sys/mklib/src/Main.m3 | 30 +++++++++- 4 files changed, 116 insertions(+), 4 deletions(-) diff --git a/m3-libs/m3core/src/m3core.h b/m3-libs/m3core/src/m3core.h index 2a78611e0b..e1d91c7fd2 100644 --- a/m3-libs/m3core/src/m3core.h +++ b/m3-libs/m3core/src/m3core.h @@ -249,7 +249,22 @@ M3EXTERNC_END #include #include +/* Strongly consider requiring a different bootstrap procedure and remove this workaround. */ +/* Newer Visual C++ has both _wassert and _assert. Older only have _assert. + Favor _assert so that we can bootstrap from newer to older. */ +#if _MSC_VER +#undef assert +#ifdef __cplusplus +extern "C" { +#endif +void __cdecl _assert(void *, void *, unsigned); +#ifdef __cplusplus +} /* extern C */ +#endif +#define assert(exp) ((void)((!!(exp)) || (_assert(#exp, __FILE__, __LINE__), 0))) +#else /* _MSC_VER */ #include +#endif #include #include #include diff --git a/m3-libs/m3core/src/thread/WIN32/ThreadWin32C.c b/m3-libs/m3core/src/thread/WIN32/ThreadWin32C.c index d26cd7524a..43973565ee 100644 --- a/m3-libs/m3core/src/thread/WIN32/ThreadWin32C.c +++ b/m3-libs/m3core/src/thread/WIN32/ThreadWin32C.c @@ -31,7 +31,22 @@ #endif #include +/* Strongly consider requiring a different bootstrap procedure and remove this workaround. */ +/* Newer Visual C++ has both _wassert and _assert. Older only have _assert. + Favor _assert so that we can bootstrap from newer to older. */ +#if _MSC_VER +#undef assert +#ifdef __cplusplus +extern "C" { +#endif +void __cdecl _assert(void *, void *, unsigned); +#ifdef __cplusplus +} /* extern C */ +#endif +#define assert(exp) ((void)((!!(exp)) || (_assert(#exp, __FILE__, __LINE__), 0))) +#else /* _MSC_VER */ #include +#endif #include #include #include diff --git a/m3-libs/sysutils/src/LibcCompatC.c b/m3-libs/sysutils/src/LibcCompatC.c index 37f476f20e..aeb713b014 100644 --- a/m3-libs/sysutils/src/LibcCompatC.c +++ b/m3-libs/sysutils/src/LibcCompatC.c @@ -1,3 +1,5 @@ +/* Strongly consider requiring a different bootstrap procedure and remove this file. */ + #ifdef _MSC_VER #if 0 /* This is a problem with certain old<=>new bootstrap steps, @@ -48,7 +50,6 @@ extern int (__cdecl * const _imp__printf)(const char* , ...) = &printf; As long as _adjust_fdiv is zero, the other functions will not be called. */ #ifdef _M_IX86 /* Microsoft x86 */ -#if _MSC_VER < 1000 || _MSC_VER >= 1100 /* TODO test 4.1 and 4.2 */ #ifdef __cplusplus extern "C" @@ -56,6 +57,9 @@ extern "C" #endif #pragma warning(disable:4035) /* no return value */ + +#if _MSC_VER < 1000 || _MSC_VER >= 1100 /* TODO test 4.1 and 4.2 */ + #pragma warning(disable:4725) /* instruction may be inaccurate on some Pentiums */ int _adjust_fdiv; @@ -76,11 +80,63 @@ float __cdecl _adj_fdiv_m32(float b) __asm { ret 4 } } +#endif /* _MSC_VER < 1000 || _MSC_VER >= 1100 */ /* TODO test 4.1 and 4.2 */ + +#if _MSC_VER <= 1310 + +/* TODO find out when ftol2_sse introduced. + I only currently have 2.0, 4.0, 5.0 (1100), 7.1 (1310), 2015 (14/1900). + I lack 4.1, 4.2, 6, 7, 8, 9, 10, 11, 12. + + Newer compilers output a call to _ftol2_sse when casting a float or double to an int. + Older runtimes have only _ftol or only _ftol and _ftol2. + _ftol2_sse jmps to _ftol2 when SSE is not available. + _ftol temporarily changes the rounding mode, _ftol2 does not (nor does _ftol2_sse). + + Another workaround would be to forward to msvcrt.dll -- have mklib + always output such forwarders. +*/ +int __cdecl _ftol(double b); +int __cdecl _ftol2(double b); + +__declspec(naked) +int __cdecl _ftol2_sse(double b) +{ +#if _MSC_VER <= 1100 + __asm { jmp _ftol } +#else + __asm { jmp _ftol2 } +#endif +} + +#endif /* _MSC_VER <= 1310 */ /* TODO test 6 (1200), 7 (1300), 8 (1400), 9 (1500), 10 (1600), 11 (1700), 12 (1800) */ + +#if _MSC_VER < 1900 /* TODO find exact versions */ + +/* +no workaround +Consider moving TimeWin32 back to Modula-3, and rewriting strtod in Modula-3 also. +Or improve and use the cross automation which avoids using the old libs. + +The calling conventions of the new float to integer functions cannot be implemented with the older compiler. +/arch:IA32 would suppress their use. + +m3core.lib.sa(TimeWin32.obj) : error LNK2019: unresolved external symbol __dtol3 referenced in function _TimeWin32__ToFileTime +m3core.lib.sa(TimeWin32.obj) : error LNK2019: unresolved external symbol __ltod3 referenced in function _TimeWin32__FromFileTime +m3core.lib.sa(dtoa.obj) : error LNK2019: unresolved external symbol __imp____fpe_flt_rounds referenced in function _m3_strtod +m3core.lib.sa(dtoa.obj) : error LNK2019: unresolved external symbol __dtoui3 referenced in function _m3_strtod + + +This is particularly odd, as the symbol has been around for a long time. +m3core.lib.sa(ThreadWin32C.obj) : error LNK2019: unresolved external symbol @__security_check_cookie@4 referenced in function _ThreadWin32__ProcessLive +*/ + +#endif + #ifdef __cplusplus } #endif -#endif /* _MSC_VER < 1000 || _MSC_VER >= 1100 */ /* TODO test 4.1 and 4.2 */ #endif /* _M_IX86 */ #endif /* _MSC_VER */ diff --git a/m3-sys/mklib/src/Main.m3 b/m3-sys/mklib/src/Main.m3 index 0b19dd2148..7bd1ec6d02 100644 --- a/m3-sys/mklib/src/Main.m3 +++ b/m3-sys/mklib/src/Main.m3 @@ -802,6 +802,17 @@ PROCEDURE CleanName (sym: TEXT): TEXT = END CleanName; PROCEDURE IsKeeper (sym: TEXT): BOOLEAN = + (* Sort these by length for later optimization. + Every symbol must be duplicated -- with and without + a leading underscore. *) + CONST syms = ARRAY OF TEXT { + "printf", + "_printf", + "_ftol2_sse", + "_vfprintf_l", + "__ftol2_sse", + "__vfprintf_l" + }; VAR len := Text.Length (sym); BEGIN IF (len > 7) @@ -822,13 +833,28 @@ PROCEDURE IsKeeper (sym: TEXT): BOOLEAN = RETURN FALSE; END; - (* Skip C++ symbols, from C runtime. *) + (* Skip C++ symbols, from C runtime, and floating point constants. *) IF len > 1 AND Match(sym, 0, "?") THEN RETURN FALSE; END; - RETURN NOT IsFloatingPointConstant(sym, len); + IF IsFloatingPointConstant (sym, len) THEN + RETURN FALSE; + END; + + IF len > Text.Length (syms[LAST(syms)]) THEN + RETURN TRUE; + END; + + FOR i := FIRST(syms) TO LAST(syms) DO + IF Text.Equal (sym, syms[i]) THEN + RETURN FALSE; + END; + END; + + RETURN TRUE; + END IsKeeper; PROCEDURE Match (txt: TEXT; start: INTEGER; key: TEXT): BOOLEAN = From 784fbaa9a94dcc03ca0e2401ad38a338b7a88c0a Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Wed, 6 Jan 2016 04:31:12 -0800 Subject: [PATCH 2/4] Go ahead and workaround missing cderr.h in XP environment. --- scripts/env/winddk/3790/wxp/x86.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/env/winddk/3790/wxp/x86.cmd b/scripts/env/winddk/3790/wxp/x86.cmd index 4800f45c68..223fca3dd0 100644 --- a/scripts/env/winddk/3790/wxp/x86.cmd +++ b/scripts/env/winddk/3790/wxp/x86.cmd @@ -4,7 +4,7 @@ @rem cderr.h is missing @call :F1 c:\winddk\3790 wxp i386 -rem @call :F3 c:\winddk\3790 wnet i386 +@call :F3 c:\winddk\3790 wnet i386 @goto :eof :F1 From 561904013825bea5e490751e4f09237bdd5c87a9 Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Wed, 6 Jan 2016 04:32:30 -0800 Subject: [PATCH 3/4] Add what I'm using to look for the alloca problem, and not a bad workflow for some testing. --- scripts/python/test1.cmd | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 scripts/python/test1.cmd diff --git a/scripts/python/test1.cmd b/scripts/python/test1.cmd new file mode 100644 index 0000000000..46087da2e9 --- /dev/null +++ b/scripts/python/test1.cmd @@ -0,0 +1,7 @@ +call ..\env\clean2.cmd +call ..\env\winddk\3790\wnet\x86.cmd + +rd /q/s \cm3.2 +xcopy /fivery \cm3-5.8.6-min \cm3.2 +.\make-dist-cfg.py +.\upgrade-full.cmd From e0bfe8ce30aa1d5dd9fb4cb1297670e7f67f227c Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Wed, 6 Jan 2016 04:35:54 -0800 Subject: [PATCH 4/4] Add _wassert so that one can upgrade from the 5.8.6 release using Visual C++ 7.1. --- m3-libs/sysutils/src/LibcCompatC.c | 61 ++++++++++++++++++++++++++++++ m3-sys/mklib/src/Main.m3 | 2 + 2 files changed, 63 insertions(+) diff --git a/m3-libs/sysutils/src/LibcCompatC.c b/m3-libs/sysutils/src/LibcCompatC.c index aeb713b014..cd1a3886c6 100644 --- a/m3-libs/sysutils/src/LibcCompatC.c +++ b/m3-libs/sysutils/src/LibcCompatC.c @@ -111,6 +111,67 @@ int __cdecl _ftol2_sse(double b) #endif /* _MSC_VER <= 1310 */ /* TODO test 6 (1200), 7 (1300), 8 (1400), 9 (1500), 10 (1600), 11 (1700), 12 (1800) */ +#if _MSC_VER <= 1310 /* TODO find exact versions */ + +/* +Starting with 5.8.6 release and upgrading with Visual C++ 7.1. +m3core.lib.sa(ThreadWin32C.obj) : error LNK2019: unresolved external symbol __wassert referenced in function _ThreadWin32__ProcessStopped +*/ + +#include + +void +__cdecl +_wassert ( + wchar_t const* w_Message, + wchar_t const* w_File, + unsigned Line + ) +{ + size_t len; + size_t i; + char* a_Message = ""; + char* a_File = ""; + + if (w_Message && w_Message[0]) + { + len = wcslen(w_Message) + 1; + a_Message = (char*)_alloca(len); + for (i = 0; i < len; ++i) + a_Message[i] = (char)w_Message[i]; + } + + if (w_File && w_File[0]) + { + len = wcslen(w_File) + 1; + a_Message = (char*)_alloca(len); + for (i = 0; i < len; ++i) + a_File[i] = (char)w_File[i]; + } + + _assert(a_Message, a_File, Line); +} + +#endif + +/* +no workaround +Consider moving TimeWin32 back to Modula-3, and rewriting strtod in Modula-3 also. +Or improve and use the cross automation which avoids using the old libs. + +The calling conventions of the new float to integer functions cannot be implemented with the older compiler. +/arch:IA32 would suppress their use. + +m3core.lib.sa(TimeWin32.obj) : error LNK2019: unresolved external symbol __dtol3 referenced in function _TimeWin32__ToFileTime +m3core.lib.sa(TimeWin32.obj) : error LNK2019: unresolved external symbol __ltod3 referenced in function _TimeWin32__FromFileTime +m3core.lib.sa(dtoa.obj) : error LNK2019: unresolved external symbol __imp____fpe_flt_rounds referenced in function _m3_strtod +m3core.lib.sa(dtoa.obj) : error LNK2019: unresolved external symbol __dtoui3 referenced in function _m3_strtod + + +This is particularly odd, as the symbol has been around for a long time. +m3core.lib.sa(ThreadWin32C.obj) : error LNK2019: unresolved external symbol @__security_check_cookie@4 referenced in function _ThreadWin32__ProcessLive +*/ + #if _MSC_VER < 1900 /* TODO find exact versions */ /* diff --git a/m3-sys/mklib/src/Main.m3 b/m3-sys/mklib/src/Main.m3 index 7bd1ec6d02..070a28e9d1 100644 --- a/m3-sys/mklib/src/Main.m3 +++ b/m3-sys/mklib/src/Main.m3 @@ -808,6 +808,8 @@ PROCEDURE IsKeeper (sym: TEXT): BOOLEAN = CONST syms = ARRAY OF TEXT { "printf", "_printf", + "_wassert", + "__wassert", "_ftol2_sse", "_vfprintf_l", "__ftol2_sse",