From patchwork Fri Sep 7 05:42:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146169 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp750327ljw; Thu, 6 Sep 2018 22:42:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZgHtSbvkYCZIfPRKVJMDAP4nDOSfwMYCEw8SWYgZLKUWR+Rg0elFHTYZKmFZfWe8Mot4zG X-Received: by 2002:a17:902:102c:: with SMTP id b41-v6mr6288821pla.257.1536298934955; Thu, 06 Sep 2018 22:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536298934; cv=none; d=google.com; s=arc-20160816; b=xjciXa+srShSlMWpBYVbGe/M4zkfQABwtHlLRJWwA4p3GnfhRCMdjl43IrxxjZ5yVL RYAgkGlKgH9MpWhE2I+EhnDQLQyVGNhapUWYtV0IsCaDjCmHv0LI7rCmF28sqlCkdBI3 EfrxQDHKR6OXajM4V+ihTgpSsp8jaKM4c62LxQyXrVKWVh685OB0CwiAyROmKLFjfRHY yunUrTqaOeYXphw8/49enOTmQaRtXFBlUm3hrK7T+KK/L8GD3WSmbxQgOb77GiJ9ptgz /o/H2elvL/GopfHud4kXyB4NGiokqq34sC+LfciIR/s0NpOolo5TwIXtmEkv3789orm9 O1xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=fbRS7dO8S+EdXesUuwLr+Qd4f/3BfzSEFsKZaVds9Ys=; b=NNvIA+x/uRv/MWVsEvh7vtxPfd1gtOEmhFcCDyAHJ/KU3rshpAPC1lrXy4UhAuGBO9 v1CFiVzsJcxkzPjmLeiWwFInjyyLZSW/EB8pYIbIg70yF/6AuVfVkJMJCce4gJwPPeBh uxckyayx58ZM+v0dbku0WUARqOd2e9Zghnqz5j5VDJF/iROIiBfBWwyJ6q5WiELJu7sh xrA+RYhELC6mn0aC2OKSPM0aSNfew3WEeb1e1UsAnGFa5uS2XzXcktoBdPaNnYcagDZX ws1h7SjQ8JPHwcBX88KA1tB1fD4MYWLqzrgGkWlOEriWHUf5nT/OOw0HbRmPoCAKY7MH YxVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FQHJdUdg; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id m13-v6si6955032pgh.360.2018.09.06.22.42.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 22:42:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FQHJdUdg; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 411E921124AF2; Thu, 6 Sep 2018 22:42:13 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::543; helo=mail-ed1-x543.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 18D9B21124AEE for ; Thu, 6 Sep 2018 22:42:10 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id f4-v6so10651774edq.3 for ; Thu, 06 Sep 2018 22:42:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=q3W8o++5y4P8uJ4PI+3ZWU4e+d2BEUoEBYVvKfDzops=; b=FQHJdUdgnSSTx8Zq2CE272OPxgTKiztbUoFJdjUmMkd5v83vqSTDYtO+/AtTy4m9a3 YfJlz5xPaMqvYF6HH1YmmRv/bthEKQ86Rg2WZtdL410XP9kOQZK+dwHG71SP2XL4T1Cq 03SrnDtTVqD/Af5I65/6efDZYXgQMEo+FJnys= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=q3W8o++5y4P8uJ4PI+3ZWU4e+d2BEUoEBYVvKfDzops=; b=Ma6tXnQ1noWzCfZMrEjhX5cp+k4iXXG5tBol8U7VAv5YFMgyPnF9gYPv1owtQLRx8u Ohku3CKedMNHzwVRfOC5YyXH4x49xjGlvwpBXNEey/7I9yz9uT+u2k9IdpypHbhjBaRX 8zM230QqacszPffV2N9LzRDPmDK1nS1xnkdKAnkGi6aEjm24E+lg6GSA9EOdzZZk4UJX pwjLxy23CUrCTNat8O48U+mpmGlUzWRtULaISRZA+dkCLUyaTDPLzIWYg+pCEXHNvoIX gzs5ySKJSKKaUSvths2DByVHBPMM4aAH/wnigoO5ZiuhXKQSGENpdKO0oMYYIBxLvktN YV9w== X-Gm-Message-State: APzg51BT/c3qTXg+YZuyZ5Bemu3E9zJu5OcQVWTEsd2stJXOLwwpbC9E eqGXNnrHy/rhOphWZG3s7R8UDp8h8ze5xEUu X-Received: by 2002:aa7:c152:: with SMTP id r18-v6mr6928944edp.109.1536298929220; Thu, 06 Sep 2018 22:42:09 -0700 (PDT) Received: from mba13.debuut.local ([2a02:a212:9283:9800:154c:2f23:f4db:9e4b]) by smtp.gmail.com with ESMTPSA id i19-v6sm3460195edg.64.2018.09.06.22.42.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 22:42:08 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 7 Sep 2018 07:42:01 +0200 Message-Id: <20180907054202.24798-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180907054202.24798-1-ard.biesheuvel@linaro.org> References: <20180907054202.24798-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 2/3] MdePkg/BasePeCoffLib: remove PE/COFF header workaround for ELILO on IPF X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao , Jiewen Yao , Star Zeng , Michael D Kinney , Laszlo Ersek , Chao Zhang MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Now that Itanium support has been dropped, we can remove the various occurrences of the ELILO on Itanium PE/COFF header workaround. Link: https://bugzilla.tianocore.org/show_bug.cgi?id=816 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel Reviewed-by: Jiewen Yao Reviewed-by: Laszlo Ersek Reviewed-by: Star Zeng Reviewed-by: Liming Gao --- MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 61 +++----------------- 1 file changed, 9 insertions(+), 52 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c index 32eca0ad2ef4..c57816a80887 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -46,36 +46,6 @@ PeCoffLoaderAdjustOffsetForTeImage ( SectionHeader->PointerToRawData -= TeStrippedOffset; } -/** - Retrieves the magic value from the PE/COFF header. - - @param Hdr The buffer in which to return the PE32, PE32+, or TE header. - - @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32 - @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+ - -**/ -UINT16 -PeCoffLoaderGetPeHeaderMagicValue ( - IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr - ) -{ - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } - // - // Return the magic value from the PC/COFF Optional Header - // - return Hdr.Pe32->OptionalHeader.Magic; -} - - /** Retrieves the PE or TE Header from a PE/COFF or TE image. @@ -101,7 +71,6 @@ PeCoffLoaderGetPeHeader ( EFI_IMAGE_DOS_HEADER DosHdr; UINTN Size; UINTN ReadSize; - UINT16 Magic; UINT32 SectionHeaderOffset; UINT32 Index; UINT32 HeaderWithoutDataDir; @@ -222,9 +191,7 @@ PeCoffLoaderGetPeHeader ( ImageContext->IsTeImage = FALSE; ImageContext->Machine = Hdr.Pe32->FileHeader.Machine; - Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); - - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // 1. Check OptionalHeader.NumberOfRvaAndSizes filed. // @@ -339,7 +306,7 @@ PeCoffLoaderGetPeHeader ( ImageContext->SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment; ImageContext->SizeOfHeaders = Hdr.Pe32->OptionalHeader.SizeOfHeaders; - } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { + } else if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { // // 1. Check FileHeader.NumberOfRvaAndSizes filed. // @@ -605,7 +572,6 @@ PeCoffLoaderGetImageInfo ( EFI_IMAGE_SECTION_HEADER SectionHeader; EFI_IMAGE_DEBUG_DIRECTORY_ENTRY DebugEntry; UINT32 NumberOfRvaAndSizes; - UINT16 Magic; UINT32 TeStrippedOffset; if (ImageContext == NULL) { @@ -622,14 +588,12 @@ PeCoffLoaderGetImageInfo ( return Status; } - Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); - // // Retrieve the base address of the image // if (!(ImageContext->IsTeImage)) { TeStrippedOffset = 0; - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -678,7 +642,7 @@ PeCoffLoaderGetImageInfo ( } if (!(ImageContext->IsTeImage)) { - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -952,7 +916,6 @@ PeCoffLoaderRelocateImage ( CHAR8 *FixupData; PHYSICAL_ADDRESS BaseAddress; UINT32 NumberOfRvaAndSizes; - UINT16 Magic; UINT32 TeStrippedOffset; ASSERT (ImageContext != NULL); @@ -985,9 +948,8 @@ PeCoffLoaderRelocateImage ( if (!(ImageContext->IsTeImage)) { Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffset); TeStrippedOffset = 0; - Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -1230,7 +1192,6 @@ PeCoffLoaderLoadImage ( UINTN Size; UINT32 TempDebugEntryRva; UINT32 NumberOfRvaAndSizes; - UINT16 Magic; EFI_IMAGE_RESOURCE_DIRECTORY *ResourceDirectory; EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY *ResourceDirectoryEntry; EFI_IMAGE_RESOURCE_DIRECTORY_STRING *ResourceDirectoryString; @@ -1404,12 +1365,11 @@ PeCoffLoaderLoadImage ( // // Get image's entry point // - Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); if (!(ImageContext->IsTeImage)) { // // Sizes of AddressOfEntryPoint are different so we need to do this safely // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -1444,7 +1404,7 @@ PeCoffLoaderLoadImage ( // the optional header to verify a desired directory entry is there. // if (!(ImageContext->IsTeImage)) { - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -1565,7 +1525,7 @@ PeCoffLoaderLoadImage ( // ImageContext->HiiResourceData = 0; if (!(ImageContext->IsTeImage)) { - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -1721,7 +1681,6 @@ PeCoffLoaderRelocateImageForRuntime ( CHAR8 *FixupData; UINTN Adjust; RETURN_STATUS Status; - UINT16 Magic; OldBase = (CHAR8 *)((UINTN)ImageBase); NewBase = (CHAR8 *)((UINTN)VirtImageBase); @@ -1750,9 +1709,7 @@ PeCoffLoaderRelocateImageForRuntime ( return ; } - Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); - - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset //