From patchwork Tue Feb 3 21:30:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 44313 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8177921513 for ; Tue, 3 Feb 2015 21:30:38 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id r20sf27338678wiv.2 for ; Tue, 03 Feb 2015 13:30:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :precedence:reply-to:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=1Dcz+3nVHhWs+v1FQ3EwOEkNlIURSL2jUcl3TY2TKO8=; b=HUrX74q7zfNuFe9S0xUX0OVfI14F24piAr5Jxtpz0bm6jAI+KIc9efZYTDwI7plsF0 +7jJRV/sK7PT6KPaWE//xf20+Lp9y3b2XdU3LUh3hw9h/wRDCCEl33DMa7zebx58Ai5e wgH/lDuVpjzVyNq18gwtjq4tueMTHGMb4cHNyd190qcJRkBvU6sPKJPX44va1Yz77Ssg jnJgWW0pDcnrokwviEIxW+g5Uazuzzq3ouOCdR/EVD+fKvpdjPOhDaIw6h+gn1oSla2G Yu6l7sL0bzyPlt2RdFDpnKPimeBo0yTt7DREKmpauez27Bz3+VeTJrr+f2RReUwRibUO VhLA== X-Gm-Message-State: ALoCoQkl8nQUNXnbsHzWXfizefG0rRiFWvDPG6ZjCLkPlXnVYxsRyDDNyG+cTxnxTwP5BNgycLzv X-Received: by 10.152.87.15 with SMTP id t15mr3402557laz.9.1422999037364; Tue, 03 Feb 2015 13:30:37 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.199 with SMTP id u7ls793307lau.63.gmail; Tue, 03 Feb 2015 13:30:37 -0800 (PST) X-Received: by 10.112.171.168 with SMTP id av8mr27263746lbc.88.1422999037215; Tue, 03 Feb 2015 13:30:37 -0800 (PST) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id yo1si20339626lbb.92.2015.02.03.13.30.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 03 Feb 2015 13:30:37 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by mail-lb0-f170.google.com with SMTP id w7so41055483lbi.1 for ; Tue, 03 Feb 2015 13:30:37 -0800 (PST) X-Received: by 10.152.20.169 with SMTP id o9mr27479649lae.50.1422999037084; Tue, 03 Feb 2015 13:30:37 -0800 (PST) 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.35.133 with SMTP id h5csp96927lbj; Tue, 3 Feb 2015 13:30:36 -0800 (PST) X-Received: by 10.140.23.40 with SMTP id 37mr23765420qgo.93.1422999035330; Tue, 03 Feb 2015 13:30:35 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n4si30383233qat.4.2015.02.03.13.30.34 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 03 Feb 2015 13:30:35 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:33337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIl3K-00044a-DJ for patch@linaro.org; Tue, 03 Feb 2015 16:30:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIl3G-00044Q-B2 for grub-devel@gnu.org; Tue, 03 Feb 2015 16:30:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YIl3D-0004eY-74 for grub-devel@gnu.org; Tue, 03 Feb 2015 16:30:30 -0500 Received: from mail-wg0-f50.google.com ([74.125.82.50]:37176) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIl3D-0004eL-1G for grub-devel@gnu.org; Tue, 03 Feb 2015 16:30:27 -0500 Received: by mail-wg0-f50.google.com with SMTP id b13so46846208wgh.9 for ; Tue, 03 Feb 2015 13:30:25 -0800 (PST) X-Received: by 10.194.175.39 with SMTP id bx7mr59596852wjc.22.1422999025792; Tue, 03 Feb 2015 13:30:25 -0800 (PST) Received: from mohikan.mushroom.smurfnet.nu (cpc4-cmbg17-2-0-cust71.5-4.cable.virginm.net. [86.14.224.72]) by mx.google.com with ESMTPSA id z13sm26233863wiv.8.2015.02.03.13.30.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Feb 2015 13:30:24 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH] arm: implement additional relocations generated by gcc 4.9 at -O3 Date: Tue, 3 Feb 2015 21:30:57 +0000 Message-Id: <1422999057-24715-1-git-send-email-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.1.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.50 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: grub-devel-bounces+patch=linaro.org@gnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: leif.lindholm@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 GCC 4.9 also generates R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_ABS, as an alternative to ABS32. Signed-off-by: Leif Lindholm --- grub-core/kern/arm/dl.c | 15 +++++++++++++++ grub-core/kern/arm/dl_helper.c | 39 +++++++++++++++++++++++++++++++++++++++ include/grub/arm/reloc.h | 5 +++++ 3 files changed, 59 insertions(+) diff --git a/grub-core/kern/arm/dl.c b/grub-core/kern/arm/dl.c index 57cac2e..5cbd65e 100644 --- a/grub-core/kern/arm/dl.c +++ b/grub-core/kern/arm/dl.c @@ -205,6 +205,21 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, */ case R_ARM_V4BX: break; + case R_ARM_THM_MOVW_ABS_NC: + case R_ARM_THM_MOVT_ABS: + { + grub_uint32_t offset; + offset = grub_arm_thm_movw_movt_get_value((grub_uint16_t *) target); + offset += sym_addr; + + if (ELF_R_TYPE (rel->r_info) == R_ARM_THM_MOVT_ABS) + offset >>= 16; + else + offset &= 0xffff; + + grub_arm_thm_movw_movt_set_value((grub_uint16_t *) target, offset); + } + break; case R_ARM_THM_JUMP19: { /* Thumb instructions can be 16-bit aligned */ diff --git a/grub-core/kern/arm/dl_helper.c b/grub-core/kern/arm/dl_helper.c index 5721939..8a72632 100644 --- a/grub-core/kern/arm/dl_helper.c +++ b/grub-core/kern/arm/dl_helper.c @@ -25,6 +25,20 @@ #include #include +static inline grub_uint32_t +thumb_get_instruction_word(grub_uint16_t *target) +{ + /* Extract instruction word in alignment-safe manner */ + return grub_le_to_cpu16 ((*target)) << 16 | grub_le_to_cpu16 (*(target + 1)); +} + +static inline void +thumb_set_instruction_word(grub_uint16_t *target, grub_uint32_t insword) +{ + *target = grub_cpu_to_le16 (insword >> 16); + *(target + 1) = grub_cpu_to_le16 (insword & 0xffff); +} + /* * R_ARM_ABS32 * @@ -214,3 +228,28 @@ grub_arm_jump24_set_offset (grub_uint32_t *target, *target = grub_cpu_to_le32 (insword); } + +grub_uint16_t +grub_arm_thm_movw_movt_get_value (grub_uint16_t *target) +{ + grub_uint32_t insword; + + insword = thumb_get_instruction_word (target); + + return ((insword & 0xf0000) >> 4) | ((insword & 0x04000000) >> 15) | \ + ((insword & 0x7000) >> 4) | (insword & 0xff); +} + +void +grub_arm_thm_movw_movt_set_value (grub_uint16_t *target, grub_uint16_t value) +{ + grub_uint32_t insword; + + insword = thumb_get_instruction_word (target); + insword &= 0xfbf08f00; + + insword |= ((value & 0xf000) << 4) | ((value & 0x0800) << 15) | \ + ((value & 0x0700) << 4) | (value & 0xff); + + thumb_set_instruction_word (target, insword); +} diff --git a/include/grub/arm/reloc.h b/include/grub/arm/reloc.h index b938037..ae92e21 100644 --- a/include/grub/arm/reloc.h +++ b/include/grub/arm/reloc.h @@ -43,4 +43,9 @@ void grub_arm_jump24_set_offset (grub_uint32_t *target, grub_int32_t offset); +grub_uint16_t +grub_arm_thm_movw_movt_get_value (grub_uint16_t *target); +void +grub_arm_thm_movw_movt_set_value (grub_uint16_t *target, grub_uint16_t value); + #endif