Re: Libpq linked statically linked to OpenSSL/LibreSSL

From: Marco Bambini <marco(at)creolabs(dot)com>
To: ALBERTO CABELLO SÁNCHEZ <alberto(at)unex(dot)es>
Cc: "pgsql-interfaces(at)lists(dot)postgresql(dot)org" <pgsql-interfaces(at)lists(dot)postgresql(dot)org>
Subject: Re: Libpq linked statically linked to OpenSSL/LibreSSL
Date: 2022-12-06 10:05:49
Message-ID: 10650109-6ECE-4F7D-9014-2785AA2D413B@creolabs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Hi,

I made some progresses, especially in understanding where the issue can be.

I started with a fresh postgresql-15.1 source code installation:
# ./configure --with-openssl --without-readline

I then modified the Makefile.global in the src directory by replacing the occurrences of -lssl and -lcrypto with:
/root/rothsoft/libressl-3.6.1/ssl/.libs/libssl.a /root/rothsoft/libressl-3.6.1/crypto/.libs/libcrypto.a
in the LIBS entry.

Then from src/interfaces/libpq I executed:
# make

libpq was successfully created but when I perform a:
# nm -D libpq.so

the output looks like:

000000000001f110 T appendBinaryPQExpBuffer
000000000001f000 T appendPQExpBuffer
000000000001f0d0 T appendPQExpBufferChar
000000000001f150 T appendPQExpBufferStr
U ASN1_STRING_data
U ASN1_STRING_length
U BIO_clear_flags
U BIO_int_ctrl
U BIO_new
U BIO_set_flags
U BIO_s_socket
U calloc
U close
U connect
000000000001ecd0 T createPQExpBuffer
U CRYPTO_get_id_callback
U CRYPTO_get_locking_callback
U CRYPTO_num_locks
U CRYPTO_set_id_callback
U CRYPTO_set_locking_callback
U __ctype_b_loc
U __ctype_tolower_loc
U __ctype_toupper_loc
w __cxa_finalize
000000000001ed30 T destroyPQExpBuffer
U ENGINE_by_id
U ENGINE_finish
U ENGINE_free
U ENGINE_init
U ENGINE_load_private_key
000000000001ed90 T enlargePQExpBuffer
U ERR_clear_error
U ERR_get_error
U __errno_location
U ERR_put_error
U ERR_reason_error_string
U EVP_DigestFinal_ex
U EVP_DigestInit_ex
...

Please notice all the U entries in the crypto/ssl functions, so it looks like that they are NOT statically linked inside the libpq.so shared library, even if I replaced the LIBS in the Makefile.

Anyone can help me with this issue?

Thanks,
Marco

> On 5 Dec 2022, at 17:47, Marco Bambini <marco(at)creolabs(dot)com> wrote:
>
> Thanks Alberto,
>
> This is a very promising approach.
>
> I tried to modify the Makefile in src/interfaces/libpq/Makefile and I replaced the occurrences of -lssl and -lcrypto with:
> /root/rothsoft/libressl-3.6.1/ssl/.libs/libssl.a
> /root/rothsoft/libressl-3.6.1/crypto/.libs/libcrypto.a
>
> The compilation process is OK but when I tried to execute the test app I receive a link error:
> Error loading DLL: /root/rothsoft/engines/postgreSQL/Linux/postgresql/libpq.so: undefined symbol: GENERAL_NAME_free
>
> GENERAL_NAME_free usually means that libcrypto is missed.
>
> Any help would be really appreciated.
>
> Please note that I also tried with:
> -l:/root/rothsoft/libressl-3.6.1/ssl/.libs/libssl.a
> -l:/root/rothsoft/libressl-3.6.1/crypto/.libs/libcrypto.a
>
> Thanks,
> Marco
>
>
>> On 5 Dec 2022, at 14:10, ALBERTO CABELLO SÁNCHEZ <alberto(at)unex(dot)es> wrote:
>>
>>>> Hi all,
>>>>
>>>> After several attempts, I am asking for help with how to compile libpq with OpenSSL
>>>> statically linked.
>>>> I need to have libpq linked with LibreSSL, but if I could statically link OpenSSL, I think
>>>> I could switch the TLS libraries at compile time.
>>>
>>> redo the step which creates libpq.so appending your libssl.a location
>>> (mine is /usr/lib/x86_64-linux-gnu/libssl.a) at the end.
>>
>> Just wanted to correct: you also have to remove "-lssl". So I guess you can just
>> substitute "-lssl" for libssl.a location in src/interfaces/libpq/Makefile (two occurrences)
>> and build as usual.
>>
>
>
>

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Andres Freund 2022-12-06 18:01:00 Re: Libpq linked statically linked to OpenSSL/LibreSSL
Previous Message Marco Bambini 2022-12-05 16:47:07 Re: Libpq linked statically linked to OpenSSL/LibreSSL