On the IA32 target, this doesn't work properly because the ImageSize field is not correctly aligned. ImageSize is a UINT64. Fields are supposed to be "naturally aligned". Naturally the spec doesn't bother to specify exactly what "naturally aligned" means, but other toolchains such as EDK2 seem to think it means a UINT64 should be 8-byte aligned.
In other words, offsetof(EFI_LOADED_IMAGE, ImageSize) on IA32 is 40 in EDK2, but 36 in shim due to the missing padding.
In pe.c, it sets the
ImageBase
andImageSize
inEFI_LOADED_IMAGE
for the second stage: https://github.com/rhboot/shim/blob/main/pe.c#L1394On the IA32 target, this doesn't work properly because the
ImageSize
field is not correctly aligned.ImageSize
is aUINT64
. Fields are supposed to be "naturally aligned". Naturally the spec doesn't bother to specify exactly what "naturally aligned" means, but other toolchains such as EDK2 seem to think it means aUINT64
should be 8-byte aligned.In other words,
offsetof(EFI_LOADED_IMAGE, ImageSize)
on IA32 is 40 in EDK2, but 36 in shim due to the missing padding.I think a straightforward fix would be to add
-malign-double
on IA32 (as EDK2 does), which will align "double, long double, and long long variables on a two-word boundary".