From 2bf569c6e4fa936b4d809b0517647db58b240cb8 Mon Sep 17 00:00:00 2001 From: Frank Hunleth Date: Tue, 21 Jun 2016 13:08:17 -0400 Subject: [PATCH] toolchain: allow crosstool-ng musl toolchains Currently, if using a crosstool-ng-generated external musl toolchain, Buildroot exits with "Incorrect selection of the C library". The musl.codu.org cross-compilers put their libraries in /lib while crosstool-ng uses /usr/lib. This change checks that location for libc.so and updates the ld-musl-$ARCH.so.1 symlink. Signed-off-by: Frank Hunleth --- toolchain/helpers.mk | 2 +- toolchain/toolchain-external/pkg-toolchain-external.mk | 6 +++++- toolchain/toolchain/toolchain.mk | 14 ++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk index 72e7292..42b69ee 100644 --- a/toolchain/helpers.mk +++ b/toolchain/helpers.mk @@ -209,7 +209,7 @@ check_glibc = \ # $1: sysroot directory check_musl = \ SYSROOT_DIR="$(strip $1)"; \ - if test ! -f $${SYSROOT_DIR}/lib/libc.so -o -e $${SYSROOT_DIR}/lib/libm.so ; then \ + if test ! \( -f $${SYSROOT_DIR}/lib/libc.so -o -f $${SYSROOT_DIR}/usr/lib/libc.so \) -o -e $${SYSROOT_DIR}/lib/libm.so ; then \ echo "Incorrect selection of the C library" ; \ exit -1; \ fi diff --git a/toolchain/toolchain-external/pkg-toolchain-external.mk b/toolchain/toolchain-external/pkg-toolchain-external.mk index 11a1bf5..ce37173 100644 --- a/toolchain/toolchain-external/pkg-toolchain-external.mk +++ b/toolchain/toolchain-external/pkg-toolchain-external.mk @@ -488,7 +488,11 @@ else MUSL_ARCH = $(ARCH) endif define TOOLCHAIN_EXTERNAL_MUSL_LD_LINK - ln -sf libc.so $(TARGET_DIR)/lib/ld-musl-$(MUSL_ARCH).so.1 + if [ -e $(STAGING_DIR)/usr/lib/libc.so ]; then \ + ln -sf ../usr/lib/libc.so $(TARGET_DIR)/lib/ld-musl-$(MUSL_ARCH).so.1 ; \ + else \ + ln -sf libc.so $(TARGET_DIR)/lib/ld-musl-$(MUSL_ARCH).so.1 ; \ + fi endef endif diff --git a/toolchain/toolchain/toolchain.mk b/toolchain/toolchain/toolchain.mk index b16db01..258068d 100644 --- a/toolchain/toolchain/toolchain.mk +++ b/toolchain/toolchain/toolchain.mk @@ -24,12 +24,14 @@ TOOLCHAIN_ADD_TOOLCHAIN_DEPENDENCY = NO # [1] http://www.openwall.com/lists/musl/2015/10/08/2 ifeq ($(BR2_TOOLCHAIN_USES_MUSL),y) define TOOLCHAIN_MUSL_KERNEL_HEADERS_COMPATIBILITY_HACK - $(SED) 's/^#if defined(__GLIBC__)$$/#if 1/' \ - $(STAGING_DIR)/usr/include/linux/libc-compat.h - $(SED) '1s/^/#define __USE_MISC\n/' \ - $(STAGING_DIR)/usr/include/linux/libc-compat.h - $(SED) '1s/^/#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 0\n/' \ - $(STAGING_DIR)/usr/include/linux/libc-compat.h + if [ -e $(STAGING_DIR)/usr/include/linux/libc-compat.h ]; then \ + $(SED) 's/^#if defined(__GLIBC__)$$/#if 1/' \ + $(STAGING_DIR)/usr/include/linux/libc-compat.h; \ + $(SED) '1s/^/#define __USE_MISC\n/' \ + $(STAGING_DIR)/usr/include/linux/libc-compat.h; \ + $(SED) '1s/^/#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 0\n/' \ + $(STAGING_DIR)/usr/include/linux/libc-compat.h; \ + fi endef TOOLCHAIN_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_MUSL_KERNEL_HEADERS_COMPATIBILITY_HACK TOOLCHAIN_INSTALL_STAGING = YES -- 2.7.4