Platforms which define OPENSSL_SYS_WINDOWS or OPENSSL_SYS_WIN32 are
not properly built following the zlib configuration parameter
[[no-]zlib|zlib-dynamic] when static zlib support is required into
openssl.
Even if static linking of zlib.lib is desired specifying option 'zlib'
to 'Configure' what finally gets built up are libraries and exe's
which actually only have zlib-dynamic support.
This bug only affects Windows platforms and can be verified using the
standard method to build openssl and specifying the 'zlib' option for
the Configure script. Once that openssl is built, verify that there is
no zlib.dll available at runtime and execute the standard tests
'..\ms\test.bat. You'll get very funy results.
This bug? results, obviously, in strange behaviour related with zlib.
For example when building with msvc60 and msvc71, running ssltest
gives several access violations if no zlib.dll can be loaded. At some
point it has not been properly detected that the zlib.dll is not
available, but that is another matter that should be addressed later
if not currently fixed in CVS.
Part of the problem is that ZLIB_SHARED is unconditionally defined in
c_zlib.c if OPENSSL_SYS_WINDOWS or OPENSSL_SYS_WIN32 are already
defined, forcing the libraries at runtime to act as if a zlib.dll was
available even when we have specified at configuration time that we
want static zlib and not a zlib-dynamic build.
Besides the change needed to c_zlib.c, mk1mf.pl and VC-32.pl also need
some minor changes to allow proper static linking of zlib.
The proposed changes only affect Windows platforms, and does not alter
in any way the actual way of working of openssl when zlib-dynamic or
no-zlib is selected for configuration.
I hope that the attached patch is of your interest, and that the
masters consider merging it into CVS.
Regards,
Yang
diff -u -r -p .\openssl-SNAP-20051118/crypto/comp/c_zlib.c
.\openssl-PATCH/crypto/comp/c_zlib.c
--- .\openssl-SNAP-20051118/crypto/comp/c_zlib.c 2005-06-18
08:00:18.000000000 +0200
+++ .\openssl-PATCH/crypto/comp/c_zlib.c 2005-11-18 23:37:01.468750000
+0100
@@ -67,14 +67,14 @@ static COMP_METHOD zlib_stateful_method=
* When OpenSSL is built on Windows, we do not want to require that
* the ZLIB.DLL be available in order for the OpenSSL DLLs to
* work. Therefore, all ZLIB routines are loaded at run time
- * and we do not link to a .LIB file.
+ * and we do not link to a .LIB file when ZLIB_SHARED is defined.
*/
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
# include <windows.h>
-
+# ifdef ZLIB_SHARED
# define Z_CALLCONV _stdcall
-# ifndef ZLIB_SHARED
-# define ZLIB_SHARED
+# else
+# define Z_CALLCONV
# endif
#else
# define Z_CALLCONV
diff -u -r -p .\openssl-SNAP-20051118/util/mk1mf.pl
.\openssl-PATCH/util/mk1mf.pl
--- .\openssl-SNAP-20051118/util/mk1mf.pl 2005-11-07 02:00:50.000000000
+0100
+++ .\openssl-PATCH/util/mk1mf.pl 2005-11-19 00:17:18.250000000 +0100
@@ -125,6 +125,7 @@ $bin_dir=(defined($VARS{'BIN'}))?$VARS{'
# $bin_dir.=$o causes a core dump on my sparc :-(
+$zlib_static_linking = 1 if ($xcflags !~ /DZLIB_SHARED/) && ($xcflags =~
/DZLIB/);
$NT=0;
@@ -831,7 +832,7 @@ sub do_defs
$ret.=$t;
}
# hack to add version info on MSVC
- if ($shlib && ($platform eq "VC-WIN32") || ($platform eq "VC-NT"))
+ if ($shlib && (($platform eq "VC-WIN32") || ($platform eq "VC-NT")))
{
if ($var eq "CRYPTOOBJ")
{ $ret.="\$(OBJ_D)\\\$(CRYPTO).res "; }
diff -u -r -p .\openssl-SNAP-20051118/util/pl/VC-32.pl
.\openssl-PATCH/util/pl/VC-32.pl
--- .\openssl-SNAP-20051118/util/pl/VC-32.pl 2005-11-15 10:00:36.000000000
+0100
+++ .\openssl-PATCH/util/pl/VC-32.pl 2005-11-18 23:34:14.031250000 +0100
@@ -147,6 +147,8 @@ if ($FLAVOR =~ /NT/)
$ex_libs="unicows.lib $ex_libs";
}
+$ex_libs.=' zlib.lib' if ($zlib_static_linking);
+
# static library stuff
$mklib='lib';
$ranlib='';
@@ -278,6 +280,7 @@ sub do_lib_rule
$ex.=' wsock32.lib gdi32.lib advapi32.lib user32.lib';
$ex.=' bufferoverflowu.lib' if ($FLAVOR =~ /WIN64/);
}
+ $ex.=' zlib.lib' if ($zlib_static_linking);
$ret.="\t\$(LINK) \$(MLFLAGS) $efile$target $name @<<\n
\$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
}
$ret.="\n";