Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfgVC-0002Ci-DV for pgsql-bugs@arkaria.postgresql.org; Tue, 25 Jun 2019 08:08:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hfgV9-0000e4-Hh for pgsql-bugs@arkaria.postgresql.org; Tue, 25 Jun 2019 08:08:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfgV7-0000as-Ow for pgsql-bugs@lists.postgresql.org; Tue, 25 Jun 2019 08:08:27 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfgV2-00053U-Lv for pgsql-bugs@lists.postgresql.org; Tue, 25 Jun 2019 08:08:25 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 1C14A225AB; Tue, 25 Jun 2019 04:08:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 25 Jun 2019 04:08:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=7uN4ptGeNGK21F55XsD32r6W+bt CGDGU2EqrzFfda3k=; b=Q8AKZjM3BUBOneEv29hpbP55KJG7rkERJwKJvmoY1/y 11kIEXwEhR2REzyzfA8uLRK6WfKKxygQBmJ2c+oH+Urs2r0HB6U0+32oHsRWxrtT W3m1DJIsGKfKD7bywsNXz3ZQVVFCkrS/3405zCKkB30Iog6sxqgRPU3KrBkeIYCW quCQWlTYRe+645fegAI3qvB8WRhj7kIbO2CQBvDivi30yaiyAnUHzeqQBTYdZSIF crf2m7NYTl2PotzGXa2gdM9IMbfN5+W20T1WrPJ4r1b5Vehj1W222xPA52zjSEHM RFqmvhGTi8zIevzt8fKkSwEi/jfMH5t5N37ib1OFjaw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=7uN4pt GeNGK21F55XsD32r6W+btCGDGU2EqrzFfda3k=; b=FGT9RF+aEltusEq5VWejgY TKeoBerm9armw8AdaNcez0bxOs38RJLEP72nGm6yo6Z/U4tYD53angheGyiBA8hf DlyTmXDrKHc4lRp4wDTi6Hcs8Ep1SL4VoM2jTQQl108NpnhWklWfdwOJ+BO0A9pc z5fF/DBZMoAdzjASF72xvMG/QjjcVl8TI8anWDFmHHMHN6ODgOsNqNolzgIudstF JoqvoAL0dz0I2U1jOEXtPQ8SUhj/LpFKGrrGW7uZTlXWPgoQ99vM+bgeXFfYQ6Sy YCf1RxoqbX2GwUxO5RFQi3/xSqGHTfFTC92n9OYoDa11MjPhV8y0uhSXPUZsmASA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudefgddufedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt udenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucfkphepuddukedrvdeguddrvdehuddrudeigeenucfrrghr rghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiienucevlh hushhtvghrufhiiigvpedt X-ME-Proxy: Received: from paquier.xyz (mp76f1fba4.ap.nuro.jp [118.241.251.164]) by mail.messagingengine.com (Postfix) with ESMTPA id B00F180062; Tue, 25 Jun 2019 04:08:15 -0400 (EDT) Date: Tue, 25 Jun 2019 17:08:11 +0900 From: Michael Paquier To: Juan =?iso-8859-1?Q?Jos=E9_Santamar=EDa?= Flecha Cc: Sandeep Thakkar , serpashk@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15789: libpq compilation with OpenSSL 1.1.1b fails on Windows with Visual Studio 2017 Message-ID: <20190625080811.GF5569@paquier.xyz> References: <20190528105802.GC2682@paquier.xyz> <20190531142832.GQ2848@paquier.xyz> <20190603235132.GA1529@paquier.xyz> <20190620024941.GB2660@paquier.xyz> <20190622024433.GA1713@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="IuhbYIxU28t+Kd57" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --IuhbYIxU28t+Kd57 Content-Type: multipart/mixed; boundary="Il7n/DHsA0sMLmDu" Content-Disposition: inline --Il7n/DHsA0sMLmDu Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 24, 2019 at 01:44:18PM +0200, Juan Jos=E9 Santamar=EDa Flecha w= rote: > The updated patches include: >=20 > 1. Comments for AddLibrary. > 2. The function GetOpenSSLVersion returns: major, minor and fix numbers. > 3. The version check will default to 1.1.X behaviour for 1.Y.X > versions if Y > 0. Thanks for the new patch set! I have been looking at that in depths and I have adjusted the whole logic a bit here and there. At the end I found the logic changed in AddLibrary more confusing because the debugging suffix may change depending on if we use a release-quality build or not, so I have kept the original interface, and completed it with a logic allowing the scripts to grab all the libraries it expects. This has a small gain when using a non-debug installation as the library names are the same for Win32 and Win64 for >=3D 1.1.0. Also, your patch was not working with other versions of MSVC as the new routine got stuck into the 2017 class, so I had to move it, and I found that it was cleaner to just make it return a string made of the 3 first digits and to do direct string comparisons. Please note that it is not necessary to create versions for the back-branches yet. If necessary, I'll do that myself, but first let's make sure that we agree about the shape of the patch for HEAD. Attached is an updated version which I would be fine to commit. I have tested it with compilation linking to OpenSSL 1.0.2 and 1.1.0 on Win32 and the build is able to complete. This applies on HEAD only, where I have run all my tests. The patch is properly indented. What do you think? -- Michael --Il7n/DHsA0sMLmDu Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="msvc-openssl-110-v2.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index cbe019e524..addada6189 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -114,6 +114,34 @@ sub copyFile return; } =20 +# Fetch version of OpenSSL based on a parsing of the command shipped with +# the installer this build is linking to. This returns as result a string +# made of the three first digits of the OpenSSL versoin, which is enough +# to decide which options to apply depending on the version of OpenSSL +# linking with. +sub GetOpenSSLVersion +{ + my $self =3D shift; + + # Attempt to get OpenSSL version and location. This assumes that + # openssl.exe is in the specified directory. + my $opensslcmd =3D + $self->{options}->{openssl} . "\\bin\\openssl.exe version 2>&1"; + my $sslout =3D `$opensslcmd`; + + $? >> 8 =3D=3D 0 + or croak + "Unable to determine OpenSSL version: The openssl.exe command wasn't fo= und."; + + if ($sslout =3D~ /(\d+)\.(\d+)\.(\d+)(\D)/m) + { + return "$1.$2.$3"; + } + + croak + "Unable to determine OpenSSL version: The openssl.exe version could not= be determined."; +} + sub GenerateFiles { my $self =3D shift; @@ -168,10 +196,23 @@ sub GenerateFiles print $o "#ifndef IGNORE_CONFIGURED_SETTINGS\n"; print $o "#define USE_ASSERT_CHECKING 1\n" if ($self->{options}->{asserts}); - print $o "#define USE_LDAP 1\n" if ($self->{options}->{ldap}); - print $o "#define HAVE_LIBZ 1\n" if ($self->{options}->{zlib}); - print $o "#define USE_OPENSSL 1\n" if ($self->{options}->{openssl}); - print $o "#define ENABLE_NLS 1\n" if ($self->{options}->{nls}); + print $o "#define USE_LDAP 1\n" if ($self->{options}->{ldap}); + print $o "#define HAVE_LIBZ 1\n" if ($self->{options}->{zlib}); + + if ($self->{options}->{openssl}) + { + print $o "#define USE_OPENSSL 1\n"; + + # More symbols are needed with OpenSSL 1.1.0 and above. + if ($self->GetOpenSSLVersion() ge '1.1.0') + { + print $o "#define HAVE_ASN1_STRING_GET0_DATA 1\n"; + print $o "#define HAVE_BIO_GET_DATA 1\n"; + print $o "#define HAVE_BIO_METH_NEW 1\n"; + print $o "#define HAVE_OPENSSL_INIT_SSL 1\n"; + } + } + print $o "#define ENABLE_NLS 1\n" if ($self->{options}->{nls}); =20 print $o "#define BLCKSZ ", 1024 * $self->{options}->{blocksize}, "\n"; @@ -613,21 +654,68 @@ sub AddProject if ($self->{options}->{openssl}) { $proj->AddIncludeDir($self->{options}->{openssl} . '\include'); - if (-e "$self->{options}->{openssl}/lib/VC/ssleay32MD.lib") + + # Starting at version 1.1.0 the OpenSSL installers have + # changed their library names from: + # - libeay to libcrypto + # - ssleay to libssl + if ($self->GetOpenSSLVersion() ge '1.1.0') { - $proj->AddLibrary( - $self->{options}->{openssl} . '\lib\VC\ssleay32.lib', 1); - $proj->AddLibrary( - $self->{options}->{openssl} . '\lib\VC\libeay32.lib', 1); + my $dbgsuffix; + my $libsslpath; + my $libcryptopath; + + # The format name of the libraries is slightly different + # between the Win32 and Win64 platform, so adapt. + if (-e "$self->{options}->{openssl}/lib/VC/sslcrypto32MD.lib") + { + # Win32 here, with a debugging library set. + $dbgsuffix =3D 1; + $libsslpath =3D '\lib\VC\libssl32.lib'; + $libcryptopath =3D '\lib\VC\libcrypto32.lib'; + } + elsif (-e "$self->{options}->{openssl}/lib/VC/sslcrypto64MD.lib") + { + # Win64 here, with a debugging library set. + $dbgsuffix =3D 1; + $libsslpath =3D '\lib\VC\libssl64.lib'; + $libcryptopath =3D '\lib\VC\libcrypto64.lib'; + } + else + { + # On both Win32 and Win64 the same library + # names are used without a debugging context. + $dbgsuffix =3D 0; + $libsslpath =3D '\lib\libssl.lib'; + $libcryptopath =3D '\lib\libcrypto.lib'; + } + + $proj->AddLibrary($self->{options}->{openssl} . $libsslpath, + $dbgsuffix); + $proj->AddLibrary($self->{options}->{openssl} . $libcryptopath, + $dbgsuffix); } else { - # We don't expect the config-specific library to be here, - # so don't ask for it in last parameter - $proj->AddLibrary( - $self->{options}->{openssl} . '\lib\ssleay32.lib', 0); - $proj->AddLibrary( - $self->{options}->{openssl} . '\lib\libeay32.lib', 0); + # Choose which set of libraries to use depending on if + # debugging libraries are in place in the installer. + if (-e "$self->{options}->{openssl}/lib/VC/ssleay32MD.lib") + { + $proj->AddLibrary( + $self->{options}->{openssl} . '\lib\VC\ssleay32.lib', 1); + $proj->AddLibrary( + $self->{options}->{openssl} . '\lib\VC\libeay32.lib', 1); + } + else + { + # We don't expect the config-specific library + # to be here, so don't ask for it in last + # parameter. + $proj->AddLibrary( + $self->{options}->{openssl} . '\lib\ssleay32.lib', 0); + $proj->AddLibrary( + $self->{options}->{openssl} . '\lib\libeay32.lib', 0); + } } } if ($self->{options}->{nls}) --Il7n/DHsA0sMLmDu-- --IuhbYIxU28t+Kd57 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl0R1msACgkQnvQgOdby QH1v2w/+Jh0A43p5SKu1VopuXkvBzWr6bCqbjOOj61SKaFT5QahwhVsftRKie5fl R+V+ky9X4Jez3VrgSBlp07Xkv5I0a60Y91GnvvGRC797p4hx3Da/trQ7sFelKlsj 6ucPwexCTAuS6kgqpTeq91z+vvijAFtUez9XNk13KRHKH4m4uW6hBc+t1x5+1aFY 9jj7W43KieWfgb/L2CUqj8trETWsZDGtgCRlwBQRNrwMJIVg23grpma90X29f6+C X5Bya2y8cvdt7HpvAIaWBhGlw5sy3c/nsJ+l4aIqK1SXkp6IJUAftSh+ddAxVrOS xiAFnonfsVlC/oY2H5z5O4X1liOQ4HKM32bFSx2413yKjNGfzzKHWTNKPKOqC77n ugud9wEwvORV2KFkcVxCe9vFwgKmEX5FtI0F6tcWY2pgwz6Iqa17fD+uQPlVEzoq kevYVwsXUV91DHjtCFEWiBy/eiHLB5WUq/Fraf3InnTOMeljmT4qUXeAKnRMlQ4b oB9ZejLNVCU/8ouU6deJUbPfXsMpcQxxHoMGYGhllwOz32pnzrvPRIr6TqwdMJQe ZK7JTT4YijLt4Fvip6emveN+WwQsJVJNtp4twN5E622BL6PhcdRVYAlh0LHcGzgJ vrZDyqTcoYJ3IGASIBCA9IbN/rCJer82ojv78jzCPs1e8fclbPA= =qjMW -----END PGP SIGNATURE----- --IuhbYIxU28t+Kd57--