From patchwork Mon Feb 29 16:16:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 63227 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1339200lbc; Mon, 29 Feb 2016 08:16:24 -0800 (PST) X-Received: by 10.98.80.150 with SMTP id g22mr23147144pfj.132.1456762584607; Mon, 29 Feb 2016 08:16:24 -0800 (PST) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id bx6si43878830pad.6.2016.02.29.08.16.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Feb 2016 08:16:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 59D0B1A1E1E; Mon, 29 Feb 2016 08:16:31 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com [IPv6:2a00:1450:400c:c09::22d]) (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 BD1801A1E1C for ; Mon, 29 Feb 2016 08:16:30 -0800 (PST) Received: by mail-wm0-x22d.google.com with SMTP id l68so44040435wml.0 for ; Mon, 29 Feb 2016 08:16:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=kCKWIRnUDc5Aw3bSZx7ozhGGfMg8BV4MiyIU/d+j+ro=; b=W75PWzTVx7e3nhEbRgf9s6TF62WrZY4FGrNtQXNVpj7LGoQR0oVpGvxO4YQi9NOzRo uPrE7wjByuDJtM5YnAB/8n18iA02TGigglHOmi8Har3iORrfXfk5mxoqQKBw2Ne4l0u8 mEfwjJpno/icmeoyWRjPUTwwhpIPxvLW01c0c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kCKWIRnUDc5Aw3bSZx7ozhGGfMg8BV4MiyIU/d+j+ro=; b=BlQp6EMA+u5LMJMmqtwvflUwsnxrwIiiicqMDB771BK/To5Qgo4cKjGVaeaBm2Av80 ltt1SXQEMA6IoBaBWAoD4VxORfDfdWVtU+7fa7BuRiOE6ZWwN/6EThobDozvu68vXcZZ x8Q5gYZxUeXqnBVpUZN1+kW3pd7ADqCp3ih3F33DfXK6Kxf+X4vC/5bhvydCrtZ1SVVK roQ6d9yDqU6rH+XRBFAzPp7PCd49PA4nVUDNc/svlh7TjDSp9t+G/PgBhw5jt9/Kqap0 fsxiakLtoZGLoAPbfN3J0wyBpcQxBpE2EtXAXqlIExbJgW+/XgLW5tkA1pdCYeKnlGK6 8Wcw== X-Gm-Message-State: AD7BkJKyNui65yxPyXbt2GBdNkKRHGvZ7XNCAub0KTpMioW4IZ0xxWQcDGgyrajTXV9EQGLc X-Received: by 10.28.144.195 with SMTP id s186mr1918800wmd.9.1456762582081; Mon, 29 Feb 2016 08:16:22 -0800 (PST) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id h132sm17014725wmf.9.2016.02.29.08.16.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Feb 2016 08:16:21 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, feng.tian@intel.com, star.zeng@intel.com Date: Mon, 29 Feb 2016 17:16:18 +0100 Message-Id: <1456762578-18459-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 Cc: Ard Biesheuvel Subject: [edk2] [PATCH] MdeModulePkg: DxeCore: fully initialize image context before passing it on X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" When the DXE core is loaded, it invokes the PeCoffExtraActionLib library function 'PeCoffLoaderRelocateImageExtraAction' explicitly, which may be in addition to the same function having been called by the DxeIpl PE/COFF loader instance. The ImageContext that DXE core presents to this function is only partially initialized, which may result in the following output on AArch64 systems: add-symbol-file ..MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll 0x5F226240 add-symbol-file ..MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll 0x5F226000 This is caused by incorrect data in the ImageContext structure, which means the start of the .text section is calculated incorrectly. In general, it is the duty of the caller to present a valid ImageContext structure, so let's add the missing values before invoking PeCoffLoaderRelocateImageExtraAction(). Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 2.5.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c index 0a34711b22a4..20ff02f663b2 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -247,6 +247,7 @@ DxeMain ( EFI_HOB_GUID_TYPE *GuidHob; EFI_VECTOR_HANDOFF_INFO *VectorInfoList; EFI_VECTOR_HANDOFF_INFO *VectorInfo; + VOID *EntryPoint; // // Setup the default exception handlers @@ -293,8 +294,13 @@ DxeMain ( // Report DXE Core image information to the PE/COFF Extra Action Library // ZeroMem (&ImageContext, sizeof (ImageContext)); - ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase; - ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress); + ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase; + ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*)(UINTN)ImageContext.ImageAddress); + ImageContext.SizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID*)(UINTN)ImageContext.ImageAddress); + Status = PeCoffLoaderGetEntryPoint ((VOID*)(UINTN)ImageContext.ImageAddress, &EntryPoint); + if (Status == EFI_SUCCESS) { + ImageContext.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)EntryPoint; + } PeCoffLoaderRelocateImageExtraAction (&ImageContext); //