Skip to content

Commit

Permalink
StandaloneMmPkg: generate position independent code for StMM core
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Jiewen Yao <[email protected]>
Tested-by: Ilias Apalodimas <[email protected]>
  • Loading branch information
Ard Biesheuvel authored and mergify[bot] committed Jun 16, 2020
1 parent 102da02 commit cdc6862
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions StandaloneMmPkg/Core/StandaloneMmCore.inf
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@
gEfiEventLegacyBootGuid
gEfiEventExitBootServicesGuid
gEfiEventReadyToBootGuid

[BuildOptions]
GCC:*_*_*_CC_FLAGS = -fpie
GCC:*_*_*_DLINK_FLAGS = -Wl,-z,text,-Bsymbolic,-pie
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@
gEfiMmPeiMmramMemoryReserveGuid
gEfiStandaloneMmNonSecureBufferGuid
gEfiArmTfCpuDriverEpDescriptorGuid

[BuildOptions]
GCC:*_*_*_CC_FLAGS = -fpie

0 comments on commit cdc6862

Please sign in to comment.