On 9/12/23 01:32, Warkentin, Andrei wrote:
> So I looked/asked and it seems both GCC and Clang have ways of ensuring
> alignment - either via #pragma or via a compiler flag
> (-falign-functions=4). I've yet to test this (particularly in the Clang
> case, which might have its own funky way via (-mllvm
> -align-all-function=2). So we could certainly mandate the alignment to
> be 32-bit for EFIAPI. Further down the line when/if 48-bit instructions
> happen this will ensure further sanity... Anyone think this is a
> terrible idea? Can someone from the U-boot side give their take - or
> maybe you know who to ask? Again the intention is to allow platform
> firmware to be build with C extension, the worry is just around EFIAPI
> (it should not be visible that the implementation uses C extension). Can
> we get a show of hands for the following two options:
> ---------------------------------------------------------------------
> Option 1) Sure, let's preemptively remove C as a requirement from UEFI
> spec, and add a 32-bit alignment requirement to EFIAPI. Even though
> deprecating C extension is just a possibility, we'd rather not keep
> perpetually introducing breaking changes to the UEFI spec.
> Option 2) We can wait it out and deal with it when/if the C extension
> becomes optional.
gcc generates 2 aligned function addresses by default. E.g. I found in
u-boot.map:
.text.efi_setup_loaded_image
0x000000008023ce7e 0xe2 lib/efi_loader/efi_boottime.o
0x000000008023ce7e efi_setup_loaded_image
-falign-functions changes the alignment of all functions.
Instead we could change the definition of EFIAPI in U-Boot and EDK II
-#define EFIAPI
+#define EFIAPI __attribute__((aligned(4)))
as described in
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-aligned-function-attribute
From the U-Boot side requiring EFIAPI function pointers to be 4 aligned
can easily be followed.
In the EDK II SCT many functions which should be EFIAPI lack that
attribute (
https://bugzilla.tianocore.org/show_bug.cgi?id=2126). I don't
know if the same holds true for EDK II itself.
U-Boot provides configuration symbol CONFIG_RISCV_ISA_C which would
allow to disable emission of compressed instructions if not supported by
the CPU.
In my role as U-Boot EFI maintainer both option 1 and option 2 look good
to me. Requiring 4 byte alignment for EFIAPI would be a prudent choice
in both cases.
Best regards
Heinrich