tpm2-software / tpm2-tss

OSS implementation of the TCG TPM2 Software Stack (TSS2)
https://tpm2-software.github.io
BSD 2-Clause "Simplified" License
745 stars 364 forks source link

Arm64 Build #2887

Open Bab95 opened 2 months ago

Bab95 commented 2 months ago

I am building tpm2-tss repo on Arm64 arch ubuntu20.04 machine and facing missing openssl error while running configure command. I have build openssl 3.2.0 on the same machine and added path as well as defined in LDFLAGS and CFLAGS. Following are the flags and values i have configured.

babnishvyas@bab-arm-linux:/usr/src/tpm2-tss$ curl -V
curl 8.5.0 (aarch64-unknown-linux-gnu) libcurl/8.5.0 OpenSSL/3.2.0
Release-Date: 2023-12-06
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS HSTS HTTPS-proxy IPv6 Largefile NTLM SSL threadsafe TLS-SRP UnixSockets
babnishvyas@bab-arm-linux:/usr/src/tpm2-tss$ openssl -v
OpenSSL 3.2.0 23 Nov 2023 (Library: OpenSSL 3.2.0 23 Nov 2023)

image

when i run configure command i get libcrypto not found error image

image

full configure command output

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking whether to enable debugging... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of gcc... gcc3
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking whether ln -s works... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking the maximum length of command line arguments... 1572864
checking how to convert aarch64-unknown-linux-gnu file names to aarch64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert aarch64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC -DPIC
checking if g++ PIC flag -fPIC -DPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking for library containing dlopen... -ldl
checking for dlerror... yes
checking for shl_load... no
checking for shl_load in -ldld... no
checking for dld_link in -ldld... no
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for strndup... yes
checking for reallocarray... yes
checking for CRYPTO... no
configure: error: OpenSSL libcrypto is missing or version requirements not met. OpenSSL version must be >= 1.1.0

I am not sure what am I missing here. is there any problem in building it on arm64?

joholl commented 2 months ago

For ./configure to be happy, pkg-config must find your library. It is not sufficient to set the LDFLAGS. If pkg-config finds your .pc file, it will tell the LDFLAGS/CFLAGS to automake, anyway.

If you installed openssl via dpkg/apt, see https://github.com/tpm2-software/tpm2-tss/issues/2866#issuecomment-2247074872.

If you installed openssl manually (i.e. not via dpkg/apt), you might need to change your install location or set PKG_CONFIG_PATH to make pkg-config find the .pc file (which is generated in the openssl build step)

Bab95 commented 2 months ago

defining PKG_CONFIG_PATH doesn't make any difference, Issue is still the same.

image
Bab95 commented 2 months ago

Manually providing the CRYPTO_LIBS and other flags resolve the above issue but still causing problems in make command.

./configure CRYPTO_LIBS=-L/usr/local/arm64/openssl/lib CRYPTO_CFLAGS=-I/usr/local/arm64/openssl/include CURL_LIBS=-L/usr/local/arm64/curl/lib CURL_CFLAGS=-I/usr/local/arm64/curl/include

/usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in function iesys_cryptossl_context_new': esys_crypto_ossl.c:(.text+0x34): undefined reference toOSSL_LIB_CTX_new' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in function iesys_bn2binpad': esys_crypto_ossl.c:(.text+0xb4): undefined reference toBN_num_bits' /usr/bin/ld: esys_crypto_ossl.c:(.text+0xe8): undefined reference to BN_bn2bin' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in functioniesys_cryptossl_context_set_hash_md.isra.0': esys_crypto_ossl.c:(.text+0x174): undefined reference to EVP_MD_fetch' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in functioniesys_cryptossl_context_free.part.0': esys_crypto_ossl.c:(.text+0x220): undefined reference to EVP_MD_CTX_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x228): undefined reference toEVP_MD_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x230): undefined reference to OSSL_LIB_CTX_free' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in functioniesys_cryptossl_hash_start': esys_crypto_ossl.c:(.text+0x32c): undefined reference to EVP_MD_CTX_new' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x33c): undefined reference toEVP_DigestInit' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in function iesys_cryptossl_hash_update': esys_crypto_ossl.c:(.text+0x634): undefined reference toEVP_DigestUpdate' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in function iesys_cryptossl_hash_finish': esys_crypto_ossl.c:(.text+0x814): undefined reference toEVP_DigestFinal' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in function iesys_cryptossl_hmac_start': esys_crypto_ossl.c:(.text+0xcbc): undefined reference toEVP_MD_CTX_new' /usr/bin/ld: esys_crypto_ossl.c:(.text+0xcd8): undefined reference to EVP_PKEY_new_raw_private_key' /usr/bin/ld: esys_crypto_ossl.c:(.text+0xcf4): undefined reference toEVP_DigestSignInit' /usr/bin/ld: esys_crypto_ossl.c:(.text+0xd50): undefined reference to EVP_PKEY_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0xe50): undefined reference toEVP_PKEY_free' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in function iesys_cryptossl_hmac_update': esys_crypto_ossl.c:(.text+0x1070): undefined reference toEVP_DigestSignUpdate' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in function iesys_cryptossl_hmac_finish': esys_crypto_ossl.c:(.text+0x12c0): undefined reference toEVP_DigestSignFinal' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in function iesys_cryptossl_random2b': esys_crypto_ossl.c:(.text+0x1650): undefined reference toOSSL_LIB_CTX_new' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1678): undefined reference to RAND_bytes_ex' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1684): undefined reference toOSSL_LIB_CTX_free' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in function iesys_cryptossl_pk_encrypt': esys_crypto_ossl.c:(.text+0x17a0): undefined reference toOSSL_LIB_CTX_new' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x17dc): undefined reference to EVP_MD_fetch' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1868): undefined reference toEVP_PKEY_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1874): undefined reference to EVP_MD_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x187c): undefined reference toOSSL_LIB_CTX_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1914): undefined reference to BN_bin2bn' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1920): undefined reference toOSSL_PARAM_BLD_new' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1938): undefined reference to OSSL_PARAM_BLD_push_BN' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1950): undefined reference toOSSL_PARAM_BLD_push_uint32' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x19c0): undefined reference to EVP_PKEY_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x19cc): undefined reference toBN_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x19d8): undefined reference to OSSL_PARAM_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x19e4): undefined reference toOSSL_PARAM_BLD_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1a08): undefined reference to OSSL_PARAM_BLD_to_param' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1a24): undefined reference toEVP_PKEY_CTX_new_from_name' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1a30): undefined reference to EVP_PKEY_fromdata_init' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1a50): undefined reference toEVP_PKEY_fromdata' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1a6c): undefined reference to EVP_PKEY_CTX_new' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1a80): undefined reference toEVP_PKEY_encrypt_init' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1af8): undefined reference to EVP_PKEY_CTX_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1b00): undefined reference toEVP_PKEY_CTX_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1b74): undefined reference to EVP_PKEY_CTX_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1b84): undefined reference toBN_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1c08): undefined reference to OSSL_LIB_CTX_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1c60): undefined reference toBN_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1c74): undefined reference to EVP_PKEY_CTX_set_rsa_padding' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1d08): undefined reference toCRYPTO_strdup' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1d34): undefined reference to EVP_PKEY_CTX_set0_rsa_oaep_label' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1d58): undefined reference toCRYPTO_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1e20): undefined reference to EVP_PKEY_CTX_set_rsa_oaep_md' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1eb4): undefined reference toEVP_PKEY_encrypt' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x1ef4): undefined reference to EVP_PKEY_encrypt' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in functioniesys_cryptossl_get_ecdh_point': esys_crypto_ossl.c:(.text+0x2138): undefined reference to EC_GROUP_new_by_curve_name' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2150): undefined reference toEVP_PKEY_CTX_new_id' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x215c): undefined reference to EVP_PKEY_keygen_init' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2170): undefined reference toEVP_PKEY_CTX_set_ec_paramgen_curve_nid' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2184): undefined reference to EVP_PKEY_keygen' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x21a0): undefined reference toEVP_PKEY_get_bn_param' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x21b8): undefined reference to EVP_PKEY_get_bn_param' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x223c): undefined reference toEC_GROUP_new_by_curve_name' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x23d4): undefined reference to EC_GROUP_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x23dc): undefined reference toEVP_PKEY_CTX_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x23e8): undefined reference to EVP_PKEY_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x23f8): undefined reference toBN_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2408): undefined reference to BN_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2418): undefined reference toBN_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2490): undefined reference to EC_GROUP_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x250c): undefined reference toEVP_PKEY_get_bn_param' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2624): undefined reference to BN_bin2bn' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x263c): undefined reference toBN_bin2bn' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x264c): undefined reference to EC_POINT_new' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x266c): undefined reference toEC_POINT_set_affine_coordinates' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x267c): undefined reference to EC_POINT_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x26e0): undefined reference toBN_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x26e8): undefined reference to BN_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2744): undefined reference toEC_GROUP_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2758): undefined reference to EC_POINT_is_on_curve' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2768): undefined reference toBN_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2770): undefined reference to BN_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2778): undefined reference toEC_POINT_new' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x279c): undefined reference to EC_POINT_mul' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2808): undefined reference toEC_POINT_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2810): undefined reference to EC_POINT_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2828): undefined reference toEC_POINT_get_affine_coordinates' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2a78): undefined reference to BN_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2afc): undefined reference toBN_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2b04): undefined reference to BN_free' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in functioniesys_cryptossl_sym_aes_encrypt': esys_crypto_ossl.c:(.text+0x2cd4): undefined reference to EVP_aes_256_cfb128' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2ce8): undefined reference toEVP_CIPHER_CTX_new' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2d00): undefined reference to EVP_EncryptInit' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2d24): undefined reference toEVP_EncryptUpdate' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2d80): undefined reference to EVP_CIPHER_CTX_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2d94): undefined reference toEVP_aes_128_cfb128' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2ee8): undefined reference to EVP_aes_192_cfb128' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x2f00): undefined reference toEVP_EncryptFinal' /usr/bin/ld: src/tss2-esys/.libs/libtss2_esys_la-esys_crypto_ossl.o: in function iesys_cryptossl_sym_aes_decrypt': esys_crypto_ossl.c:(.text+0x30b0): undefined reference toEVP_aes_256_cfb128' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x30b8): undefined reference to EVP_CIPHER_CTX_new' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x312c): undefined reference toEVP_DecryptInit' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x3184): undefined reference to EVP_CIPHER_CTX_free' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x31c8): undefined reference toEVP_aes_128_cfb128' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x31d0): undefined reference to EVP_CIPHER_CTX_new' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x325c): undefined reference toEVP_DecryptUpdate' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x3274): undefined reference to EVP_DecryptFinal' /usr/bin/ld: esys_crypto_ossl.c:(.text+0x337c): undefined reference toEVP_aes_192_cfb128' collect2: error: ld returned 1 exit status make[1]: [Makefile:12327: src/tss2-esys/libtss2-esys.la] Error 1 make[1]: Leaving directory '/usr/src/tpm2-tss' make: [Makefile:11692: all] Error 2

Bab95 commented 2 months ago

To all the people who struggled out there following command worked ./configure CRYPTO_LIBS="-L/usr/local/arm64/openssl/lib -lssl -lcrypto" CRYPTO_CFLAGS="-I/usr/local/arm64/openssl/include" CURL_LIBS="-L/usr/local/arm64/curl/lib -lcurl" CURL_CFLAGS="-I/usr/local/arm64/curl/include" CFLAGS="-I/usr/local/arm64/openssl/include"

probably CRYPTO_CFLAGS could be dropped. I don't know haven't checked. but i would still like to know why pkg-config didn't work and why i had to define CRYPTO_LIBS flag and CURL_LIBS flag specifically forcing to find libs not even LDFLAGS setting was enough. If this is going to be the case then probably build instructions need to be updated. Weird combination of flags though linking done via specific flags and include needs to be set with CFLAGS