From patchwork Wed Jul 4 21:42:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 939592 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41LZH20lYkz9s2R for ; Thu, 5 Jul 2018 07:43:08 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 121D624346; Wed, 4 Jul 2018 21:43:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id L2342jX0CUfJ; Wed, 4 Jul 2018 21:43:04 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 4DE9C22E96; Wed, 4 Jul 2018 21:43:04 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 9F3D51CF2B6 for ; Wed, 4 Jul 2018 21:43:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 9C32F8848F for ; Wed, 4 Jul 2018 21:43:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PAlmyIptfGF0 for ; Wed, 4 Jul 2018 21:43:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.bootlin.com (mail.bootlin.com [62.4.15.54]) by whitealder.osuosl.org (Postfix) with ESMTP id E509B88485 for ; Wed, 4 Jul 2018 21:43:01 +0000 (UTC) Received: by mail.bootlin.com (Postfix, from userid 110) id 89E99207BD; Wed, 4 Jul 2018 23:42:58 +0200 (CEST) Received: from localhost (LFbn-TOU-1-88-197.w86-201.abo.wanadoo.fr [86.201.177.197]) by mail.bootlin.com (Postfix) with ESMTPSA id 5919420719; Wed, 4 Jul 2018 23:42:58 +0200 (CEST) From: Thomas Petazzoni To: Romain Naour , "Yann E. MORIN" , Thomas De Schampheleire , Buildroot List Date: Wed, 4 Jul 2018 23:42:57 +0200 Message-Id: <20180704214257.6849-1-thomas.petazzoni@bootlin.com> X-Mailer: git-send-email 2.14.4 Subject: [Buildroot] [PATCH] toolchain: improve musl check to support static toolchains X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Petazzoni MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" The check_musl function currently builds a program and verifies if the program interpreter starts with /lib/ld-musl. While this works fine for dynamically linked programs, this obviously doesn't work for a purely static musl toolchain such as [1]. There is no easy way to identify a toolchain as using the musl C library. For glibc, dynamic linking is always supported, so we look at the dynamic linker name. For uClibc, there is a distinctive uClibc_config.h header file. There is no such distinctive feature in musl. We end up resorting to looking for the string MUSL_LOCPATH, which is used by musl locale_map.c source file. This string has been present in musl since 2014. It certainly isn't a very stable or convincing solution to identify the C library as being musl, but it's the best we could find. Note that we are sure there is a libc.a file, because the check_unusable_toolchain function checks that there is a such a file. [1] http://autobuild.buildroot.net/toolchains/tarballs/br-arm-musl-static-2018.05.tar.bz2 Signed-off-by: Thomas Petazzoni Reviewed-by: Arnout Vandecappelle (Essensium/Mind) --- toolchain/helpers.mk | 9 +++------ toolchain/toolchain-external/pkg-toolchain-external.mk | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk index 1792286add..e5520c00c3 100644 --- a/toolchain/helpers.mk +++ b/toolchain/helpers.mk @@ -241,14 +241,11 @@ check_glibc = \ # $2: cross-readelf path check_musl = \ __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*; \ + libc_a_path=`$${__CROSS_CC} -print-file-name=libc.a` ; \ + if ! strings $${libc_a_path} | grep -q MUSL_LOCPATH ; then \ echo "Incorrect selection of the C library" ; \ exit -1; \ - fi ; \ - rm -f $(BUILD_DIR)/.br-toolchain-test.tmp* + fi # # 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 8b2c283654..02d992531d 100644 --- a/toolchain/toolchain-external/pkg-toolchain-external.mk +++ b/toolchain/toolchain-external/pkg-toolchain-external.mk @@ -557,8 +557,7 @@ define $(2)_CONFIGURE_CMDS $$(call check_uclibc,$$$${SYSROOT_DIR}) ; \ elif test "$$(BR2_TOOLCHAIN_EXTERNAL_MUSL)" = "y" ; then \ $$(call check_musl,\ - "$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)",\ - $$(TOOLCHAIN_EXTERNAL_READELF)) ; \ + "$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)") ; \ else \ $$(call check_glibc,$$$${SYSROOT_DIR}) ; \ fi