Fails to build u-boot CONFIG_FIT_SIGNATURE with provided LibreSSL 2.9.2

When trying to compile u-boot with OpenWRT and CONFIG_FIT_SIGNATURE (or CONFIG_RSA) enabled, it fails to build due to missing symbols in/with LibreSSL 2.9.2 and pthread:

/usr/bin/ld: /home/bam/devel/allwinnerv3s/openwrtv3s/staging_dir/host/lib/libssl.a(ssl_init.o): in function `OPENSSL_init_ssl':
ssl_init.c:(.text+0x59): undefined reference to `pthread_once'
/usr/bin/ld: /home/bam/devel/allwinnerv3s/openwrtv3s/staging_dir/host/lib/libcrypto.a(libcrypto_la-crypto_init.o): in function `OPENSSL_init_crypto':
crypto_init.c:(.text+0x51): undefined reference to `pthread_once'
/usr/bin/ld: /home/bam/devel/allwinnerv3s/openwrtv3s/staging_dir/host/lib/libcrypto.a(libcrypto_la-conf_sap.o): in function `OpenSSL_config':
conf_sap.c:(.text+0xbc): undefined reference to `pthread_once'
/usr/bin/ld: /home/bam/devel/allwinnerv3s/openwrtv3s/staging_dir/host/lib/libcrypto.a(libcrypto_la-conf_sap.o): in function `OpenSSL_no_config':
conf_sap.c:(.text+0xf3): undefined reference to `pthread_once'
/usr/bin/ld: /home/bam/devel/allwinnerv3s/openwrtv3s/staging_dir/host/lib/libcrypto.a(libcrypto_la-eng_all.o): in function `ENGINE_load_builtin_engines':
eng_all.c:(.text+0x30): undefined reference to `pthread_once'
/usr/bin/ld: /home/bam/devel/allwinnerv3s/openwrtv3s/staging_dir/host/lib/libcrypto.a(libcrypto_la-err.o):err.c:(.text+0xa7e): more undefined references to `pthread_once' follow
collect2: error: ld returned 1 exit status

It is missing pthread_once even tho it is linked to in LibreSSL 2.9.2
Any suggestions to fix this?

Its a bug in u-boots makefile not linking in pthread.
One can add a workaround in the OpenWRT u-boot makefile with

  HOSTLOADLIBES_mkimage="-pthread -lcrypto -lssl"

Its ugly but does the trick. Maybe I should submit a bug-report to u-boot.

You may also use the following patch, submitted to u-boot:

From a48643614cba7703f1ebbf92ecb5be5d73389f8a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Benedikt-Alexander=20Mokro=C3=9F?= <>
Date: Tue, 3 Dec 2019 09:52:34 +0100
Subject: [PATCH] Add -pthread to HOSTLOADLIBES_mkimage

On some unix distributions, pthread is not automatically linked.
This results in unresolved symbols when e.g. building u-boot via OpenWRT (using LibreSSL) in dumpimage and other host tools when i.E. CONFIG_FIT_SIGNATURE is set.
Using -pthread to link pthread should be portable across all distributions and OS X.

* Added -pthread to HOSTLOADLIBES_mkimage
 tools/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/Makefile b/tools/Makefile
index 24581adccd..2f122bed8e 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -150,7 +150,8 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_ARMADA_39X)$(CON
 HOSTCFLAGS_kwbimage.o += \
 	$(shell pkg-config --cflags libssl libcrypto 2> /dev/null || echo "")
 HOSTLOADLIBES_mkimage += \
-	$(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto")
+	$(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto") \
+	-pthread
 # OS X deprecate openssl in favour of CommonCrypto, supress deprecation
 # warnings on those systems

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.