* Re: [RESEND PATCH v2 2/6] efi_loader: Initial HII database protocols
2019-01-08 9:51 ` Leif Lindholm
@ 2019-01-08 10:07 ` Ard Biesheuvel
2019-01-08 11:55 ` Laszlo Ersek
2019-01-08 15:02 ` Bi, Dandan
2 siblings, 0 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2019-01-08 10:07 UTC (permalink / raw)
To: Leif Lindholm
Cc: Laszlo Ersek, AKASHI Takahiro, Alexander Graf,
Heinrich Schuchardt, Tom Rini, Rob Clark, U-Boot Mailing List,
edk2-devel@lists.01.org, Jian J Wang, Hao Wu, Ruiyu Ni, Star Zeng,
Andrew Fish, Michael D Kinney, Liming Gao
On Tue, 8 Jan 2019 at 10:51, Leif Lindholm <leif.lindholm@linaro.org> wrote:
>
> MdePkg/MdeModulePkg maintainers - any comments?
>
> On Tue, Jan 08, 2019 at 01:28:00AM +0100, Laszlo Ersek wrote:
> > On 01/07/19 20:22, Leif Lindholm wrote:
> > > On Mon, Jan 07, 2019 at 07:29:47PM +0100, Laszlo Ersek wrote:
> >
> > >> The UEFI spec (v2.7) explicitly requires EFI_GUID to be 64-bit aligned,
> > >> unless specified otherwise. See in "Table 5. Common UEFI Data Types":
> > >>
> > >> EFI_GUID -- 128-bit buffer containing a unique identifier value.
> > >> Unless otherwise specified, aligned on a 64-bit
> > >> boundary.
> > >
> > > Indeed.
> > >
> > >> Whether edk2 satisfies that, and if so, how (by chance / by general
> > >> build flags), I don't know. The code says,
> > >>
> > >> ///
> > >> /// 128 bit buffer containing a unique identifier value.
> > >> /// Unless otherwise specified, aligned on a 64 bit boundary.
> > >> ///
> > >> typedef struct {
> > >> UINT32 Data1;
> > >> UINT16 Data2;
> > >> UINT16 Data3;
> > >> UINT8 Data4[8];
> > >> } GUID;
> > >>
> > >> I think there may have been an expectation in "MdePkg/Include/Base.h"
> > >> that the supported compilers would automatically ensure the specified
> > >> alignment, given the structure definition.
> > >
> > > But that would be expecting things not only not guaranteed by C, but
> > > something there is no semantic information suggesting would be useful
> > > for the compiler to do above. [...]
> >
> > Agreed. I'm not saying the edk2 code is right, just guessing why the
> > code might look like it does. This would not be the first silent
> > assumption, I think.
> >
> > Anyhow, I think it would be better to change the code than the spec.
>
> Of course it would be better to change the code than the spec.
>
> But as Ard points out off-thread, doing (as a hack, with gcc)
>
> diff --git a/MdePkg/Include/Uefi/UefiBaseType.h
> b/MdePkg/Include/Uefi/UefiBaseType.h
> index 8c9d571eb1..75409f3460 100644
> --- a/MdePkg/Include/Uefi/UefiBaseType.h
> +++ b/MdePkg/Include/Uefi/UefiBaseType.h
> @@ -26,7 +26,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
> EITHER EXPRESS OR IMPLIED.
> ///
> /// 128-bit buffer containing a unique identifier value.
> ///
> -typedef GUID EFI_GUID;
> +typedef GUID EFI_GUID __attribute__((aligned (8)));
> ///
> /// Function return status for EFI API.
> ///
>
> breaks Linux boot on ARM (32-bit), since it inserts 32-bits of padding
> between ConfigurationTable entries in the system table. So I don't see
> how that can realistically be fixed in the EDK2 codebase.
>
> And with things like the EFI_HII_KEYBOARD_LAYOUT struct, if there has
> ever been compatibility between EDK2 and commercial BIOSes, then that
> struct has always been treated as packed (not just 32-bit aligned
> GUIDs), and the spec just needs to reflect reality. If there hasn't,
> then indeed the code change here would be trivial.
>
> (Adding Liming as well, since we're now discussing MdePkg also.)
>
> Yes, this discussion belongs on USWG (UEFI specification working group
> mailing list), but I want to hear some comment from the package
> maintainers first.
>
Since we don't align EFI_GUIDs to 64 bits anywhere in the EDK2 code
base, and given that it is always possible to relax a spec but not to
tighten it without breaking backward compatibility, I think the only
sane way to deal with this is to update the spec and/or any pertinent
comments in the code to say that EFI_GUIDs are 32-bit aligned not
64-bit aligned.
That still leaves us with an issue in Linux, since efi_guid_t there
has no minimal alignment, and runtime services code taking EFI_GUID
pointers as input (such as Get/SetVariable) may assume they are 32-bit
aligned (given the UINT32 member in the EDK2 definition) and thus
assume it is safe to use load double/multiple instructions to access
them (which will either fault or cause an alignment fixup to trigger
if they are invoked with an unaligned memory address). But this is a
different issue.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RESEND PATCH v2 2/6] efi_loader: Initial HII database protocols
2019-01-08 9:51 ` Leif Lindholm
2019-01-08 10:07 ` Ard Biesheuvel
@ 2019-01-08 11:55 ` Laszlo Ersek
2019-01-08 15:12 ` Gao, Liming
2019-01-08 15:02 ` Bi, Dandan
2 siblings, 1 reply; 11+ messages in thread
From: Laszlo Ersek @ 2019-01-08 11:55 UTC (permalink / raw)
To: Leif Lindholm
Cc: AKASHI Takahiro, Alexander Graf, Heinrich Schuchardt, trini,
robdclark, u-boot, edk2-devel, Jian J Wang, Hao Wu, Ruiyu Ni,
Star Zeng, Andrew Fish, Michael D Kinney, Ard Biesheuvel,
Liming Gao
On 01/08/19 10:51, Leif Lindholm wrote:
> MdePkg/MdeModulePkg maintainers - any comments?
>
> On Tue, Jan 08, 2019 at 01:28:00AM +0100, Laszlo Ersek wrote:
>> On 01/07/19 20:22, Leif Lindholm wrote:
>>> On Mon, Jan 07, 2019 at 07:29:47PM +0100, Laszlo Ersek wrote:
>>
>>>> The UEFI spec (v2.7) explicitly requires EFI_GUID to be 64-bit aligned,
>>>> unless specified otherwise. See in "Table 5. Common UEFI Data Types":
>>>>
>>>> EFI_GUID -- 128-bit buffer containing a unique identifier value.
>>>> Unless otherwise specified, aligned on a 64-bit
>>>> boundary.
>>>
>>> Indeed.
>>>
>>>> Whether edk2 satisfies that, and if so, how (by chance / by general
>>>> build flags), I don't know. The code says,
>>>>
>>>> ///
>>>> /// 128 bit buffer containing a unique identifier value.
>>>> /// Unless otherwise specified, aligned on a 64 bit boundary.
>>>> ///
>>>> typedef struct {
>>>> UINT32 Data1;
>>>> UINT16 Data2;
>>>> UINT16 Data3;
>>>> UINT8 Data4[8];
>>>> } GUID;
>>>>
>>>> I think there may have been an expectation in "MdePkg/Include/Base.h"
>>>> that the supported compilers would automatically ensure the specified
>>>> alignment, given the structure definition.
>>>
>>> But that would be expecting things not only not guaranteed by C, but
>>> something there is no semantic information suggesting would be useful
>>> for the compiler to do above. [...]
>>
>> Agreed. I'm not saying the edk2 code is right, just guessing why the
>> code might look like it does. This would not be the first silent
>> assumption, I think.
>>
>> Anyhow, I think it would be better to change the code than the spec.
>
> Of course it would be better to change the code than the spec.
>
> But as Ard points out off-thread, doing (as a hack, with gcc)
>
> diff --git a/MdePkg/Include/Uefi/UefiBaseType.h
> b/MdePkg/Include/Uefi/UefiBaseType.h
> index 8c9d571eb1..75409f3460 100644
> --- a/MdePkg/Include/Uefi/UefiBaseType.h
> +++ b/MdePkg/Include/Uefi/UefiBaseType.h
> @@ -26,7 +26,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
> EITHER EXPRESS OR IMPLIED.
> ///
> /// 128-bit buffer containing a unique identifier value.
> ///
> -typedef GUID EFI_GUID;
> +typedef GUID EFI_GUID __attribute__((aligned (8)));
> ///
> /// Function return status for EFI API.
> ///
>
> breaks Linux boot on ARM (32-bit), since it inserts 32-bits of padding
> between ConfigurationTable entries in the system table.
(
More precisely, it adds padding to EFI_CONFIGURATION_TABLE after
"VendorGuid" or after "VendorTable". Padding may not be added at the
beginning of structures, and may not be added anywhere to arrays.
The practical effect is the same, so this is just a side comment about C.
)
Thanks
Laszlo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RESEND PATCH v2 2/6] efi_loader: Initial HII database protocols
2019-01-08 11:55 ` Laszlo Ersek
@ 2019-01-08 15:12 ` Gao, Liming
2019-01-08 15:45 ` Leif Lindholm
2019-01-08 17:15 ` Laszlo Ersek
0 siblings, 2 replies; 11+ messages in thread
From: Gao, Liming @ 2019-01-08 15:12 UTC (permalink / raw)
To: Laszlo Ersek, Leif Lindholm
Cc: AKASHI Takahiro, Alexander Graf, Heinrich Schuchardt,
trini@konsulko.com, robdclark@gmail.com, u-boot@lists.denx.de,
edk2-devel@lists.01.org, Wang, Jian J, Wu, Hao A, Ni, Ray,
Zeng, Star, Andrew Fish, Kinney, Michael D, Ard Biesheuvel,
Rothman, Michael A
EFI_GUID structure definition follows RFC UUID https://www.ietf.org/rfc/rfc4122.txt. This RFC has no 64 bit boundary requirement. I don't know the background why UEFI spec requires to align on 64-bit boundary. This may be true for early IPF arch. UEFI forum can clarify its purpose. If no specific reason, I suggest to follow the industry standard GUID format, and update UEFI spec.
On pack in structure EFI_HII_KEYBOARD_LAYOUT, UEFI2.7 32.3 Code Definitions has one sentence that this chapter describes the binary encoding of the different package types. 32.3.3 Font Package has the additional statement that structures described here are byte packed. Base on those description, we can infer HII package data is the byte packed. I agree to obviously specify that structures described here are byte packed in 32.3 section.
Last, EFI_HII_KEYBOARD_PACKAGE_HDR structure definition doesn't follow UEFI spec. I remember we ever meet with the compiler issue for below style. GCC49 may complaint it. I need to double confirm.
typedef struct {
EFI_HII_PACKAGE_HEADER Header;
UINT16 LayoutCount;
EFI_HII_KEYBOARD_LAYOUT Layout[];
} EFI_HII_KEYBOARD_PACKAGE_HDR;
Thanks
Liming
> -----Original Message-----
> From: Laszlo Ersek [mailto:lersek@redhat.com]
> Sent: Tuesday, January 8, 2019 7:56 PM
> To: Leif Lindholm <leif.lindholm@linaro.org>
> Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>; Alexander Graf <agraf@suse.de>; Heinrich Schuchardt <xypron.glpk@gmx.de>;
> trini@konsulko.com; robdclark@gmail.com; u-boot@lists.denx.de; edk2-devel@lists.01.org; Wang, Jian J <jian.j.wang@intel.com>; Wu,
> Hao A <hao.a.wu@intel.com>; Ni, Ray <ray.ni@intel.com>; Zeng, Star <star.zeng@intel.com>; Andrew Fish <afish@apple.com>; Kinney,
> Michael D <michael.d.kinney@intel.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>; Gao, Liming <liming.gao@intel.com>
> Subject: Re: [RESEND PATCH v2 2/6] efi_loader: Initial HII database protocols
>
> On 01/08/19 10:51, Leif Lindholm wrote:
> > MdePkg/MdeModulePkg maintainers - any comments?
> >
> > On Tue, Jan 08, 2019 at 01:28:00AM +0100, Laszlo Ersek wrote:
> >> On 01/07/19 20:22, Leif Lindholm wrote:
> >>> On Mon, Jan 07, 2019 at 07:29:47PM +0100, Laszlo Ersek wrote:
> >>
> >>>> The UEFI spec (v2.7) explicitly requires EFI_GUID to be 64-bit aligned,
> >>>> unless specified otherwise. See in "Table 5. Common UEFI Data Types":
> >>>>
> >>>> EFI_GUID -- 128-bit buffer containing a unique identifier value.
> >>>> Unless otherwise specified, aligned on a 64-bit
> >>>> boundary.
> >>>
> >>> Indeed.
> >>>
> >>>> Whether edk2 satisfies that, and if so, how (by chance / by general
> >>>> build flags), I don't know. The code says,
> >>>>
> >>>> ///
> >>>> /// 128 bit buffer containing a unique identifier value.
> >>>> /// Unless otherwise specified, aligned on a 64 bit boundary.
> >>>> ///
> >>>> typedef struct {
> >>>> UINT32 Data1;
> >>>> UINT16 Data2;
> >>>> UINT16 Data3;
> >>>> UINT8 Data4[8];
> >>>> } GUID;
> >>>>
> >>>> I think there may have been an expectation in "MdePkg/Include/Base.h"
> >>>> that the supported compilers would automatically ensure the specified
> >>>> alignment, given the structure definition.
> >>>
> >>> But that would be expecting things not only not guaranteed by C, but
> >>> something there is no semantic information suggesting would be useful
> >>> for the compiler to do above. [...]
> >>
> >> Agreed. I'm not saying the edk2 code is right, just guessing why the
> >> code might look like it does. This would not be the first silent
> >> assumption, I think.
> >>
> >> Anyhow, I think it would be better to change the code than the spec.
> >
> > Of course it would be better to change the code than the spec.
> >
> > But as Ard points out off-thread, doing (as a hack, with gcc)
> >
> > diff --git a/MdePkg/Include/Uefi/UefiBaseType.h
> > b/MdePkg/Include/Uefi/UefiBaseType.h
> > index 8c9d571eb1..75409f3460 100644
> > --- a/MdePkg/Include/Uefi/UefiBaseType.h
> > +++ b/MdePkg/Include/Uefi/UefiBaseType.h
> > @@ -26,7 +26,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
> > EITHER EXPRESS OR IMPLIED.
> > ///
> > /// 128-bit buffer containing a unique identifier value.
> > ///
> > -typedef GUID EFI_GUID;
> > +typedef GUID EFI_GUID __attribute__((aligned (8)));
> > ///
> > /// Function return status for EFI API.
> > ///
> >
> > breaks Linux boot on ARM (32-bit), since it inserts 32-bits of padding
> > between ConfigurationTable entries in the system table.
>
> (
>
> More precisely, it adds padding to EFI_CONFIGURATION_TABLE after
> "VendorGuid" or after "VendorTable". Padding may not be added at the
> beginning of structures, and may not be added anywhere to arrays.
>
> The practical effect is the same, so this is just a side comment about C.
>
> )
>
> Thanks
> Laszlo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RESEND PATCH v2 2/6] efi_loader: Initial HII database protocols
2019-01-08 15:12 ` Gao, Liming
@ 2019-01-08 15:45 ` Leif Lindholm
2019-01-08 17:15 ` Laszlo Ersek
1 sibling, 0 replies; 11+ messages in thread
From: Leif Lindholm @ 2019-01-08 15:45 UTC (permalink / raw)
To: Gao, Liming
Cc: Laszlo Ersek, AKASHI Takahiro, Alexander Graf,
Heinrich Schuchardt, trini@konsulko.com, robdclark@gmail.com,
u-boot@lists.denx.de, edk2-devel@lists.01.org, Wang, Jian J,
Wu, Hao A, Ni, Ray, Zeng, Star, Andrew Fish, Kinney, Michael D,
Ard Biesheuvel, Rothman, Michael A
Thanks Liming, this exactly the reply I was hoping for.
On Tue, Jan 08, 2019 at 03:12:11PM +0000, Gao, Liming wrote:
> EFI_GUID structure definition follows RFC UUID
> https://www.ietf.org/rfc/rfc4122.txt. This RFC has no 64 bit
> boundary requirement. I don't know the background why UEFI spec
> requires to align on 64-bit boundary. This may be true for early IPF
> arch. UEFI forum can clarify its purpose. If no specific reason, I
> suggest to follow the industry standard GUID format, and update UEFI
> spec.
Since there would be no 64-bit alignment requirements for IPF either
for correctness reasons, I expect it was added for performance reasons.
> On pack in structure EFI_HII_KEYBOARD_LAYOUT, UEFI2.7 32.3 Code
> Definitions has one sentence that this chapter describes the binary
> encoding of the different package types. 32.3.3 Font Package has the
> additional statement that structures described here are byte
> packed. Base on those description, we can infer HII package data is
> the byte packed. I agree to obviously specify that structures
> described here are byte packed in 32.3 section.
That sounds good to me.
> Last, EFI_HII_KEYBOARD_PACKAGE_HDR structure definition doesn't
> follow UEFI spec. I remember we ever meet with the compiler issue
> for below style. GCC49 may complaint it. I need to double confirm.
> typedef struct {
> EFI_HII_PACKAGE_HEADER Header;
> UINT16 LayoutCount;
> EFI_HII_KEYBOARD_LAYOUT Layout[];
> } EFI_HII_KEYBOARD_PACKAGE_HDR;
I did remark on this to Ard, and he pointed out the old compiler
issue. If I delete those comment markers, I cannot reproduce a problem
with either GCC48 or GCC49 (on those actual compiler versions) on ARM.
Right, I will put together an email to USWG with you on cc.
Regards,
Leif
>
> Thanks
> Liming
> > -----Original Message-----
> > From: Laszlo Ersek [mailto:lersek@redhat.com]
> > Sent: Tuesday, January 8, 2019 7:56 PM
> > To: Leif Lindholm <leif.lindholm@linaro.org>
> > Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>; Alexander Graf <agraf@suse.de>; Heinrich Schuchardt <xypron.glpk@gmx.de>;
> > trini@konsulko.com; robdclark@gmail.com; u-boot@lists.denx.de; edk2-devel@lists.01.org; Wang, Jian J <jian.j.wang@intel.com>; Wu,
> > Hao A <hao.a.wu@intel.com>; Ni, Ray <ray.ni@intel.com>; Zeng, Star <star.zeng@intel.com>; Andrew Fish <afish@apple.com>; Kinney,
> > Michael D <michael.d.kinney@intel.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>; Gao, Liming <liming.gao@intel.com>
> > Subject: Re: [RESEND PATCH v2 2/6] efi_loader: Initial HII database protocols
> >
> > On 01/08/19 10:51, Leif Lindholm wrote:
> > > MdePkg/MdeModulePkg maintainers - any comments?
> > >
> > > On Tue, Jan 08, 2019 at 01:28:00AM +0100, Laszlo Ersek wrote:
> > >> On 01/07/19 20:22, Leif Lindholm wrote:
> > >>> On Mon, Jan 07, 2019 at 07:29:47PM +0100, Laszlo Ersek wrote:
> > >>
> > >>>> The UEFI spec (v2.7) explicitly requires EFI_GUID to be 64-bit aligned,
> > >>>> unless specified otherwise. See in "Table 5. Common UEFI Data Types":
> > >>>>
> > >>>> EFI_GUID -- 128-bit buffer containing a unique identifier value.
> > >>>> Unless otherwise specified, aligned on a 64-bit
> > >>>> boundary.
> > >>>
> > >>> Indeed.
> > >>>
> > >>>> Whether edk2 satisfies that, and if so, how (by chance / by general
> > >>>> build flags), I don't know. The code says,
> > >>>>
> > >>>> ///
> > >>>> /// 128 bit buffer containing a unique identifier value.
> > >>>> /// Unless otherwise specified, aligned on a 64 bit boundary.
> > >>>> ///
> > >>>> typedef struct {
> > >>>> UINT32 Data1;
> > >>>> UINT16 Data2;
> > >>>> UINT16 Data3;
> > >>>> UINT8 Data4[8];
> > >>>> } GUID;
> > >>>>
> > >>>> I think there may have been an expectation in "MdePkg/Include/Base.h"
> > >>>> that the supported compilers would automatically ensure the specified
> > >>>> alignment, given the structure definition.
> > >>>
> > >>> But that would be expecting things not only not guaranteed by C, but
> > >>> something there is no semantic information suggesting would be useful
> > >>> for the compiler to do above. [...]
> > >>
> > >> Agreed. I'm not saying the edk2 code is right, just guessing why the
> > >> code might look like it does. This would not be the first silent
> > >> assumption, I think.
> > >>
> > >> Anyhow, I think it would be better to change the code than the spec.
> > >
> > > Of course it would be better to change the code than the spec.
> > >
> > > But as Ard points out off-thread, doing (as a hack, with gcc)
> > >
> > > diff --git a/MdePkg/Include/Uefi/UefiBaseType.h
> > > b/MdePkg/Include/Uefi/UefiBaseType.h
> > > index 8c9d571eb1..75409f3460 100644
> > > --- a/MdePkg/Include/Uefi/UefiBaseType.h
> > > +++ b/MdePkg/Include/Uefi/UefiBaseType.h
> > > @@ -26,7 +26,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
> > > EITHER EXPRESS OR IMPLIED.
> > > ///
> > > /// 128-bit buffer containing a unique identifier value.
> > > ///
> > > -typedef GUID EFI_GUID;
> > > +typedef GUID EFI_GUID __attribute__((aligned (8)));
> > > ///
> > > /// Function return status for EFI API.
> > > ///
> > >
> > > breaks Linux boot on ARM (32-bit), since it inserts 32-bits of padding
> > > between ConfigurationTable entries in the system table.
> >
> > (
> >
> > More precisely, it adds padding to EFI_CONFIGURATION_TABLE after
> > "VendorGuid" or after "VendorTable". Padding may not be added at the
> > beginning of structures, and may not be added anywhere to arrays.
> >
> > The practical effect is the same, so this is just a side comment about C.
> >
> > )
> >
> > Thanks
> > Laszlo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RESEND PATCH v2 2/6] efi_loader: Initial HII database protocols
2019-01-08 15:12 ` Gao, Liming
2019-01-08 15:45 ` Leif Lindholm
@ 2019-01-08 17:15 ` Laszlo Ersek
1 sibling, 0 replies; 11+ messages in thread
From: Laszlo Ersek @ 2019-01-08 17:15 UTC (permalink / raw)
To: Gao, Liming, Leif Lindholm
Cc: AKASHI Takahiro, Alexander Graf, Heinrich Schuchardt,
trini@konsulko.com, robdclark@gmail.com, u-boot@lists.denx.de,
edk2-devel@lists.01.org, Wang, Jian J, Wu, Hao A, Ni, Ray,
Zeng, Star, Andrew Fish, Kinney, Michael D, Ard Biesheuvel,
Rothman, Michael A
On 01/08/19 16:12, Gao, Liming wrote:
> Last, EFI_HII_KEYBOARD_PACKAGE_HDR structure definition doesn't follow UEFI spec. I remember we ever meet with the compiler issue for below style. GCC49 may complaint it. I need to double confirm.
> typedef struct {
> EFI_HII_PACKAGE_HEADER Header;
> UINT16 LayoutCount;
> EFI_HII_KEYBOARD_LAYOUT Layout[];
> } EFI_HII_KEYBOARD_PACKAGE_HDR;
This is called "flexible array member", and it was introduced in ISO
C99. It is not part of the earlier C standards, and I quite expect
several of the toolchains currently supported by edk2 to reject it.
Code written against earlier releases of the ISO C standard than C99
would use a construct colloquially called the "struct hack", such as
typedef struct {
EFI_HII_PACKAGE_HEADER Header;
UINT16 LayoutCount;
EFI_HII_KEYBOARD_LAYOUT Layout[1];
} EFI_HII_KEYBOARD_PACKAGE_HDR;
indexing "Layout" with a subscript >= 1. Needless to say, that was
always undefined behavior :) C99 introduced the flexible array member
precisely for covering the "struct hack" use case with a well-defined
construct.
There is no portable, pre-C99 way to actually spell out the Layout field
in the structure definition, with the intended use case. The most
portable approach I can think of would be:
- explain the trailing (nameless) array in a comment,
- instruct programmers to write manual pointer-to-unsigned-char arithmetic,
- once the necessary element is located, copy it into an object actually
declared with the element type, and access it there.
In edk2 we sometimes do steps #1 and #2, which is OK. But, even in those
cases, we almost never do step #3 (because it's both cumbersome and
wastes cycles) -- instead, we favor type-punning.
Whenever I see that, I tell myself, "we disable the effective type rules
with '-fno-strict-aliasing', so this should be fine, in practice. I hope
anyway." :)
Thanks,
Laszlo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RESEND PATCH v2 2/6] efi_loader: Initial HII database protocols
2019-01-08 9:51 ` Leif Lindholm
2019-01-08 10:07 ` Ard Biesheuvel
2019-01-08 11:55 ` Laszlo Ersek
@ 2019-01-08 15:02 ` Bi, Dandan
2 siblings, 0 replies; 11+ messages in thread
From: Bi, Dandan @ 2019-01-08 15:02 UTC (permalink / raw)
To: 'Leif Lindholm', Laszlo Ersek
Cc: Ni, Ray, trini@konsulko.com, AKASHI Takahiro, Wu, Hao A,
Heinrich Schuchardt, edk2-devel@lists.01.org, Alexander Graf,
Gao, Liming, u-boot@lists.denx.de, robdclark@gmail.com,
Kinney, Michael D, Zeng, Star
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Leif Lindholm
> Sent: Tuesday, January 08, 2019 5:51 PM
> To: Laszlo Ersek <lersek@redhat.com>
> Cc: Ni, Ray <ray.ni@intel.com>; trini@konsulko.com; AKASHI Takahiro
> <takahiro.akashi@linaro.org>; Wu, Hao A <hao.a.wu@intel.com>; Heinrich
> Schuchardt <xypron.glpk@gmx.de>; edk2-devel@lists.01.org; Alexander
> Graf <agraf@suse.de>; Gao, Liming <liming.gao@intel.com>; u-
> boot@lists.denx.de; robdclark@gmail.com; Kinney, Michael D
> <michael.d.kinney@intel.com>; Zeng, Star <star.zeng@intel.com>
> Subject: Re: [edk2] [RESEND PATCH v2 2/6] efi_loader: Initial HII database
> protocols
>
> MdePkg/MdeModulePkg maintainers - any comments?
>
> On Tue, Jan 08, 2019 at 01:28:00AM +0100, Laszlo Ersek wrote:
> > On 01/07/19 20:22, Leif Lindholm wrote:
> > > On Mon, Jan 07, 2019 at 07:29:47PM +0100, Laszlo Ersek wrote:
> >
> > >> The UEFI spec (v2.7) explicitly requires EFI_GUID to be 64-bit
> > >> aligned, unless specified otherwise. See in "Table 5. Common UEFI Data
> Types":
> > >>
> > >> EFI_GUID -- 128-bit buffer containing a unique identifier value.
> > >> Unless otherwise specified, aligned on a 64-bit
> > >> boundary.
> > >
> > > Indeed.
> > >
> > >> Whether edk2 satisfies that, and if so, how (by chance / by general
> > >> build flags), I don't know. The code says,
> > >>
> > >> ///
> > >> /// 128 bit buffer containing a unique identifier value.
> > >> /// Unless otherwise specified, aligned on a 64 bit boundary.
> > >> ///
> > >> typedef struct {
> > >> UINT32 Data1;
> > >> UINT16 Data2;
> > >> UINT16 Data3;
> > >> UINT8 Data4[8];
> > >> } GUID;
> > >>
> > >> I think there may have been an expectation in
> "MdePkg/Include/Base.h"
> > >> that the supported compilers would automatically ensure the
> > >> specified alignment, given the structure definition.
> > >
> > > But that would be expecting things not only not guaranteed by C, but
> > > something there is no semantic information suggesting would be
> > > useful for the compiler to do above. [...]
> >
> > Agreed. I'm not saying the edk2 code is right, just guessing why the
> > code might look like it does. This would not be the first silent
> > assumption, I think.
> >
> > Anyhow, I think it would be better to change the code than the spec.
>
> Of course it would be better to change the code than the spec.
>
> But as Ard points out off-thread, doing (as a hack, with gcc)
>
> diff --git a/MdePkg/Include/Uefi/UefiBaseType.h
> b/MdePkg/Include/Uefi/UefiBaseType.h
> index 8c9d571eb1..75409f3460 100644
> --- a/MdePkg/Include/Uefi/UefiBaseType.h
> +++ b/MdePkg/Include/Uefi/UefiBaseType.h
> @@ -26,7 +26,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF
> ANY KIND, EITHER EXPRESS OR IMPLIED.
> ///
> /// 128-bit buffer containing a unique identifier value.
> ///
> -typedef GUID EFI_GUID;
> +typedef GUID EFI_GUID __attribute__((aligned (8)));
> ///
> /// Function return status for EFI API.
> ///
>
> breaks Linux boot on ARM (32-bit), since it inserts 32-bits of padding
> between ConfigurationTable entries in the system table. So I don't see how
> that can realistically be fixed in the EDK2 codebase.
>
> And with things like the EFI_HII_KEYBOARD_LAYOUT struct, if there has ever
> been compatibility between EDK2 and commercial BIOSes, then that struct
> has always been treated as packed (not just 32-bit aligned GUIDs), and the
> spec just needs to reflect reality. If there hasn't, then indeed the code
> change here would be trivial.
The structure definitions in Include/Uefi/UefiInternalFormRepresentation.h mainly describe the binary encoding of the different package types. And EFI_HII_KEYBOARD_LAYOUT struct is for the Keyboard Layout Package.
Describing the *binary encoding* of the different package type, so I think we should treat them as packed and it also should be the reason why they are packed now. Maybe we can reflect this more clear in Spec.
>
> (Adding Liming as well, since we're now discussing MdePkg also.)
>
> Yes, this discussion belongs on USWG (UEFI specification working group
> mailing list), but I want to hear some comment from the package
> maintainers first.
>
> Either way, I see a bunch of new SCT tests coming up.
>
> /
> Leif
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
^ permalink raw reply [flat|nested] 11+ messages in thread