[LibraryClasses.common.UEFI_DRIVER]\r
UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
\r
-[BuildOptions.common.EDKII.SEC, BuildOptions.common.EDKII.BASE]\r
+[BuildOptions]\r
#\r
- # CLANG38 with LTO support enabled uses the GNU GOLD linker, which insists\r
- # on emitting GOT based symbol references when running in shared mode, unless\r
- # we override visibility to 'hidden' in all modules that make up the PrePi\r
- # build.\r
+ # We need to avoid jump tables in SEC modules, so that the PE/COFF\r
+ # self-relocation code itself is guaranteed to be position independent.\r
#\r
- GCC:*_CLANG38_*_CC_FLAGS = -include $(WORKSPACE)/ArmVirtPkg/Include/Platform/Hidden.h\r
+ GCC:*_*_*_CC_FLAGS = -fno-jump-tables\r
\r
################################################################################\r
#\r
[LibraryClasses.common.UEFI_DRIVER]\r
UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
\r
-[BuildOptions.common.EDKII.SEC, BuildOptions.common.EDKII.BASE]\r
+[BuildOptions]\r
#\r
- # CLANG38 with LTO support enabled uses the GNU GOLD linker, which insists\r
- # on emitting GOT based symbol references when running in shared mode, unless\r
- # we override visibility to 'hidden' in all modules that make up the PrePi\r
- # build.\r
+ # We need to avoid jump tables in SEC modules, so that the PE/COFF\r
+ # self-relocation code itself is guaranteed to be position independent.\r
#\r
- GCC:*_CLANG38_*_CC_FLAGS = -include $(WORKSPACE)/ArmVirtPkg/Include/Platform/Hidden.h\r
+ GCC:*_*_*_CC_FLAGS = -fno-jump-tables\r
\r
################################################################################\r
#\r
#include <AsmMacroIoLibV8.h>\r
\r
ASM_FUNC(_ModuleEntryPoint)\r
- //\r
- // We are built as a ET_DYN PIE executable, so we need to process all\r
- // relative relocations regardless of whether or not we are executing from\r
- // the same offset we were linked at. This is only possible if we are\r
- // running from RAM.\r
- //\r
- adr x8, __reloc_base\r
- adr x9, __reloc_start\r
- adr x10, __reloc_end\r
-\r
-.Lreloc_loop:\r
- cmp x9, x10\r
- bhs .Lreloc_done\r
-\r
- //\r
- // AArch64 uses the ELF64 RELA format, which means each entry in the\r
- // relocation table consists of\r
- //\r
- // UINT64 offset : the relative offset of the value that needs to\r
- // be relocated\r
- // UINT64 info : relocation type and symbol index (the latter is\r
- // not used for R_AARCH64_RELATIVE relocations)\r
- // UINT64 addend : value to be added to the value being relocated\r
- //\r
- ldp x11, x12, [x9], #24 // read offset into x11 and info into x12\r
- cmp x12, #0x403 // check info == R_AARCH64_RELATIVE?\r
- bne .Lreloc_loop // not a relative relocation? then skip\r
-\r
- ldr x12, [x9, #-8] // read addend into x12\r
- add x12, x12, x8 // add reloc base to addend to get relocated value\r
- str x12, [x11, x8] // write relocated value at offset\r
- b .Lreloc_loop\r
-.Lreloc_done:\r
-\r
bl ASM_PFX(DiscoverDramFromDt)\r
\r
// Get ID of this CPU in Multicore system\r
str x1, [x8]\r
str x7, [x9]\r
\r
+ //\r
+ // The runtime address may be different from the link time address so fix\r
+ // up the PE/COFF relocations. Since we are calling a C function, use the\r
+ // window at the beginning of the FD image as a temp stack.\r
+ //\r
+ mov x0, x7\r
+ adr x1, PeCoffLoaderImageReadFromMemory\r
+ mov sp, x7\r
+ bl RelocatePeCoffImage\r
+\r
//\r
// Discover the memory size and offset from the DTB, and record in the\r
// respective PCDs. This will also return false if a corrupt DTB is\r
- // encountered. Since we are calling a C function, use the window at the\r
- // beginning of the FD image as a temp stack.\r
+ // encountered.\r
//\r
+ mov x0, x28\r
adr x1, PcdGet64 (PcdSystemMemoryBase)\r
adr x2, PcdGet64 (PcdSystemMemorySize)\r
- mov sp, x7\r
bl FindMemnode\r
cbz x0, .Lout\r
\r
#include <AsmMacroIoLib.h>\r
\r
ASM_FUNC(_ModuleEntryPoint)\r
- //\r
- // We are built as a ET_DYN PIE executable, so we need to process all\r
- // relative relocations if we are executing from a different offset than we\r
- // were linked at. This is only possible if we are running from RAM.\r
- //\r
- ADRL (r4, __reloc_base)\r
- ADRL (r5, __reloc_start)\r
- ADRL (r6, __reloc_end)\r
-\r
-.Lreloc_loop:\r
- cmp r5, r6\r
- bhs .Lreloc_done\r
-\r
- //\r
- // AArch32 uses the ELF32 REL format, which means each entry in the\r
- // relocation table consists of\r
- //\r
- // UINT32 offset : the relative offset of the value that needs to\r
- // be relocated\r
- // UINT32 info : relocation type and symbol index (the latter is\r
- // not used for R_ARM_RELATIVE relocations)\r
- //\r
- ldrd r8, r9, [r5], #8 // read offset into r8 and info into r9\r
- cmp r9, #23 // check info == R_ARM_RELATIVE?\r
- bne .Lreloc_loop // not a relative relocation? then skip\r
-\r
- ldr r9, [r8, r4] // read addend into r9\r
- add r9, r9, r1 // add image base to addend to get relocated value\r
- str r9, [r8, r4] // write relocated value at offset\r
- b .Lreloc_loop\r
-.Lreloc_done:\r
-\r
// Do early platform specific actions\r
bl ASM_PFX(ArmPlatformPeiBootAction)\r
\r
str r1, [r8]\r
str r5, [r7]\r
\r
+ //\r
+ // The runtime address may be different from the link time address so fix\r
+ // up the PE/COFF relocations. Since we are calling a C function, use the\r
+ // window at the beginning of the FD image as a temp stack.\r
+ //\r
+ mov r0, r5\r
+ ADRL (r1, PeCoffLoaderImageReadFromMemory)\r
+ mov sp, r5\r
+ bl RelocatePeCoffImage\r
+\r
//\r
// Discover the memory size and offset from the DTB, and record in the\r
// respective PCDs. This will also return false if a corrupt DTB is\r
- // encountered. Since we are calling a C function, use the window at the\r
- // beginning of the FD image as a temp stack.\r
+ // encountered.\r
//\r
+ mov r0, r10\r
ADRL (r1, PcdGet64 (PcdSystemMemoryBase))\r
ADRL (r2, PcdGet64 (PcdSystemMemorySize))\r
- mov sp, r5\r
bl FindMemnode\r
teq r0, #0\r
beq .Lout\r
SerialPortLib\r
ExtractGuidedSectionLib\r
LzmaDecompressLib\r
+ PeCoffLib\r
PrePiLib\r
MemoryAllocationLib\r
HobLib\r
gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress\r
gArmTokenSpaceGuid.PcdFdBaseAddress\r
gArmTokenSpaceGuid.PcdFvBaseAddress\r
-\r
-[BuildOptions]\r
- GCC:*_*_*_DLINK_FLAGS = -Wl,-Bsymbolic,-pie,-T,$(MODULE_DIR)/Scripts/PrePi-PIE.lds\r
#include <PiPei.h>\r
#include <Pi/PiBootMode.h>\r
\r
+#include <Library/PeCoffLib.h>\r
#include <Library/PrePiLib.h>\r
#include <Library/PrintLib.h>\r
#include <Library/PrePiHobListPointerLib.h>\r
// DXE Core should always load and never return\r
ASSERT (FALSE);\r
}\r
+\r
+VOID\r
+RelocatePeCoffImage (\r
+ IN EFI_PEI_FV_HANDLE FwVolHeader,\r
+ IN PE_COFF_LOADER_READ_FILE ImageRead\r
+ )\r
+{\r
+ EFI_PEI_FILE_HANDLE FileHandle;\r
+ VOID *SectionData;\r
+ PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r
+ EFI_STATUS Status;\r
+\r
+ FileHandle = NULL;\r
+ Status = FfsFindNextFile (EFI_FV_FILETYPE_SECURITY_CORE, FwVolHeader,\r
+ &FileHandle);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &SectionData);\r
+ if (EFI_ERROR (Status)) {\r
+ Status = FfsFindSectionData (EFI_SECTION_TE, FileHandle, &SectionData);\r
+ }\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ ZeroMem (&ImageContext, sizeof ImageContext);\r
+\r
+ ImageContext.Handle = (EFI_HANDLE)SectionData;\r
+ ImageContext.ImageRead = ImageRead;\r
+ PeCoffLoaderGetImageInfo (&ImageContext);\r
+\r
+ if (ImageContext.ImageAddress != (UINTN)SectionData) {\r
+ ImageContext.ImageAddress = (UINTN)SectionData;\r
+ PeCoffLoaderRelocateImage (&ImageContext);\r
+ }\r
+}\r