On 6/10/20 8:21 PM, Sean Brogan wrote:
Ard,

I see you are only doing this for GCC?

Is it not needed for VS or clang? Are these toolchains not supported for StandaloneMmPkg?


This works with Clang as well as GCC (Clang is part of the GCC toolchain family in EDK2)

None of the AArch64 platforms we have in EDK2 or edk2-platforms can be built with VS today: the problem is that the asm dialect is different, and we don't have .asm versions of the startup code that can be built with VS. I think some of the common pieces have been ported by Pete Batard (so you can build individual drivers for AArch64 using VS), but nothing else.

Not trying to hold up your work and don't expect you to enable every toolchain but also don't like the idea of only building out support for a single toolchain given all the work that has gone into making modules compatible with numerous toolchains.

thoughts?


Leif and I tasked someone with adding this VS support when we were both at Linaro, but this never materialized, unfortunately. I don't have a Windows machine, and no bandwidth to educate myself on the use of Visual Studio (last version I used was 6 :-)), so I am going to leave this up to someone else.

That said, this alternative approach (suggested by Jiewen) was adopted to rely less on ELF particulars or GCC/binutils. I do think that building this code needs the attention of someone who understanfds the VS toolchain really well, though, since we need to build a standalone PE/COFF executable that is structured as a shared library (i.e., with no relocation records pointing into the executable segment), otherwise there is no way we can dispatch those running at S-EL0 under the Secure Partition Manager.

Do you have any candidates that could help me figure out the build options we need for VS here? Beyond that, I don't see any GCC dependencies in StandaloneMmPkg at all.




On 6/10/2020 1:17 AM, Ard Biesheuvel wrote:
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.biesheu...@arm.com>
---
StandaloneMmPkg/Core/StandaloneMmCore.inf | 4 ++++ StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf | 3 +++
  2 files changed, 7 insertions(+)

diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf b/StandaloneMmPkg/Core/StandaloneMmCore.inf
index d17ff9965bdc..87bf6e9440a7 100644
--- a/StandaloneMmPkg/Core/StandaloneMmCore.inf
+++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf
@@ -75,3 +75,7 @@ [Guids]
    gEfiEventLegacyBootGuid

    gEfiEventExitBootServicesGuid

    gEfiEventReadyToBootGuid

+

+[BuildOptions]

+  GCC:*_*_*_CC_FLAGS = -fpie

+  GCC:*_*_*_DLINK_FLAGS = -Wl,-z,text,-Bsymbolic,-pie

diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
index 891c292e92f8..7d6ee4e08ecb 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
@@ -48,3 +48,6 @@ [Guids]
    gEfiMmPeiMmramMemoryReserveGuid

    gEfiStandaloneMmNonSecureBufferGuid

    gEfiArmTfCpuDriverEpDescriptorGuid

+

+[BuildOptions]

+  GCC:*_*_*_CC_FLAGS = -fpie



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61088): https://edk2.groups.io/g/devel/message/61088
Mute This Topic: https://groups.io/mt/74792291/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to