]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: DxeCore: fully initialize image context before passing it on
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 29 Feb 2016 16:08:45 +0000 (17:08 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 1 Mar 2016 09:15:59 +0000 (10:15 +0100)
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
<some intermediate output>
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 <ard.biesheuvel@linaro.org>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c

index 0a34711b22a4ab411aa4d08fa5e3f5c04ff87fc0..20ff02f663b288da232a85bcceae8012219d14fd 100644 (file)
@@ -247,6 +247,7 @@ DxeMain (
   EFI_HOB_GUID_TYPE             *GuidHob;\r
   EFI_VECTOR_HANDOFF_INFO       *VectorInfoList;\r
   EFI_VECTOR_HANDOFF_INFO       *VectorInfo;\r
+  VOID                          *EntryPoint;\r
 \r
   //\r
   // Setup the default exception handlers\r
@@ -293,8 +294,13 @@ DxeMain (
   // Report DXE Core image information to the PE/COFF Extra Action Library\r
   //\r
   ZeroMem (&ImageContext, sizeof (ImageContext));\r
-  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;\r
-  ImageContext.PdbPointer   = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);\r
+  ImageContext.ImageAddress   = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;\r
+  ImageContext.PdbPointer     = PeCoffLoaderGetPdbPointer ((VOID*)(UINTN)ImageContext.ImageAddress);\r
+  ImageContext.SizeOfHeaders  = PeCoffGetSizeOfHeaders ((VOID*)(UINTN)ImageContext.ImageAddress);\r
+  Status = PeCoffLoaderGetEntryPoint ((VOID*)(UINTN)ImageContext.ImageAddress, &EntryPoint);\r
+  if (Status == EFI_SUCCESS) {\r
+    ImageContext.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)EntryPoint;\r
+  }\r
   PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r
 \r
   //\r