From: Juergen Perlinger Date: Sun, 2 Oct 2016 07:01:53 +0000 (+0200) Subject: [Bug 3095] Compatibility with openssl 1.1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9035bbc9c1a25587cabd54891be227faa77aa2e4;p=thirdparty%2Fntp.git [Bug 3095] Compatibility with openssl 1.1 - add autolib hader - fix linker input selection bk: 57f0b0e1o_rUHYk9FtY_XDNPZ5kkpA --- diff --git a/include/ssl_applink.c b/include/ssl_applink.c index ba1f4a8fe..e409f3421 100644 --- a/include/ssl_applink.c +++ b/include/ssl_applink.c @@ -10,6 +10,9 @@ # ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4152) +# ifndef OPENSSL_NO_AUTOLINK +# include "msvc_ssl_autolib.h" +# endif # endif # include # ifdef _MSC_VER @@ -29,16 +32,25 @@ void wrap_dbg_free(void *p); #if defined(OPENSSL) && defined(SYS_WINNT) + void ssl_applink(void); void ssl_applink(void) { -#ifdef WRAP_DBG_MALLOC - CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free); +#if OPENSSL_VERSION_NUMBER >= 0x10100000L +# ifdef WRAP_DBG_MALLOC + CRYPTO_set_mem_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free); +# else + OPENSSL_malloc_init(); +# endif #else +# ifdef WRAP_DBG_MALLOC + CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free); +# else CRYPTO_malloc_init(); -#endif +# endif +#endif /* OpenSSL version cascade */ } #else /* !OPENSSL || !SYS_WINNT */ #define ssl_applink() do {} while (0) diff --git a/libntp/libssl_compat.c b/libntp/libssl_compat.c index ce6acb7d3..2e4f2eec6 100644 --- a/libntp/libssl_compat.c +++ b/libntp/libssl_compat.c @@ -17,6 +17,10 @@ #include "config.h" #include +#if defined(HAVE_INTTYPES_H) || _MSC_VER >= _MSC_VER == 1800 +# include +#endif + #include #include diff --git a/ports/winnt/include/msvc_ssl_autolib.h b/ports/winnt/include/msvc_ssl_autolib.h new file mode 100644 index 000000000..688b5e262 --- /dev/null +++ b/ports/winnt/include/msvc_ssl_autolib.h @@ -0,0 +1,94 @@ +/* + * msvc_ssl_autolib.h -- automatic link library selection + * + * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. + * The contents of 'html/copyright.html' apply. + * -------------------------------------------------------------------- + * + * OpenSSL library names changed over time, at least once when v1.1.0 + * emerged. For systems where the build system is inspected before + * the build environment is created (autconf, CMake, SCONS,...) this + * would be harmless, once it's known what libraries should be looked + * for. With MSVC / MSBUILD that's much trickier. + * + * So instead of manipulating the build environment we use the build + * tools themselves to create requests for linking the right library. + * + * To use this feature, it is recommended to use the precompiled + * VC binaries from Shining Light Productions: + * https://slproweb.com/products/Win32OpenSSL.html + * These are installed in (OPENSSL_LIB)/vc. + * + * As an alternative, create the set of build variants of OpenSSL you + * need, implementing the following naming scheme: + * + * basename.lib + * + * so that e.g. libcrypto64MTd.lib is a 64bit binary, using a static + * multithreaded runtime in debug version. See the code below how this + * is handled. + * -------------------------------------------------------------------- + */ +#pragma once + +#if !defined(_MSC_VER) +# error use this header only with Micro$oft Visual C compilers! +#elif defined(OPENSSL_NO_AUTOLINK) +# pragma message("automatic OpenSSL library selection disabled") +#else +/* ---------------------------------------------------------------- */ +/* selection dance to get the right libraries linked */ +/* ---------------------------------------------------------------- */ + +/* --*-- check if this a DEBUG or a RELEASE build --*-- + * The '_DEBUG' macro is only set for DEBUG build variants + */ +# ifdef _DEBUG +# define LTAG_DEBUG "d" +# else +# define LTAG_DEBUG "" +# endif + +/* --*-- check platform (32 bit vs. 64 bit) --*-- + * '_WIN64' is defined for X64 Platform only + */ +# ifdef _WIN64 +# define LTAG_SIZE "64" +# else +# define LTAG_SIZE "32" +# endif + +/* --*-- check VC runtime model --*-- + * '_DLL' is set if a runtime-in-a-dll code generation model is chosen. + * Note that we do not check for the single-threaded static runtime. + * This would make no sense, since the Windows Build *uses* threads and + * therefore needs a multithread runtime anyway. And Micro$oft decided + * somewhere after VS2008 to drop that model anyway, so it's no longer + * available on newer platforms. + */ +# ifdef _DLL +# #define LTAG_RTLIB "MD" +# else +# define LTAG_RTLIB "MT" +# endif + +/* --*-- place linker request in object file --*-- + * Here we come to the reason for all that trouble: the library names + * to link depend on the OpenSSL version... + * + * Before v1.1.0, the 'old' (ancient?) name 'libeay32' was used, + * no matter what platform. (The corresponding 'ssleay32.lib' was/is + * not used by NTP.) Since v1.1.0, the name stems are libcrypto + * and libssl, and they contain the platform size (32 or 64). + * + * So we use '#pragma comment(lib,...)' to place a proper linker + * request in the object file, depending on the SSL version and the + * build variant. + */ +# if OPENSSL_VERSION_NUMBER >= 0x10100000L +# pragma comment(lib, "libcrypto" LTAG_SIZE LTAG_RTLIB LTAG_DEBUG ".lib") +# else +# pragma comment(lib, "libeay32" LTAG_RTLIB LTAG_DEBUG ".lib") +# endif + +#endif /*!defined(OPENSSL_NO_AUTOLINK)*/ diff --git a/ports/winnt/vs2008/debug-x64.vsprops b/ports/winnt/vs2008/debug-x64.vsprops index 06f6f204e..3f241c2c8 100644 --- a/ports/winnt/vs2008/debug-x64.vsprops +++ b/ports/winnt/vs2008/debug-x64.vsprops @@ -14,7 +14,7 @@ /> + /> diff --git a/ports/winnt/vs2008/debug.vsprops b/ports/winnt/vs2008/debug.vsprops index 0a1619748..0cbd9f4ae 100644 --- a/ports/winnt/vs2008/debug.vsprops +++ b/ports/winnt/vs2008/debug.vsprops @@ -14,7 +14,7 @@ /> diff --git a/ports/winnt/vs2008/release-x64.vsprops b/ports/winnt/vs2008/release-x64.vsprops index 23cb8a8cb..8c0ee80b0 100644 --- a/ports/winnt/vs2008/release-x64.vsprops +++ b/ports/winnt/vs2008/release-x64.vsprops @@ -15,7 +15,7 @@ /> diff --git a/ports/winnt/vs2008/release.vsprops b/ports/winnt/vs2008/release.vsprops index 4c7c513ad..498779578 100644 --- a/ports/winnt/vs2008/release.vsprops +++ b/ports/winnt/vs2008/release.vsprops @@ -15,7 +15,7 @@ /> diff --git a/ports/winnt/vs2013/debug-x64.props b/ports/winnt/vs2013/debug-x64.props index ac72381ae..65d4f863f 100644 --- a/ports/winnt/vs2013/debug-x64.props +++ b/ports/winnt/vs2013/debug-x64.props @@ -16,8 +16,8 @@ MultiThreadedDebug - $(OPENSSL64_LIB)\libeay32.lib;%(AdditionalDependencies) MachineX64 + $(OPENSSL64_LIB)\vc diff --git a/ports/winnt/vs2013/debug.props b/ports/winnt/vs2013/debug.props index 380885908..46792f845 100644 --- a/ports/winnt/vs2013/debug.props +++ b/ports/winnt/vs2013/debug.props @@ -16,8 +16,8 @@ MultiThreadedDebug - $(OPENSSL_LIB)\libeay32.lib;%(AdditionalDependencies) MachineX86 + $(OPENSSL_LIB)\vc diff --git a/ports/winnt/vs2013/libntp/libntp.vcxproj b/ports/winnt/vs2013/libntp/libntp.vcxproj index 5171e948a..26a13c21f 100644 --- a/ports/winnt/vs2013/libntp/libntp.vcxproj +++ b/ports/winnt/vs2013/libntp/libntp.vcxproj @@ -388,6 +388,7 @@ + @@ -431,4 +432,4 @@ - + \ No newline at end of file diff --git a/ports/winnt/vs2013/libntp/libntp.vcxproj.filters b/ports/winnt/vs2013/libntp/libntp.vcxproj.filters index 022ccf4a1..9839bbd83 100644 --- a/ports/winnt/vs2013/libntp/libntp.vcxproj.filters +++ b/ports/winnt/vs2013/libntp/libntp.vcxproj.filters @@ -574,6 +574,9 @@ Header Files + + Header Files + diff --git a/ports/winnt/vs2013/release-x64.props b/ports/winnt/vs2013/release-x64.props index dcd725557..2bb07cb37 100644 --- a/ports/winnt/vs2013/release-x64.props +++ b/ports/winnt/vs2013/release-x64.props @@ -17,8 +17,8 @@ MultiThreaded - $(OPENSSL64_LIB)\libeay32.lib;%(AdditionalDependencies) MachineX64 + $(OPENSSL64_LIB)\vc diff --git a/ports/winnt/vs2013/release.props b/ports/winnt/vs2013/release.props index d32ea70c1..f6382dfba 100644 --- a/ports/winnt/vs2013/release.props +++ b/ports/winnt/vs2013/release.props @@ -17,8 +17,8 @@ MultiThreaded - $(OPENSSL_LIB)\libeay32.lib;%(AdditionalDependencies) MachineX86 + $(OPENSSL_LIB)\vc diff --git a/ports/winnt/vs2015/debug-x64.props b/ports/winnt/vs2015/debug-x64.props index ac72381ae..65d4f863f 100644 --- a/ports/winnt/vs2015/debug-x64.props +++ b/ports/winnt/vs2015/debug-x64.props @@ -16,8 +16,8 @@ MultiThreadedDebug - $(OPENSSL64_LIB)\libeay32.lib;%(AdditionalDependencies) MachineX64 + $(OPENSSL64_LIB)\vc diff --git a/ports/winnt/vs2015/debug.props b/ports/winnt/vs2015/debug.props index 380885908..46792f845 100644 --- a/ports/winnt/vs2015/debug.props +++ b/ports/winnt/vs2015/debug.props @@ -16,8 +16,8 @@ MultiThreadedDebug - $(OPENSSL_LIB)\libeay32.lib;%(AdditionalDependencies) MachineX86 + $(OPENSSL_LIB)\vc diff --git a/ports/winnt/vs2015/libntp/libntp.vcxproj b/ports/winnt/vs2015/libntp/libntp.vcxproj index 6f6899f9c..a93e97015 100644 --- a/ports/winnt/vs2015/libntp/libntp.vcxproj +++ b/ports/winnt/vs2015/libntp/libntp.vcxproj @@ -388,6 +388,7 @@ + diff --git a/ports/winnt/vs2015/libntp/libntp.vcxproj.filters b/ports/winnt/vs2015/libntp/libntp.vcxproj.filters index 022ccf4a1..9839bbd83 100644 --- a/ports/winnt/vs2015/libntp/libntp.vcxproj.filters +++ b/ports/winnt/vs2015/libntp/libntp.vcxproj.filters @@ -574,6 +574,9 @@ Header Files + + Header Files + diff --git a/ports/winnt/vs2015/release-x64.props b/ports/winnt/vs2015/release-x64.props index dcd725557..2bb07cb37 100644 --- a/ports/winnt/vs2015/release-x64.props +++ b/ports/winnt/vs2015/release-x64.props @@ -17,8 +17,8 @@ MultiThreaded - $(OPENSSL64_LIB)\libeay32.lib;%(AdditionalDependencies) MachineX64 + $(OPENSSL64_LIB)\vc diff --git a/ports/winnt/vs2015/release.props b/ports/winnt/vs2015/release.props index d32ea70c1..f6382dfba 100644 --- a/ports/winnt/vs2015/release.props +++ b/ports/winnt/vs2015/release.props @@ -17,8 +17,8 @@ MultiThreaded - $(OPENSSL_LIB)\libeay32.lib;%(AdditionalDependencies) MachineX86 + $(OPENSSL_LIB)\vc