From patchwork Mon Mar 13 03:26:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Neyman X-Patchwork-Id: 19542 Received: (qmail 19334 invoked by alias); 13 Mar 2017 03:26:32 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 19105 invoked by uid 89); 13 Mar 2017 03:26:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: nm1-vm4.access.bullet.mail.bf1.yahoo.com Received: from nm1-vm4.access.bullet.mail.bf1.yahoo.com (HELO nm1-vm4.access.bullet.mail.bf1.yahoo.com) (216.109.114.75) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 13 Mar 2017 03:26:13 +0000 Received: from [66.196.81.158] by nm1.access.bullet.mail.bf1.yahoo.com with NNFMP; 13 Mar 2017 03:26:12 -0000 Received: from [98.138.226.240] by tm4.access.bullet.mail.bf1.yahoo.com with NNFMP; 13 Mar 2017 03:26:12 -0000 Received: from [127.0.0.1] by smtp111.sbc.mail.ne1.yahoo.com with NNFMP; 13 Mar 2017 03:26:12 -0000 X-Yahoo-SMTP: 0h0Q7euswBD_g.kcEqbzJWRFfrba801gq1M1 To: gdb-patches@sourceware.org From: Alexey Neyman Subject: [PATCH] PowerPC: incorrect library search order? Message-ID: Date: Sun, 12 Mar 2017 20:26:10 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 Hi, The problem below resulted in failures of some PowerPC sample toolchains in crosstool-ng. As far as I understand, the code in ld/emulparams/elf32ppccommon.sh attempts to use /lib32 or /lib64 if the endianness of the selected emulation matches the endianness of the machine, and use the directories with explicit endianness (such as /lib32le, /lib32be, /lib64le, /lib64be) otherwise. However, there are two issues with that code: First, it checks for *host's* triplet, not target. The host may not be using 'le' suffix to designate its endianness - for example, it may be little-endian by default. It also doesn't seem to make much sense to check the host for default layout - why would the expected sysroot layout on a big-endian host differ from that on a little-endian host? Second, the check itself is flawed: it should be checking just the CPU part of the triplet, not the whole string. In its current form, the check compares $host against "*le-*" pattern - which matches "x86_64-apple-darwin16.0". This results in ld configured for powerpc64le-unknown-linux target on x86_64-unknown-linux host behaving as follows: - without -m, or with -melf64lppc it searches /lib64le first - with '-melf64ppc' it searches /lib64 first - which seems to run counter to the intended purpose of that code, as the target is configured as little-endian! 'ld' works ok with libraries in /lib (which is always searched as the last fallback, regardless of the host and selected emulation). Once the libraries are placed in /lib64 (default gcc's directory for this target), ld fails to find them. This erroneous code first appeared in binutils 2.24. Patch attached. Regards, Alexey. From cf2cf4ea661b8527d0fe48a9ffda1b02154d0c67 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sat, 11 Mar 2017 17:27:09 -0800 Subject: [PATCH] Fix library paths on PowerPC First, need to match against just the CPU name, not the whole triplet. Otherwise, the test picks up "*le-*" pattern from x86_64-apple-darwin triplet. Second, it should be testing for $target, not $host. Host may be little endian by default, and the sysroot directory layout shouldn't depend on whether it is built on LE or BE machine. Signed-off-by: Alexey Neyman --- ld/emulparams/elf32ppccommon.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ld/emulparams/elf32ppccommon.sh b/ld/emulparams/elf32ppccommon.sh index 1f54ef8..d00cf68 100644 --- a/ld/emulparams/elf32ppccommon.sh +++ b/ld/emulparams/elf32ppccommon.sh @@ -44,11 +44,11 @@ fi # Look for 64 bit target libraries in /lib64, /usr/lib64 etc., first. # Similarly, look for 32 bit libraries in /lib32, /usr/lib32 etc. -case "$host":"$EMULATION_NAME" in - *le-*:*64lppc*) LIBPATH_SUFFIX=64 ;; - *le-*:*32lppc*) LIBPATH_SUFFIX=32 ;; - *le-*:*64*) LIBPATH_SUFFIX=64be ;; - *le-*:*32*) LIBPATH_SUFFIX=32be ;; +case `echo "$target" | sed -e 's/-.*//'`:"$EMULATION_NAME" in + *le:*64lppc*) LIBPATH_SUFFIX=64 ;; + *le:*32lppc*) LIBPATH_SUFFIX=32 ;; + *le:*64*) LIBPATH_SUFFIX=64be ;; + *le:*32*) LIBPATH_SUFFIX=32be ;; *:*64lppc*) LIBPATH_SUFFIX=64le ;; *:*32lppc*) LIBPATH_SUFFIX=32le ;; *:*64*) LIBPATH_SUFFIX=64 ;; -- 2.9.3