diff mbox

[1/1] toolchain-external: improve musl external check

Message ID 1489989370-22377-1-git-send-email-ilya.kuzmich@gmail.com
State Accepted
Headers show

Commit Message

Ilya Kuzmich March 20, 2017, 5:56 a.m. UTC
Test whether musl used or not: compile minimal C program and check if
interpreter contains /lib/ld-musl.

Signed-off-by: Ilya Kuzmich <ilya.kuzmich@gmail.com>
---
 toolchain/helpers.mk                                   | 13 +++++++++----
 toolchain/toolchain-external/pkg-toolchain-external.mk |  4 +++-
 2 files changed, 12 insertions(+), 5 deletions(-)

Comments

Thomas Petazzoni March 21, 2017, 10:18 p.m. UTC | #1
Hello,

On Mon, 20 Mar 2017 08:56:10 +0300, Ilya Kuzmich wrote:
> Test whether musl used or not: compile minimal C program and check if
> interpreter contains /lib/ld-musl.
> 
> Signed-off-by: Ilya Kuzmich <ilya.kuzmich@gmail.com>

This doesn't look bad, but what is the motivation behind the change? Is
the current check not working for you?

Thanks!

Thomas
Ilya Kuzmich March 22, 2017, 8:06 a.m. UTC | #2
Current check fails on crosstool-ng musl toolchain,
ctng puts libc.so at sysroot/usr/lib/, not sysroot/lib

On 21/03, Thomas Petazzoni wrote:
> Hello,
> 
> On Mon, 20 Mar 2017 08:56:10 +0300, Ilya Kuzmich wrote:
> > Test whether musl used or not: compile minimal C program and check if
> > interpreter contains /lib/ld-musl.
> > 
> > Signed-off-by: Ilya Kuzmich <ilya.kuzmich@gmail.com>
> 
> This doesn't look bad, but what is the motivation behind the change? Is
> the current check not working for you?
> 
> Thanks!
> 
> Thomas
> -- 
> Thomas Petazzoni, CTO, Free Electrons
> Embedded Linux and Kernel engineering
> http://free-electrons.com
Thomas Petazzoni March 22, 2017, 8:08 a.m. UTC | #3
Hello,

On Wed, 22 Mar 2017 11:06:51 +0300, Ilya Kuzmich wrote:
> Current check fails on crosstool-ng musl toolchain,
> ctng puts libc.so at sysroot/usr/lib/, not sysroot/lib

OK, thanks, makes sense. I'll update the commit log with this
explanation when applying.

Best regards,

Thomas
Thomas Petazzoni March 26, 2017, 7:41 p.m. UTC | #4
Hello,

On Mon, 20 Mar 2017 08:56:10 +0300, Ilya Kuzmich wrote:
> Test whether musl used or not: compile minimal C program and check if
> interpreter contains /lib/ld-musl.
> 
> Signed-off-by: Ilya Kuzmich <ilya.kuzmich@gmail.com>
> ---
>  toolchain/helpers.mk                                   | 13 +++++++++----
>  toolchain/toolchain-external/pkg-toolchain-external.mk |  4 +++-
>  2 files changed, 12 insertions(+), 5 deletions(-)

Applied to master, thanks. However, I had to make a preliminary fix
because TOOLCHAIN_EXTERNAL_READELF had a wrong value when Buildroot
external toolchains were used.

Thomas
Ilya Kuzmich April 3, 2017, 3:25 p.m. UTC | #5
Turns out this is not an end to the story.

TOOLCHAIN_EXTERNAL_MUSL_LD_LINK @ pkg-toolchain-external.mk assumes that
there is a /lib/libc.so. This is not a case for ct-ng musl toolchain.
Ct-ng does this: sysroot/lib/ld-musl-armhf.so.1 -> ../usr/lib/libc.so

How do i fix this?
I've poked around pkg-toolchain-external.mk, but to no avail.

On 26/03, Thomas Petazzoni wrote:
> Hello,
> 
> On Mon, 20 Mar 2017 08:56:10 +0300, Ilya Kuzmich wrote:
> > Test whether musl used or not: compile minimal C program and check if
> > interpreter contains /lib/ld-musl.
> > 
> > Signed-off-by: Ilya Kuzmich <ilya.kuzmich@gmail.com>
> > ---
> >  toolchain/helpers.mk                                   | 13 +++++++++----
> >  toolchain/toolchain-external/pkg-toolchain-external.mk |  4 +++-
> >  2 files changed, 12 insertions(+), 5 deletions(-)
> 
> Applied to master, thanks. However, I had to make a preliminary fix
> because TOOLCHAIN_EXTERNAL_READELF had a wrong value when Buildroot
> external toolchains were used.
> 
> Thomas
> -- 
> Thomas Petazzoni, CTO, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com
diff mbox

Patch

diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
index 2f73ebb..77303a8 100644
--- a/toolchain/helpers.mk
+++ b/toolchain/helpers.mk
@@ -197,13 +197,18 @@  check_glibc = \
 #
 # Check that the selected C library really is musl
 #
-# $1: sysroot directory
+# $1: cross-gcc path
+# $2: cross-readelf path
 check_musl = \
-	SYSROOT_DIR="$(strip $1)"; \
-	if test ! -f $${SYSROOT_DIR}/lib/libc.so -o -e $${SYSROOT_DIR}/lib/libm.so ; then \
+	__CROSS_CC=$(strip $1) ; \
+	__CROSS_READELF=$(strip $2) ; \
+	echo 'void main(void) {}' | $${__CROSS_CC} -x c -o $(BUILD_DIR)/.br-toolchain-test.tmp - >/dev/null 2>&1; \
+	if ! $${__CROSS_READELF} -l $(BUILD_DIR)/.br-toolchain-test.tmp 2> /dev/null | grep 'program interpreter: /lib/ld-musl' -q; then \
+		rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*; \
 		echo "Incorrect selection of the C library" ; \
 		exit -1; \
-	fi
+	fi ; \
+	rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*
 
 #
 # Check the conformity of Buildroot configuration with regard to the
diff --git a/toolchain/toolchain-external/pkg-toolchain-external.mk b/toolchain/toolchain-external/pkg-toolchain-external.mk
index 77b7bbb..8a774eb 100644
--- a/toolchain/toolchain-external/pkg-toolchain-external.mk
+++ b/toolchain/toolchain-external/pkg-toolchain-external.mk
@@ -565,7 +565,9 @@  define $(2)_CONFIGURE_CMDS
 	if test "$$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC)" = "y" ; then \
 		$$(call check_uclibc,$$$${SYSROOT_DIR}) ; \
 	elif test "$$(BR2_TOOLCHAIN_EXTERNAL_MUSL)" = "y" ; then \
-		$$(call check_musl,$$$${SYSROOT_DIR}) ; \
+		$$(call check_musl,\
+			"$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)",\
+			$$(TOOLCHAIN_EXTERNAL_READELF)) ; \
 	else \
 		$$(call check_glibc,$$$${SYSROOT_DIR}) ; \
 	fi