diff mbox series

[1/1] xerces: fix static linking with mbedtls

Message ID 20181025205402.10649-1-fontaine.fabrice@gmail.com
State Rejected
Headers show
Series [1/1] xerces: fix static linking with mbedtls | expand

Commit Message

Fabrice Fontaine Oct. 25, 2018, 8:54 p.m. UTC
curl can be statically linked with mbedtls, in this case build will
fail on:
kex.c:(.text+0x1be0): undefined reference to `mbedtls_mpi_read_binary'

This is due to the fact that CURL_LIBRARIES does not contain mbedtls
library:
CURL_LIBRARIES:INTERNAL=curl;cares;ssh2;ssh2;z;ssl;crypto;z;z;crypto;z;z;ssl;z;z;crypto;z

even if libcurl.pc is correct:
Libs.private: -lcares -lssh2 -L/home/fabrice/buildroot/output/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -lssh2 /home/fabrice/buildroot/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libmbedcrypto.a /home/fabrice/buildroot/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libmbedcrypto.a -L/home/fabrice/buildroot/output/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -L/home/fabrice/buildroot/output/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -lz -lssl -lcrypto -lssl -lz -lz -lcrypto -lz -lz

So to fix this replace CURL_LIBRARIES by CURL_LDFLAGS

Fixes:
 - http://autobuild.buildroot.org/results/dc7810d5d5c62658837cdd2faae6fe3390f968a2

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
---
 ...0003-fix-static-linking-with-mbedtls.patch | 42 +++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 package/xerces/0003-fix-static-linking-with-mbedtls.patch

Comments

Thomas Petazzoni Nov. 2, 2018, 9:30 p.m. UTC | #1
Hello Fabrice,

On Thu, 25 Oct 2018 22:54:02 +0200, Fabrice Fontaine wrote:
> curl can be statically linked with mbedtls, in this case build will
> fail on:
> kex.c:(.text+0x1be0): undefined reference to `mbedtls_mpi_read_binary'
> 
> This is due to the fact that CURL_LIBRARIES does not contain mbedtls
> library:
> CURL_LIBRARIES:INTERNAL=curl;cares;ssh2;ssh2;z;ssl;crypto;z;z;crypto;z;z;ssl;z;z;crypto;z
> 
> even if libcurl.pc is correct:
> Libs.private: -lcares -lssh2 -L/home/fabrice/buildroot/output/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -lssh2 /home/fabrice/buildroot/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libmbedcrypto.a /home/fabrice/buildroot/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libmbedcrypto.a -L/home/fabrice/buildroot/output/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -L/home/fabrice/buildroot/output/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -lz -lssl -lcrypto -lssl -lz -lz -lcrypto -lz -lz

A quick guess is that CURL_LIBRARIES doesn't mention mbedtls because
it's listed in Libs.private using a full path to the .a files rather
than using the gcc -l<something> flag.

Perhaps this is what should be fixed instead ?

BTW, do you have a minimal defconfig that exhibits this problem?

I tried with:

BR2_arm=y
BR2_STATIC_LIBS=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-arm-full-static-2018.05.tar.bz2"
BR2_TOOLCHAIN_EXTERNAL_GCC_6=y
BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_1=y
BR2_TOOLCHAIN_EXTERNAL_LOCALE=y
# BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_INIT_NONE=y
BR2_SYSTEM_BIN_SH_NONE=y
# BR2_PACKAGE_BUSYBOX is not set
BR2_PACKAGE_LIBSSH2=y
BR2_PACKAGE_MBEDTLS=y
BR2_PACKAGE_XERCES=y
BR2_PACKAGE_LIBCURL=y
# BR2_TARGET_ROOTFS_TAR is not set

but it build just fine.

Thanks,

Thomas
Fabrice Fontaine Nov. 2, 2018, 10:56 p.m. UTC | #2
Dear Thomas,
Le ven. 2 nov. 2018 à 22:30, Thomas Petazzoni
<thomas.petazzoni@bootlin.com> a écrit :
>
> Hello Fabrice,
>
> On Thu, 25 Oct 2018 22:54:02 +0200, Fabrice Fontaine wrote:
> > curl can be statically linked with mbedtls, in this case build will
> > fail on:
> > kex.c:(.text+0x1be0): undefined reference to `mbedtls_mpi_read_binary'
> >
> > This is due to the fact that CURL_LIBRARIES does not contain mbedtls
> > library:
> > CURL_LIBRARIES:INTERNAL=curl;cares;ssh2;ssh2;z;ssl;crypto;z;z;crypto;z;z;ssl;z;z;crypto;z
> >
> > even if libcurl.pc is correct:
> > Libs.private: -lcares -lssh2 -L/home/fabrice/buildroot/output/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -lssh2 /home/fabrice/buildroot/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libmbedcrypto.a /home/fabrice/buildroot/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libmbedcrypto.a -L/home/fabrice/buildroot/output/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -L/home/fabrice/buildroot/output/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -lz -lssl -lcrypto -lssl -lz -lz -lcrypto -lz -lz
>
> A quick guess is that CURL_LIBRARIES doesn't mention mbedtls because
> it's listed in Libs.private using a full path to the .a files rather
> than using the gcc -l<something> flag.
>
> Perhaps this is what should be fixed instead ?
The fullpath to mbedtls library in libcurl.pc was added by
https://patchwork.ozlabs.org/patch/917565. This patch was merged
upstream.
This fullpath in libssh2.pc was added by
http://patchwork.ozlabs.org/patch/888395.
This patch to libssh2 was not yet merged upstream so indeed we could
find an other solution.
For example, instead of adding $LIBMBEDCRYPTO (which contains the full
library path returned by AC_LIB_HAVE_LINKFLAGS) to LIBS, an other
solution would be to simply add -lmbedcrypto to LIBS.
If you agree, I can test this proposal and send a new patch to libssh2.
>
> BTW, do you have a minimal defconfig that exhibits this problem?
Nope, I used the autobuilder defconfig but I think you need
BR2_PACKAGE_LIBSSH2_MBEDTLS=y to build libssh2 with mbedtls instead of
openssl.
>
> I tried with:
>
> BR2_arm=y
> BR2_STATIC_LIBS=y
> BR2_TOOLCHAIN_EXTERNAL=y
> BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
> BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-arm-full-static-2018.05.tar.bz2"
> BR2_TOOLCHAIN_EXTERNAL_GCC_6=y
> BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_1=y
> BR2_TOOLCHAIN_EXTERNAL_LOCALE=y
> # BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set
> BR2_TOOLCHAIN_EXTERNAL_CXX=y
> BR2_INIT_NONE=y
> BR2_SYSTEM_BIN_SH_NONE=y
> # BR2_PACKAGE_BUSYBOX is not set
> BR2_PACKAGE_LIBSSH2=y
> BR2_PACKAGE_MBEDTLS=y
> BR2_PACKAGE_XERCES=y
> BR2_PACKAGE_LIBCURL=y
> # BR2_TARGET_ROOTFS_TAR is not set
>
> but it build just fine.
>
> Thanks,
>
> Thomas
> --
> Thomas Petazzoni, CTO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
Best Regards,

Fabrice
Thomas Petazzoni Nov. 3, 2018, 1:48 p.m. UTC | #3
Hello Fabrice,

On Fri, 2 Nov 2018 23:56:36 +0100, Fabrice Fontaine wrote:

> The fullpath to mbedtls library in libcurl.pc was added by
> https://patchwork.ozlabs.org/patch/917565. This patch was merged
> upstream.
> This fullpath in libssh2.pc was added by
> http://patchwork.ozlabs.org/patch/888395.
> This patch to libssh2 was not yet merged upstream so indeed we could
> find an other solution.
> For example, instead of adding $LIBMBEDCRYPTO (which contains the full
> library path returned by AC_LIB_HAVE_LINKFLAGS) to LIBS, an other
> solution would be to simply add -lmbedcrypto to LIBS.
> If you agree, I can test this proposal and send a new patch to libssh2.

Use LTLIBMBEDCRYPTO instead of LIBMBEDCRYPTO. We had the same problem
in the past, and that's how Romain Naour solved it:
http://lists.busybox.net/pipermail/buildroot/2017-May/192294.html

> > BTW, do you have a minimal defconfig that exhibits this problem?  
> Nope, I used the autobuilder defconfig but I think you need
> BR2_PACKAGE_LIBSSH2_MBEDTLS=y to build libssh2 with mbedtls instead of
> openssl.

It was set in my configuration, even if not visible in the minimal
defconfig.

Thanks!

Thomas
diff mbox series

Patch

diff --git a/package/xerces/0003-fix-static-linking-with-mbedtls.patch b/package/xerces/0003-fix-static-linking-with-mbedtls.patch
new file mode 100644
index 0000000000..3523219555
--- /dev/null
+++ b/package/xerces/0003-fix-static-linking-with-mbedtls.patch
@@ -0,0 +1,42 @@ 
+From f769f2c5979176ada5ea99d1b7914adc96e2e3d9 Mon Sep 17 00:00:00 2001
+From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
+Date: Thu, 25 Oct 2018 22:38:43 +0200
+Subject: [PATCH] fix static linking with mbedtls
+
+curl can be statically linked with mbedtls, in this case build will
+fail on:
+kex.c:(.text+0x1be0): undefined reference to `mbedtls_mpi_read_binary'
+
+This is due to the fact that CURL_LIBRARIES does not contain mbedtls
+library:
+CURL_LIBRARIES:INTERNAL=curl;cares;ssh2;ssh2;z;ssl;crypto;z;z;crypto;z;z;ssl;z;z;crypto;z
+
+even if libcurl.pc is correct:
+Libs.private: -lcares -lssh2 -L/home/fabrice/buildroot/output/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -lssh2 /home/fabrice/buildroot/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libmbedcrypto.a /home/fabrice/buildroot/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libmbedcrypto.a -L/home/fabrice/buildroot/output/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -L/home/fabrice/buildroot/output/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -lz -lssl -lcrypto -lssl -lz -lz -lcrypto -lz -lz
+
+So to fix this replace CURL_LIBRARIES by CURL_LDFLAGS
+
+Fixes:
+ - http://autobuild.buildroot.org/results/dc7810d5d5c62658837cdd2faae6fe3390f968a2
+
+Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
+---
+ src/CMakeLists.txt | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
+index c29aa257b..72e8648f4 100644
+--- a/src/CMakeLists.txt
++++ b/src/CMakeLists.txt
+@@ -1085,7 +1085,7 @@ endif()
+ if(XERCES_USE_NETACCESSOR_CURL)
+   list(APPEND libxerces_c_SOURCES ${curl_sources})
+   list(APPEND libxerces_c_HEADERS ${curl_headers})
+-  list(APPEND libxerces_c_DEPS ${CURL_LIBRARIES})
++  list(APPEND libxerces_c_DEPS ${CURL_LDFLAGS})
+ endif()
+ 
+ if(XERCES_USE_NETACCESSOR_SOCKET)
+-- 
+2.17.1
+