From patchwork Thu Oct 23 01:13:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vkamensky X-Patchwork-Id: 39341 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 47CD120341 for ; Thu, 23 Oct 2014 01:14:00 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id gi9sf14881lab.6 for ; Wed, 22 Oct 2014 18:13:59 -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=MkToFXMcLxkFqjJSb0qovZz6xNOVV+J9YPcLTlBbWio=; b=eyueebLEhA2bxfZ0xxs+neNXEdXYr0zopM0kbrswUX64TqUf0S9Uz5Ozj4vuDvqD5y XBcRT6hmxStSiELursZW6TQ6/wHT0TwUJIFX4rc37mx8e1eoEggH+5Yn2AYXKCrDzNJe D5mPOCEjnVlYC8UpxR405kcXCAoV/d5oMlklyl1oup274l5Ph0g20YUa7wms/u4baC5l cp5tGrBClD/K5M9DVtl22NT8YIzwpEgPaBiITeAi3phxtnqK3WXPBbLseAiM0q6pIA6r tjUTjgLtVpBQ2R8JKiZcFUk5vtFUiEhGnzOeFa62Xu0OX2abU2QW5wwzP9WZbSp+Vtpt B8lw== X-Gm-Message-State: ALoCoQlFs5Y+PjksjVx18FFz2rSUN0FuYWwgvYRkS+vt7WDLNRPnFMyOf6n3EzZbuVxZJjfMYnV5 X-Received: by 10.152.6.4 with SMTP id w4mr158064law.7.1414026839131; Wed, 22 Oct 2014 18:13:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.166 with SMTP id t6ls282652lat.20.gmail; Wed, 22 Oct 2014 18:13:59 -0700 (PDT) X-Received: by 10.112.147.225 with SMTP id tn1mr1446773lbb.37.1414026838989; Wed, 22 Oct 2014 18:13:58 -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 sf5si406980lbb.46.2014.10.22.18.13.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 22 Oct 2014 18:13:58 -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 q1so25075lam.22 for ; Wed, 22 Oct 2014 18:13:58 -0700 (PDT) X-Received: by 10.152.120.73 with SMTP id la9mr1480846lab.23.1414026838487; Wed, 22 Oct 2014 18:13:58 -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 c5csp178527lbz; Wed, 22 Oct 2014 18:13:57 -0700 (PDT) X-Received: by 10.70.130.235 with SMTP id oh11mr1716821pdb.50.1414026836878; Wed, 22 Oct 2014 18:13:56 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id xm9si215481pbc.170.2014.10.22.18.13.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Oct 2014 18:13:56 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-return-85128-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 22801 invoked by alias); 23 Oct 2014 01:13:20 -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 22715 invoked by uid 89); 23 Oct 2014 01:13:20 -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-f43.google.com Received: from mail-pa0-f43.google.com (HELO mail-pa0-f43.google.com) (209.85.220.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 23 Oct 2014 01:13:17 +0000 Received: by mail-pa0-f43.google.com with SMTP id eu11so34937pac.30 for ; Wed, 22 Oct 2014 18:13:16 -0700 (PDT) X-Received: by 10.66.142.230 with SMTP id rz6mr1397888pab.129.1414026796252; Wed, 22 Oct 2014 18:13:16 -0700 (PDT) Received: from kamensky-w530.hsd1.ca.comcast.net ([24.6.79.41]) by mx.google.com with ESMTPSA id kw10sm243208pab.0.2014.10.22.18.13.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Oct 2014 18:13:15 -0700 (PDT) From: Victor Kamensky To: binutils@sourceware.org, Alan Modra Cc: victor.kamensky@linaro.org, Andrew Pinski Subject: [PATCH V3] ARM: plt_size functions need to read instructions in right byte order Date: Wed, 22 Oct 2014 18:13:04 -0700 Message-Id: <1414026784-26135-2-git-send-email-victor.kamensky@linaro.org> In-Reply-To: <1414026784-26135-1-git-send-email-victor.kamensky@linaro.org> References: <1414026784-26135-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..56b66d3 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) != 0) + /* 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) != 0) + /* 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])