Missing -lpthread for libssl / libcrypto (LibreSSL) when compiling U-Boot

Andre Heider a.heider at gmail.com
Wed Oct 13 05:22:42 PDT 2021


How about the two attached patches?
That's on top of the libressl bump for u-boot.

I only built uboot-mvebu with these and didn't check if this works for 
the others.

On 13/10/2021 10:10, Rafał Miłecki wrote:
> *** Introduction ***
> 
> OpenWrt compiles U-Boot with some host tools like mkimage.
> 
> 
> *** Problem ***
> 
>    HOSTLD  tools/mkimage
> /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: 
> /home/rmilecki/openwrt/openwrt-master-bcm4908/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/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: 
> /home/rmilecki/openwrt/openwrt-master-bcm4908/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/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: 
> /home/rmilecki/openwrt/openwrt-master-bcm4908/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'
> 
> It seems that OpenWrt wants to compile mkimage with statically linked
> LibreSSL.
> 
> LibreSSL seems to be compiled OK:
> $ grep Libs staging_dir/host/lib/pkgconfig/libcrypto.pc
> Libs: -L${libdir} -lcrypto
> Libs.private: -lresolv -lpthread
> 
> Related:
> 9bfca308268e ("uboot-mvebu: Fix build with libressl 2.7.2")
> 
> 
> *** Manual pkg-config test ***
> 
> I'm not sure if I test it correctly but output looks OK:
> 
> $ 
> PATH=/home/rmilecki/openwrt/openwrt-master-bcm4908/staging_dir/host/bin:$PATH 
> ./staging_dir/host/bin/pkg-config --libs libssl libcrypto
> -L/lib64 -lssl -lcrypto
> 
> $ 
> PATH=/home/rmilecki/openwrt/openwrt-master-bcm4908/staging_dir/host/bin:$PATH 
> ./staging_dir/host/bin/pkg-config --static --libs libssl libcrypto
> -L/lib64 -lssl -lresolv -lpthread -lcrypto -L/lib64 -lresolv -lpthread 
> -lcrypto -lresolv -lpthread
> 
> 
> *** U-Boot code ***
> 
> In tools/Makefile it uses:
> 
> HOSTLOADLIBES_mkimage += \
>      $(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo 
> "-lssl -lcrypto")
> 
> Above works for most cases. Adding -pthread was rejected, see:
> [U-Boot] [PATCH] Add -pthread to HOSTLOADLIBES_mkimage
> https://patchwork.ozlabs.org/project/uboot/patch/BEFD3339-5C21-407C-85BA-86BA2BB505A4@icognize.de/ 
> 
> 
> I guess OpenWrt is special case with static linking.
> 
> First of all I'm not sure if that pkg-config shouldn't use --static. I
> have no idea how to tell U-Boot we want mkimage built static.
> 
> Secondly for some reason pkg-config doesn't seem to work from U-Boot
> build context. After dropping "2> /dev/null" I can see:
> 
> Package libssl was not found in the pkg-config search path.
> Perhaps you should add the directory containing `libssl.pc'
> to the PKG_CONFIG_PATH environment variable
> Package 'libssl', required by 'virtual:world', not found
> Package 'libcrypto', required by 'virtual:world', not found
> Package libssl was not found in the pkg-config search path.
> Perhaps you should add the directory containing `libssl.pc'
> to the PKG_CONFIG_PATH environment variable
> Package 'libssl', required by 'virtual:world', not found
> Package 'libcrypto', required by 'virtual:world', not found
> Package libssl was not found in the pkg-config search path.
> Perhaps you should add the directory containing `libssl.pc'
> to the PKG_CONFIG_PATH environment variable
> Package 'libssl', required by 'virtual:world', not found
> Package 'libcrypto', required by 'virtual:world', not found
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-libressl-update-pc-files-to-always-include-private-l.patch
Type: text/x-patch
Size: 2342 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20211013/314c1bad/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-u-boot-fix-pkg-config-usage.patch
Type: text/x-patch
Size: 2976 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20211013/314c1bad/attachment-0003.bin>


More information about the openwrt-devel mailing list