pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
Cc: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
Cc: serpashk@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15789: libpq compilation with OpenSSL 1.1.1b fails on Windows with Visual Studio 2017
Date: Tue, 25 Jun 2019 17:08:11 +0900
Message-ID: <20190625080811.GF5569@paquier.xyz> (raw)
In-Reply-To: <CAC+AXB0abV7wqwz4_SJ9jfRVRD0g4WvqSKStDTBgykFeqoy7Uw@mail.gmail.com>
References: <20190528105802.GC2682@paquier.xyz>
	<CAC+AXB2gUvPEg_AcCVE-DREP3nECi7bvaaOhre-sZVHj7Khjhw@mail.gmail.com>
	<20190531142832.GQ2848@paquier.xyz>
	<CANFyU977NVQCO_Xu_er76Eezg2D3zVNNmf_d7j5d5iq2T6FLdw@mail.gmail.com>
	<20190603235132.GA1529@paquier.xyz>
	<CAC+AXB3_YNqAr=u9ccuXOoKQF=kZRQFjnLgRaSFQEjNz+Po+1w@mail.gmail.com>
	<20190620024941.GB2660@paquier.xyz>
	<CAC+AXB2gyrRJE+8gPwWTptaMTEH31dzJDsBSTMc3twn56zb=jQ@mail.gmail.com>
	<20190622024433.GA1713@paquier.xyz>
	<CAC+AXB0abV7wqwz4_SJ9jfRVRD0g4WvqSKStDTBgykFeqoy7Uw@mail.gmail.com>

On Mon, Jun 24, 2019 at 01:44:18PM +0200, Juan José Santamaría Flecha wrote:
> The updated patches include:
> 
> 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 >= 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

Attachments:

msvc-openssl-110-v2.patch (text/x-diff, 4.8K) download 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; } +# 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 = shift; + + # Attempt to get OpenSSL version and location. This assumes that + # openssl.exe is in the specified directory. + my $opensslcmd = + $self->{options}->{openssl} . "\\bin\\openssl.exe version 2>&1"; + my $sslout = `$opensslcmd`; + + $? >> 8 == 0 + or croak + "Unable to determine OpenSSL version: The openssl.exe command wasn't found."; + + if ($sslout =~ /(\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 = 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}); 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 = 1; + $libsslpath = '\lib\VC\libssl32.lib'; + $libcryptopath = '\lib\VC\libcrypto32.lib'; + } + elsif (-e "$self->{options}->{openssl}/lib/VC/sslcrypto64MD.lib") + { + # Win64 here, with a debugging library set. + $dbgsuffix = 1; + $libsslpath = '\lib\VC\libssl64.lib'; + $libcryptopath = '\lib\VC\libcrypto64.lib'; + } + else + { + # On both Win32 and Win64 the same library + # names are used without a debugging context. + $dbgsuffix = 0; + $libsslpath = '\lib\libssl.lib'; + $libcryptopath = '\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})
signature.asc (application/pgp-signature, 832B) download

view thread (18+ messages)  latest in thread

Message-ID: <20190625080811.GF5569@paquier.xyz>
Permalink:  ../20190625080811.GF5569@paquier.xyz/
Also on:    postgresql.org/message-id/20190625080811.GF5569@paquier.xyz

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: michael@paquier.xyz, juanjo.santamaria@gmail.com, sandeep.thakkar@enterprisedb.com, 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
  In-Reply-To: <20190625080811.GF5569@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox