From patchwork Tue Oct 21 05:16:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vkamensky X-Patchwork-Id: 39092 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5DC84203C5 for ; Tue, 21 Oct 2014 05:17:11 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf263651lab.7 for ; Mon, 20 Oct 2014 22:17:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:mailing-list :precedence:list-id:list-unsubscribe:list-subscribe:list-archive :list-post:list-help:sender:delivered-to:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results; bh=XJhJzEPIjmRJaiUb2/zaS8j4/LY1zr+nJibeneDEYzM=; b=QHFIYlemh7H9smNHWzNiz+tBOfxV+Xhch7B34W0ZcMHpsxUfOiZcjU8iKEhbkOXx7q 75JW/eiY4T/tV33sHwF+BaBjilqvBBd89LyWUQ3K8240gNJP/7nnqqn/xnUrc5OwhK1T vdq92qiCuJO1YwKYjWOSvuR2vKl87dNqx4b2p0JH+TRyBFAAW75IJQ4MrMkhoP2nh1AN xGnL5mLz9CD+7HBkyuay+N/YILlqXOxrGHuWcu4JX2GgPoCIHtq4VOwFU98uKL09lgKe SoWHoCNKhIqmSnBXGPwZRAP7sw8F/z7oQwhITckaGV6iDYMkUKCfoN7bKC4qb8tjD5BI mheQ== X-Gm-Message-State: ALoCoQm2eBWnVSOIFykBfbELdLDBR9neF3FBfzTPyOQQo8uFWotEtSPb7JgQmHEzpgf7vT3zWXXm X-Received: by 10.180.90.115 with SMTP id bv19mr3135812wib.1.1413868630159; Mon, 20 Oct 2014 22:17:10 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.44 with SMTP id t12ls14173lal.104.gmail; Mon, 20 Oct 2014 22:17:09 -0700 (PDT) X-Received: by 10.153.11.133 with SMTP id ei5mr31990995lad.75.1413868629596; Mon, 20 Oct 2014 22:17:09 -0700 (PDT) Received: from mail-lb0-x230.google.com (mail-lb0-x230.google.com. [2a00:1450:4010:c04::230]) by mx.google.com with ESMTPS id bf9si17052538lab.114.2014.10.20.22.17.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 20 Oct 2014 22:17:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::230 as permitted sender) client-ip=2a00:1450:4010:c04::230; Received: by mail-lb0-f176.google.com with SMTP id p9so335896lbv.7 for ; Mon, 20 Oct 2014 22:17:09 -0700 (PDT) X-Received: by 10.112.97.135 with SMTP id ea7mr32120120lbb.46.1413868629501; Mon, 20 Oct 2014 22:17:09 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp434716lbz; Mon, 20 Oct 2014 22:17:08 -0700 (PDT) X-Received: by 10.70.140.70 with SMTP id re6mr7263811pdb.149.1413868628005; Mon, 20 Oct 2014 22:17:08 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id br4si9750623pbc.155.2014.10.20.22.17.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Oct 2014 22:17:07 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-return-85095-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 29624 invoked by alias); 21 Oct 2014 05:16:35 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list List-Id: List-Unsubscribe: , List-Subscribe: List-Archive: List-Post: , List-Help: , Sender: binutils-owner@sourceware.org Delivered-To: mailing list binutils@sourceware.org Received: (qmail 29607 invoked by uid 89); 21 Oct 2014 05:16:34 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f52.google.com Received: from mail-pa0-f52.google.com (HELO mail-pa0-f52.google.com) (209.85.220.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 21 Oct 2014 05:16:32 +0000 Received: by mail-pa0-f52.google.com with SMTP id fb1so582510pad.25 for ; Mon, 20 Oct 2014 22:16:31 -0700 (PDT) X-Received: by 10.70.23.163 with SMTP id n3mr33134265pdf.0.1413868590991; Mon, 20 Oct 2014 22:16:30 -0700 (PDT) Received: from kamensky-w530.cisco.com (128-107-239-233.cisco.com. [128.107.239.233]) by mx.google.com with ESMTPSA id ib8sm10769179pad.43.2014.10.20.22.16.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Oct 2014 22:16:30 -0700 (PDT) From: Victor Kamensky To: binutils@sourceware.org Cc: victor.kamensky@linaro.org, pinskia@gmail.com Subject: [PATCH] ARM: plt_size functions need to read instructions in right byte order Date: Mon, 20 Oct 2014 22:16:18 -0700 Message-Id: <1413868578-6761-2-git-send-email-victor.kamensky@linaro.org> In-Reply-To: <1413868578-6761-1-git-send-email-victor.kamensky@linaro.org> References: <1413868578-6761-1-git-send-email-victor.kamensky@linaro.org> X-Original-Sender: victor.kamensky@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::230 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org X-Google-Group-Id: 836684582541 elf32_arm_plt0_size and elf32_arm_plt_size read instructions to determine what is size of PLT entry. However it does not read instruction correctly in case of ARM big endian V7 case. In this case instructions are still kept in little endian order (BE8). Because of that in armv7b case gdb.base/dprintf-pending.exp test is failing - It cannot find 'pendfunc@plt' symbol. And that symbol is not created because elf32_arm_get_synthetic_symtab function does not create 'pendfunc@plt' symbol for symbols from PLT after elf32_arm_plt0_size returns -1. Fix is to introduce code reading functions read_code32, read_code16 which would read code content in little endian mode when it is armv7b executabe (i.e e_flags has EF_ARM_BE8) set. elf32_arm_plt0_size and elf32_arm_plt_size to use these functions in place where H_GET_32, H_GET_16 were used before. --- bfd/ChangeLog | 9 +++++++++ bfd/elf32-arm.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index e4445dc..8b183ac 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,12 @@ +2014-10-13 Victor Kamensky + + * elf32-arm.c (read_code32): New function to read 32 bit + arm instruction. + (read_code16): New function to read 16 bit thumb instrution. + (elf32_arm_plt0_size, elf32_arm_plt_size) change code to use + read_code32, read_code16 to read instruction to deal with + BE8 arm case. + 2014-09-29 H.J. Lu PR ld/17440 diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 08aa3f9..89e4f35 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -15953,6 +15953,46 @@ const struct elf_size_info elf32_arm_size_info = bfd_elf32_swap_reloca_out }; +static bfd_vma +read_code32 (const bfd *abfd, const bfd_byte *addr) +{ + bfd_vma retval; + + if ((elf_elfheader(abfd)->e_flags) & EF_ARM_BE8) + { + /* + * V7 BE8 code is always little endian + */ + retval = bfd_getl32(addr); + } + else + { + retval = H_GET_32(abfd, addr); + } + return retval; +} + + +static bfd_vma +read_code16 (const bfd *abfd, const bfd_byte *addr) +{ + bfd_vma retval; + + if ((elf_elfheader(abfd)->e_flags) & EF_ARM_BE8) + { + /* + * V7 BE8 code is always little endian + */ + retval = bfd_getl16(addr); + } + else + { + retval = H_GET_16(abfd, addr); + } + return retval; +} + + /* Return size of plt0 entry starting at ADDR or (bfd_vma) -1 if size can not be determined. */ @@ -15962,7 +16002,7 @@ elf32_arm_plt0_size (const bfd *abfd, const bfd_byte *addr) bfd_vma first_word; bfd_vma plt0_size; - first_word = H_GET_32 (abfd, addr); + first_word = read_code32 (abfd, addr); if (first_word == elf32_arm_plt0_entry[0]) plt0_size = 4 * ARRAY_SIZE (elf32_arm_plt0_entry); @@ -15987,17 +16027,17 @@ elf32_arm_plt_size (const bfd *abfd, const bfd_byte *start, bfd_vma offset) const bfd_byte *addr = start + offset; /* PLT entry size if fixed on Thumb-only platforms. */ - if (H_GET_32(abfd, start) == elf32_thumb2_plt0_entry[0]) + if (read_code32(abfd, start) == elf32_thumb2_plt0_entry[0]) return 4 * ARRAY_SIZE (elf32_thumb2_plt_entry); /* Respect Thumb stub if necessary. */ - if (H_GET_16(abfd, addr) == elf32_arm_plt_thumb_stub[0]) + if (read_code16(abfd, addr) == elf32_arm_plt_thumb_stub[0]) { plt_size += 2 * ARRAY_SIZE(elf32_arm_plt_thumb_stub); } /* Strip immediate from first add. */ - first_insn = H_GET_32(abfd, addr + plt_size) & 0xffffff00; + first_insn = read_code32(abfd, addr + plt_size) & 0xffffff00; #ifdef FOUR_WORD_PLT if (first_insn == elf32_arm_plt_entry[0])