]> git.proxmox.com Git - mirror_edk2.git/commitdiff
StandaloneMmPkg: generate position independent code for StMM core
authorArd Biesheuvel <ard.biesheuvel@arm.com>
Tue, 9 Jun 2020 08:24:06 +0000 (10:24 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 16 Jun 2020 16:15:00 +0000 (16:15 +0000)
The standalone MM core runs in a restricted environment that is set
up by a higher privilege level, and which may not allow memory regions
to be writable and executable at the same time.

This means that making the StMM core self-relocatable requires that
all the targets of the relocation fixups are outside of the executable
region of the image, given that we cannot remap the executable code
writable from the executable code itself without losing those execute
permissions.

So instead, use the existing toolchain support to ensure that position
independent code is used where possible, and that all the remaining
relocated quantities are emitted into the data section. (Note that
staticallly initialized const pointers will be emitted into the
.data.rel.ro section, which gets pulled into the .data section by
our linker script)

To ensure that we don't pick up any absolute references in executable
code inadvertently (e.g., in assembler code), add the '-z text' linker
option which will force the build to fail in this case.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
Acked-by: Jiewen Yao <Jiewen.yao@intel.com>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
StandaloneMmPkg/Core/StandaloneMmCore.inf
StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf

index d17ff9965bdcd0ff506c841dd1feb4ee3b586273..87bf6e9440a77b3c737a439be07896e2fcb406a2 100644 (file)
@@ -75,3 +75,7 @@
   gEfiEventLegacyBootGuid\r
   gEfiEventExitBootServicesGuid\r
   gEfiEventReadyToBootGuid\r
+\r
+[BuildOptions]\r
+  GCC:*_*_*_CC_FLAGS = -fpie\r
+  GCC:*_*_*_DLINK_FLAGS = -Wl,-z,text,-Bsymbolic,-pie\r
index 891c292e92f883e3639b4bd13cd4e6c6888d1e96..7d6ee4e08ecbff3262017f2e567145a148dfe0f7 100644 (file)
@@ -48,3 +48,6 @@
   gEfiMmPeiMmramMemoryReserveGuid\r
   gEfiStandaloneMmNonSecureBufferGuid\r
   gEfiArmTfCpuDriverEpDescriptorGuid\r
+\r
+[BuildOptions]\r
+  GCC:*_*_*_CC_FLAGS = -fpie\r