From patchwork Wed Oct 22 05:25:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vkamensky X-Patchwork-Id: 39241 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D5E52202DB for ; Wed, 22 Oct 2014 05:26:14 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id b57sf1173787eek.4 for ; Tue, 21 Oct 2014 22:26:14 -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=qw4fNmgzW3wFgNjF6giAOWIUj/+aoU4+sCusQdOSplY=; b=jSlG3+UflX5UQKhuxMYH+rKK7dIJrBupCGGnkakgxMWqvZEbfHztH57ONlMXjjsPrd pg0uydfCWml0fiM8R6MRw7sff3iwu18msYF7xZ9Sz1PFeiy8vCKYip91hJv9gv4PkRLU g4ZJl7pnEzn9FLaz+3w3OMUo47IEv5X4CY8jBB4FPaTwJbE2QEYAYP35zPewm5QBIS3L mjJKV/cqURJymH6Lf4VK24vIgjSi+nL5zf3l8Hn2bzg7inej/oZ0euVOnt38IN8wVBXM F9Vrrs2QqJTmiZHaeiSSF8TZlP2XK6uMjRhdXyYoRO1AUmrSQw/obQZS9ySIaLixG8uB iNZA== X-Gm-Message-State: ALoCoQn0rDIRoWUgeV3tYNbCrwzS68dA29wUwtgPJIl3H0Fdi5b+a3SzLSw4dbjyg1cqz7rSq8gU X-Received: by 10.194.118.197 with SMTP id ko5mr5958256wjb.2.1413955573955; Tue, 21 Oct 2014 22:26:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.67 with SMTP id 3ls143396las.63.gmail; Tue, 21 Oct 2014 22:26:13 -0700 (PDT) X-Received: by 10.112.156.138 with SMTP id we10mr8193206lbb.88.1413955573609; Tue, 21 Oct 2014 22:26:13 -0700 (PDT) Received: from mail-la0-x231.google.com (mail-la0-x231.google.com. [2a00:1450:4010:c03::231]) by mx.google.com with ESMTPS id b4si6136603lbd.70.2014.10.21.22.26.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 21 Oct 2014 22:26:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::231 as permitted sender) client-ip=2a00:1450:4010:c03::231; Received: by mail-la0-f49.google.com with SMTP id q1so2210565lam.8 for ; Tue, 21 Oct 2014 22:26:13 -0700 (PDT) X-Received: by 10.112.12.35 with SMTP id v3mr21060194lbb.80.1413955573152; Tue, 21 Oct 2014 22:26:13 -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 c5csp13989lbz; Tue, 21 Oct 2014 22:26:12 -0700 (PDT) X-Received: by 10.68.165.1 with SMTP id yu1mr39684043pbb.76.1413955571594; Tue, 21 Oct 2014 22:26:11 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id wz2si13256652pab.115.2014.10.21.22.26.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Oct 2014 22:26:11 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-return-85115-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 27203 invoked by alias); 22 Oct 2014 05:25:36 -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 27179 invoked by uid 89); 22 Oct 2014 05:25:36 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f45.google.com Received: from mail-pa0-f45.google.com (HELO mail-pa0-f45.google.com) (209.85.220.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 22 Oct 2014 05:25:35 +0000 Received: by mail-pa0-f45.google.com with SMTP id lj1so2950637pab.32 for ; Tue, 21 Oct 2014 22:25:33 -0700 (PDT) X-Received: by 10.68.200.100 with SMTP id jr4mr2145391pbc.69.1413955533459; Tue, 21 Oct 2014 22:25:33 -0700 (PDT) Received: from kamensky-w530.hsd1.ca.comcast.net ([24.6.79.41]) by mx.google.com with ESMTPSA id hp4sm13224157pbb.95.2014.10.21.22.25.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Oct 2014 22:25:32 -0700 (PDT) From: Victor Kamensky To: binutils@sourceware.org, Alan Modra Cc: victor.kamensky@linaro.org, Andrew Pinski Subject: [PATCH V2] ARM: plt_size functions need to read instructions in right byte order Date: Tue, 21 Oct 2014 22:25:13 -0700 Message-Id: <1413955513-4923-2-git-send-email-victor.kamensky@linaro.org> In-Reply-To: <1413955513-4923-1-git-send-email-victor.kamensky@linaro.org> References: <1413955513-4923-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:c03::231 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: 2014-10-21 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. --- bfd/elf32-arm.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 08aa3f9..450cabd 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -15953,6 +15953,34 @@ 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 = bfd_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 = bfd_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 +15990,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 +16015,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])