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

Submitted by Ilya Kuzmich on March 20, 2017, 5:56 a.m.

Details

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

Commit Message

Ilya Kuzmich March 20, 2017, 5:56 a.m.
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.
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.
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.
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

Patch hide | download patch | download mbox

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