summaryrefslogtreecommitdiffstats
path: root/ArmVirtPkg/PrePi/Arm
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@arm.com>2020-06-08 13:07:54 +0200
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-06-12 22:17:46 +0000
commitb16fd231f6d8124fa05a0f086840934b8709faf9 (patch)
treeacd28e0fb051819aa22845af2b99360905c25c90 /ArmVirtPkg/PrePi/Arm
parentfd708fe0e1f813d6faf02d92ec5e8d73ce876ed1 (diff)
downloadedk2-b16fd231f6d8124fa05a0f086840934b8709faf9.tar.gz
edk2-b16fd231f6d8124fa05a0f086840934b8709faf9.tar.bz2
edk2-b16fd231f6d8124fa05a0f086840934b8709faf9.zip
ArmVirtPkg/PrePi: use standard PeCoff routines for self-relocation
Instead of having a GCC specific routine to perform self-relocation based on ELF metadata, use the PE/COFF metadata and the existing PeCoff library routines. This reduces the amount of bespoke assembler code that is a burden to maintain, and is not portable across the set of toolchains we support. This does require some special care, as we have no control over how the C code references global symbols, so we need to emit these references from the calling assembler code. Otherwise, they may be emitted as absolute references, in which case they need to be fixed up themselves, leading to a circular dependency. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com> Acked-by: Laszlo Ersek <lersek@redhat.com> Acked-by: Sami Mujawar <Sami.Mujawar@arm.com>
Diffstat (limited to 'ArmVirtPkg/PrePi/Arm')
-rw-r--r--ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S47
1 files changed, 12 insertions, 35 deletions
diff --git a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
index 72d756fdb5..f0536c65eb 100644
--- a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
+++ b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
@@ -9,38 +9,6 @@
#include <AsmMacroIoLib.h>
ASM_FUNC(_ModuleEntryPoint)
- //
- // We are built as a ET_DYN PIE executable, so we need to process all
- // relative relocations if we are executing from a different offset than we
- // were linked at. This is only possible if we are running from RAM.
- //
- ADRL (r4, __reloc_base)
- ADRL (r5, __reloc_start)
- ADRL (r6, __reloc_end)
-
-.Lreloc_loop:
- cmp r5, r6
- bhs .Lreloc_done
-
- //
- // AArch32 uses the ELF32 REL format, which means each entry in the
- // relocation table consists of
- //
- // UINT32 offset : the relative offset of the value that needs to
- // be relocated
- // UINT32 info : relocation type and symbol index (the latter is
- // not used for R_ARM_RELATIVE relocations)
- //
- ldrd r8, r9, [r5], #8 // read offset into r8 and info into r9
- cmp r9, #23 // check info == R_ARM_RELATIVE?
- bne .Lreloc_loop // not a relative relocation? then skip
-
- ldr r9, [r8, r4] // read addend into r9
- add r9, r9, r1 // add image base to addend to get relocated value
- str r9, [r8, r4] // write relocated value at offset
- b .Lreloc_loop
-.Lreloc_done:
-
// Do early platform specific actions
bl ASM_PFX(ArmPlatformPeiBootAction)
@@ -173,14 +141,23 @@ ASM_PFX(ArmPlatformPeiBootAction):
str r5, [r7]
//
+ // The runtime address may be different from the link time address so fix
+ // up the PE/COFF relocations. Since we are calling a C function, use the
+ // window at the beginning of the FD image as a temp stack.
+ //
+ mov r0, r5
+ ADRL (r1, PeCoffLoaderImageReadFromMemory)
+ mov sp, r5
+ bl RelocatePeCoffImage
+
+ //
// Discover the memory size and offset from the DTB, and record in the
// respective PCDs. This will also return false if a corrupt DTB is
- // encountered. Since we are calling a C function, use the window at the
- // beginning of the FD image as a temp stack.
+ // encountered.
//
+ mov r0, r10
ADRL (r1, PcdGet64 (PcdSystemMemoryBase))
ADRL (r2, PcdGet64 (PcdSystemMemorySize))
- mov sp, r5
bl FindMemnode
teq r0, #0
beq .Lout