From patchwork Fri Jul 3 09:40:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 50615 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9792D214B3 for ; Fri, 3 Jul 2015 09:40:51 +0000 (UTC) Received: by wgfk9 with SMTP id k9sf28274237wgf.1 for ; Fri, 03 Jul 2015 02:40:50 -0700 (PDT) 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:date:message-id:in-reply-to :references:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=jw+A9ZsILItis7RY1SR141k0eJuUaHx+CG7sDn4g89o=; b=Jgzp7qFeogZtOgjAGJcLbhpunka7kBoivSI6H2CBVyZzPw+PQvpiLEq1JL5hgJe2Cb SZPTN3qeeyhCACK2K/+P+YrEAHMAqBINArahusrWcLru7tmpAjnWTyjqrTs+KtlBVN4v xv1Z9sSVRdoE4kQejhH3kYyYz5QcUMmGhwJpGOElwI7VacmkIm79Gzo9hzvNvKozFcIi NAjL4HkPPJiOSIUXu1q+/Uif3PSGVqFZVyjKisDRgIXWebEPt1whBa6hj3OGOZQ81Q/F bBxvu2rRH6jtyhNAZIjRHSq5b3K3hre/PDx0VdsSnE5gPaXtk8cuv1zz7auYwkI8oOEE mX0A== X-Gm-Message-State: ALoCoQmUm2lJz0yd8x4AqwJ3HFMXJx8nXW9KTn4oDG6oqsIBG9mVkCkZilQNSGUK+a+gZQ5FmKdw X-Received: by 10.152.8.9 with SMTP id n9mr19365445laa.1.1435916450903; Fri, 03 Jul 2015 02:40:50 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.202 with SMTP id d10ls481811laa.69.gmail; Fri, 03 Jul 2015 02:40:50 -0700 (PDT) X-Received: by 10.152.21.65 with SMTP id t1mr34232484lae.49.1435916450750; Fri, 03 Jul 2015 02:40:50 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id pd4si6778911lbc.40.2015.07.03.02.40.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jul 2015 02:40:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by lagc2 with SMTP id c2so78737333lag.3 for ; Fri, 03 Jul 2015 02:40:50 -0700 (PDT) X-Received: by 10.112.42.50 with SMTP id k18mr32103467lbl.76.1435916450616; Fri, 03 Jul 2015 02:40:50 -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.108.230 with SMTP id hn6csp1046279lbb; Fri, 3 Jul 2015 02:40:49 -0700 (PDT) X-Received: by 10.50.18.42 with SMTP id t10mr11950439igd.0.1435916448538; Fri, 03 Jul 2015 02:40:48 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id n10si4865524igv.28.2015.07.03.02.40.47 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 03 Jul 2015 02:40:48 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZAxSZ-0000I5-6e; Fri, 03 Jul 2015 09:40:39 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZAxSX-0000Hi-O4 for edk2-devel@lists.sourceforge.net; Fri, 03 Jul 2015 09:40:37 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.212.178 as permitted sender) client-ip=209.85.212.178; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wi0-f178.google.com; Received: from mail-wi0-f178.google.com ([209.85.212.178]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1ZAxSW-0004Aa-Vg for edk2-devel@lists.sourceforge.net; Fri, 03 Jul 2015 09:40:37 +0000 Received: by wiwl6 with SMTP id l6so221428003wiw.0 for ; Fri, 03 Jul 2015 02:40:31 -0700 (PDT) X-Received: by 10.194.48.108 with SMTP id k12mr64513348wjn.151.1435916430992; Fri, 03 Jul 2015 02:40:30 -0700 (PDT) Received: from localhost.localdomain ([185.13.106.72]) by mx.google.com with ESMTPSA id fa8sm12986803wib.14.2015.07.03.02.40.28 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Jul 2015 02:40:30 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, michael.d.kinney@intel.com, Jiewen.Yao@intel.com, liming.gao@intel.com, jordan.l.justen@intel.com Date: Fri, 3 Jul 2015 11:40:04 +0200 Message-Id: <1435916407-29683-4-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1435916407-29683-1-git-send-email-ard.biesheuvel@linaro.org> References: <1435916407-29683-1-git-send-email-ard.biesheuvel@linaro.org> X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1ZAxSW-0004Aa-Vg Subject: [edk2] [PATCH 3/6] MdePkg/BasePeCoffLib: account for carry in high/low relocation pairs X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@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.215.41 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 Relocations of types EFI_IMAGE_REL_BASED_HIGH and EFI_IMAGE_REL_BASED_LOW occur in pairs, where each of the pair relocates a 16-bit word half of a 32-bit dword. Since the target of the relocation arithmetic is a 32-bit quantity, we should handle a carry that may occur in the low word relocation, by taking the carry into account when relocating the high word. Since we know the relocation pair refers to a single value, we can simply perform the addition for the entire value when handling the high relocation, and truncate the result to 16-bits. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c index 33cad23a014e..28c84062d125 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -1103,7 +1103,8 @@ PeCoffLoaderRelocateImage ( case EFI_IMAGE_REL_BASED_HIGH: Fixup16 = (UINT16 *) Fixup; - *Fixup16 = (UINT16) (*Fixup16 + ((UINT16) ((UINT32) Adjust >> 16))); + Fixup32 = (UINT32 *) (Fixup16 - 1); + *Fixup16 = (UINT16) ((*Fixup32 + (UINT32) Adjust) >> 16); if (FixupData != NULL) { *(UINT16 *) FixupData = *Fixup16; FixupData = FixupData + sizeof (UINT16); @@ -1828,8 +1829,9 @@ PeCoffLoaderRelocateImageForRuntime ( case EFI_IMAGE_REL_BASED_HIGH: Fixup16 = (UINT16 *) Fixup; + Fixup32 = (UINT32 *) (Fixup16 - 1); if (*(UINT16 *) FixupData == *Fixup16) { - *Fixup16 = (UINT16) (*Fixup16 + ((UINT16) ((UINT32) Adjust >> 16))); + *Fixup16 = (UINT16) ((*Fixup32 + (UINT32) Adjust) >> 16); } FixupData = FixupData + sizeof (UINT16);