Skip to contentSkip to conversation

xerces: fix static linking with mbedtls

PATCH New Fabrice Fontaine 2 participants 4 messages Oct 25, 2018 – Nov 3, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xerces: 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

---
 ...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
package/xerces/0003-fix-static-linking-with-mbedtls.patch new file +42 -0
new file mode 100644
index 0000000000..3523219555
@@ -0,0 +1,42 @@
+From f769f2c5979176ada5ea99d1b7914adc96e2e3d9 Mon Sep 17 00:00:00 2001
+From: Fabrice Fontaine <[email protected]>
+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 <[email protected]>
+---
+ 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
+
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 xerces: fix static linking with mbedtls

Hello Fabrice,

Quoted 10 lines · Fabrice Fontaine

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

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 xerces: fix static linking with mbedtls

Dear Thomas,
Le ven. 2 nov. 2018 ? 22:30, Thomas Petazzoni
<[email protected]> a ?crit :

Quoted 12 lines

Hello Fabrice,

Quoted 8 lines · Fabrice Fontaine

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

Quoted 8 lines
Quoted 2 lines

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.

Quoted 2 lines

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.

Quoted 24 lines

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.

Quoted 7 lines

Thanks,

Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Best Regards,

Fabrice

#3 lore raw

PATCH 1/1 xerces: fix static linking with mbedtls

Hello Fabrice,

Quoted 11 lines · Fabrice Fontaine

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

Quoted 4 lines
Quoted 1 line

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

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com