From patchwork Sun Jul 2 13:41:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 783186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3x0rzG1lWlz9sNn for ; Sun, 2 Jul 2017 23:42:02 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id F0D432EBB7; Sun, 2 Jul 2017 13:41:54 +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 ItrxmL3FtTsV; Sun, 2 Jul 2017 13:41:54 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id E9DF622F02; Sun, 2 Jul 2017 13:41:52 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 215EE1C41FC for ; Sun, 2 Jul 2017 13:41:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 1BF592D6A4 for ; Sun, 2 Jul 2017 13:41:45 +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 WxJrgQeNe1+H for ; Sun, 2 Jul 2017 13:41:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.free-electrons.com (mail.free-electrons.com [62.4.15.54]) by silver.osuosl.org (Postfix) with ESMTP id 928312D3AF for ; Sun, 2 Jul 2017 13:41:43 +0000 (UTC) Received: by mail.free-electrons.com (Postfix, from userid 110) id A1B7820956; Sun, 2 Jul 2017 15:41:40 +0200 (CEST) Received: from localhost (ARennes-651-1-1-150.w86-215.abo.wanadoo.fr [86.215.144.150]) by mail.free-electrons.com (Postfix) with ESMTPSA id 6BC0120958; Sun, 2 Jul 2017 15:41:30 +0200 (CEST) From: Thomas Petazzoni To: Buildroot List , Thomas De Schampheleire , Ilya Kuzmich , "Arnout Vandecappelle (Essensium/Mind)" Date: Sun, 2 Jul 2017 15:41:05 +0200 Message-Id: <20170702134107.11488-3-thomas.petazzoni@free-electrons.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170702134107.11488-1-thomas.petazzoni@free-electrons.com> References: <20170702134107.11488-1-thomas.petazzoni@free-electrons.com> Cc: Thomas Petazzoni Subject: [Buildroot] [PATCH 2/4] toolchain/helpers.mk: re-evaluate DESTDIR in copy_toolchain_lib_root X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" copy_toolchain_lib_root copies libraries from staging to target, resolving and copying symbolic links along the way. The most inner loop, a "while" loop, starts from an initial name, and if it's a symbolic link, gets resolved to the target, and the loop iterates until we reach a real file. However, the destination folder where the symbolic link or real file is created is computed in DESTDIR only once, before this loop starts. Therefore, this loop works fine when all symbolic links in the chain, and the real file all belong to the same directory. But it doesn't do the correct thing when the symbolic link and/or real file are in different folder. An example is Crosstool-NG musl toolchains, where the dynamic loader is in /lib/ld-musl*.so but points to ../usr/lib/libc.so. With the current logic, we copy /lib/ld-musl*.so to /lib, but we also copy libc.so to /lib instead of the expected /usr/lib. This currently doesn't cause any problem because the musl dynamic linker is manually created by the TOOLCHAIN_EXTERNAL_MUSL_LD_LINK hook. However, this logic has a number of problems, so in a followup commit, we are going to put the musl dynamic linker in TOOLCHAIN_EXTERNAL_LIBS, which will cause it to be copied by copy_toolchain_lib_root. But we obviously want the link and its target to be copied to the right place, hence this fix. Signed-off-by: Thomas Petazzoni --- toolchain/helpers.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk index 90834f4..fe2b4b9 100644 --- a/toolchain/helpers.mk +++ b/toolchain/helpers.mk @@ -13,10 +13,10 @@ copy_toolchain_lib_root = \ \ LIBPATHS=`find $(STAGING_DIR)/ -name "$${LIBPATTERN}" 2>/dev/null` ; \ for LIBPATH in $${LIBPATHS} ; do \ - DESTDIR=`echo $${LIBPATH} | sed "s,^$(STAGING_DIR)/,," | xargs dirname` ; \ mkdir -p $(TARGET_DIR)/$${DESTDIR}; \ while true ; do \ LIBNAME=`basename $${LIBPATH}`; \ + DESTDIR=`echo $${LIBPATH} | sed "s,^$(STAGING_DIR)/,," | xargs dirname` ; \ rm -fr $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \ if test -h $${LIBPATH} ; then \ cp -d $${LIBPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \