jeroen / openssl

OpenSSL bindings for R
Other
65 stars 23 forks source link

Building error on Ubuntu 22.04 due to undefined symbol: PKCS12_SAFEBAG_free #103

Closed alazarolop closed 2 years ago

alazarolop commented 2 years ago

Hi,

I am unable to build the openssl R package on WSL Ubuntu 22.04 using R downloaded from RStudio site:

$ uname -a
Linux DESKTOP-3UFB8R8 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

$ R --version
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

I have installed and reinstalled openssl OS packages:

$ sudo apt reinstall libssl-dev libssl3
$ openssl version -a

OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)
built on: Thu May  5 08:04:52 2022 UTC
platform: debian-amd64
options:  bn(64,64)
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -Wa,--noexecstack -g -O2 -ffile-prefix-map=/build/openssl-Ke3YUO/openssl-3.0.2=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -DOPENSSL_TLS_SECURITY_LEVEL=2 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -Wdate-time -D_FORTIFY_SOURCE=2
OPENSSLDIR: "/usr/lib/ssl"
ENGINESDIR: "/usr/lib/x86_64-linux-gnu/engines-3"
MODULESDIR: "/usr/lib/x86_64-linux-gnu/ossl-modules"
Seeding source: os-specific
CPUINFO: OPENSSL_ia32cap=0xfeda32235f8bffff:0x9c27a9

When building the R package I get the following error:

** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘openssl’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/R/4.2.0/lib/R/site-library/00LOCK-openssl/00new/openssl/libs/openssl.so':
  /opt/R/4.2.0/lib/R/site-library/00LOCK-openssl/00new/openssl/libs/openssl.so: undefined symbol: PKCS12_SAFEBAG_free
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/opt/R/4.2.0/lib/R/site-library/openssl’

How could I fix it? Thanks

jeroen commented 2 years ago

Can you show the full installation log?

alazarolop commented 2 years ago

Sure, it is:

Installing package into ‘/opt/R/4.2.0/lib/R/site-library’
(as ‘lib’ is unspecified)
system (cmd0): /opt/R/4.2.0/lib/R/bin/R CMD INSTALL
trying URL 'https://cloud.r-project.org/src/contrib/openssl_2.0.1.tar.gz'
Content type 'application/x-gzip' length 1204569 bytes (1.1 MB)
==================================================
downloaded 1.1 MB

foundpkgs: openssl, /tmp/RtmpkmVNXm/downloaded_packages/openssl_2.0.1.tar.gz
files: /tmp/RtmpkmVNXm/downloaded_packages/openssl_2.0.1.tar.gz
* installing *source* package ‘openssl’ ...
** package ‘openssl’ successfully unpacked and MD5 sums checked
** using staged installation
Found pkg-config cflags and libs!
Using PKG_CFLAGS=
Using PKG_LIBS=-l:libssl.so.3 -l:libcrypto.so.3
** libs
rm -f aes.o base64.o bignum.o cert.o compatibility.o diffie.o envelope.o error.o hash.o info.o keygen.o keys.o onload.o openssh.o password.o pbkdf.o pem.o pkcs12.o pkcs7.o rand.o rsa.o signing.o ssl.o stream.o write.o x25519.o openssl.so bcrypt/libstatbcrypt.a bcrypt/bcrypt_pbkdf.o bcrypt/blowfish.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c aes.c -o aes.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c base64.c -o base64.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c bignum.c -o bignum.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c cert.c -o cert.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c compatibility.c -o compatibility.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c diffie.c -o diffie.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c envelope.c -o envelope.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c error.c -o error.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c hash.c -o hash.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c info.c -o info.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c keygen.c -o keygen.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c keys.c -o keys.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c onload.c -o onload.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c openssh.c -o openssh.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c password.c -o password.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c pbkdf.c -o pbkdf.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c pem.c -o pem.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c pkcs12.c -o pkcs12.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c pkcs7.c -o pkcs7.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c rand.c -o rand.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c rsa.c -o rsa.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c signing.c -o signing.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c ssl.c -o ssl.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c stream.c -o stream.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c write.c -o write.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c x25519.c -o x25519.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c bcrypt/bcrypt_pbkdf.c -o bcrypt/bcrypt_pbkdf.o
ccache gcc-11 -I"/opt/R/4.2.0/lib/R/include" -DNDEBUG -DOPENSSL_SUPPRESS_DEPRECATED  -I/usr/local/include  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -fpic  -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp -c bcrypt/blowfish.c -o bcrypt/blowfish.o
ar rcs bcrypt/libstatbcrypt.a bcrypt/bcrypt_pbkdf.o bcrypt/blowfish.o
ccache gcc-11 -shared -L/opt/R/4.2.0/lib/R/lib -L/usr/local/lib -o openssl.so aes.o base64.o bignum.o cert.o compatibility.o diffie.o envelope.o error.o hash.o info.o keygen.o keys.o onload.o openssh.o password.o pbkdf.o pem.o pkcs12.o pkcs7.o rand.o rsa.o signing.o ssl.o stream.o write.o x25519.o -fopenmp -lgomp -L/opt/R/4.2.0/lib/R/lib -lR
installing to /opt/R/4.2.0/lib/R/site-library/00LOCK-openssl/00new/openssl/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘openssl’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/R/4.2.0/lib/R/site-library/00LOCK-openssl/00new/openssl/libs/openssl.so':
  /opt/R/4.2.0/lib/R/site-library/00LOCK-openssl/00new/openssl/libs/openssl.so: undefined symbol: PKCS12_SAFEBAG_free
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/opt/R/4.2.0/lib/R/site-library/openssl’

The downloaded source packages are in
        ‘/tmp/RtmpkmVNXm/downloaded_packages’
Warning message:
In install.packages("openssl", verbose = TRUE) :
  installation of package ‘openssl’ had non-zero exit status
jeroen commented 2 years ago

How did you install R? It is using unusual settings. I suspect there is a conflicting version of libssl in /usr/local/lib which seems to be hardcoded in your CFLAGS.

Also why are you compiling with ccache gcc-11? Can you try compiling with just gcc ?

jeroen commented 2 years ago

Can you check if there is maybe a second conflicting openssl installation in /usr/local/include/openssl ? The only openssl installation should be under /usr/include/openssl.

alazarolop commented 2 years ago

Thank you a lot for the quick reply!

  1. I installed following instructions in RStudio, so I need to build packages from source.
curl -O https://cdn.rstudio.com/r/ubuntu-${OS_VERSION}/pkgs/r-${R_VERSION}_1_amd64.deb
sudo gdebi r-${R_VERSION}_1_amd64.deb
  1. Yes, I had ccache in Makevars. I erased it, but I got the same error.
  2. /usr/local/lib doesn't have any openssl folder inside. The same happens in usr/local/include/openssl.
  3. I see what you meant on /usr/local/lib harcoded. But I wasn't able to locate it (as I mentioned). I thought the problem could come from R build and installation process. Thus, I decided to create two new WSL (20.04 and 22.04) and follow the same installation process. I was able to install the openssl R package in 20.04, but it was throwing the issue in 22.04. I noticed 22.04 is using 3.0.2 version rather than the 1.1.1 version in 20.04. I wonder whether the problem could come from openssl building in 22.04 or maybe the R package not being able to cope with 3.0.2 (in Ubuntu 22.04)?
jeroen commented 2 years ago

What do you mean by "the same happens in usr/local/include/openssl"? Does that folder exist? If it exists you should delete it and try again.

I use ubuntu 22.04 myself and many other systems with openssl 3.0.2 so the problem is definitely in your configuration.

alazarolop commented 2 years ago

I am sorry that sound vague. I meant inside /usr/local/include/, the directory is fully empty. Inside /usr/local/lib/ there are two folder, but none related to openssl. Both directories don't contain any openssl folder.

I also checked pkg-config libssl -L -cflags and I couldn't see any path pointing to /usr/local/lib/. Could I force R to get the openssl directory I need by using configure.args?

jeroen commented 2 years ago

I just downloaded the same R as you did for ubuntu 22.04, but the result is very different. The problem happens in this line in your output:

ccache gcc-11 -shared -L/opt/R/4.2.0/lib/R/lib -L/usr/local/lib -o openssl.so aes.o base64.o bignum.o cert.o compatibility.o diffie.o envelope.o error.o hash.o info.o keygen.o keys.o onload.o openssh.o password.o pbkdf.o pem.o pkcs12.o pkcs7.o rand.o rsa.o signing.o ssl.o stream.o write.o x25519.o -fopenmp -lgomp -L/opt/R/4.2.0/lib/R/lib -lR

It looks like your linker flags are completely wrong. They show -fopenmp -lgomp instead of the libssl flags. Are you overriding PKG_LIBS or LDFLAGS in your local config?

On my own ubuntu 22.04 machine I see this

gcc -shared -L/opt/R/4.2.0/lib/R/lib -L/usr/local/lib -o openssl.so aes.o base64.o bignum.o cert.o compatibility.o diffie.o envelope.o error.o hash.o info.o keygen.o keys.o onload.o openssh.o password.o pbkdf.o pem.o pkcs12.o pkcs7.o rand.o rsa.o signing.o ssl.o stream.o write.o x25519.o -Lbcrypt -lstatbcrypt -l:libssl.so.3 -l:libcrypto.so.3 -L/opt/R/4.2.0/lib/R/lib -lR
jeroen commented 2 years ago

@alazarolop has your problem been solved? Can you check if your settings are overriding PKG_LIBS or LDFLAGS or similar?

alazarolop commented 2 years ago

Hi and sorry for the late response,

I tried to follow yours comments, but I couldn't figure out where the overriding was happening.

Recently, I've tried again after upgrading all the packages (openssl included) and it worked out-of-the-box in a vanilla installation (no config changes in WSL Ubuntu 22.04), so I guess the SO package was involved in the error. I guess the ticket can be now closed. Thank you a lot for your support.