From: Laszlo Ersek <lersek@redhat.com>
To: "Gao, Liming" <liming.gao@intel.com>,
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" <trini@konsulko.com>,
"robdclark@gmail.com" <robdclark@gmail.com>,
"u-boot@lists.denx.de" <u-boot@lists.denx.de>,
"edk2-devel@lists.01.org" <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>,
"Rothman, Michael A" <michael.a.rothman@intel.com>
Subject: Re: [RESEND PATCH v2 2/6] efi_loader: Initial HII database protocols
Date: Tue, 8 Jan 2019 18:15:00 +0100 [thread overview]
Message-ID: <ea2253e4-7cdd-b06f-5319-5dc4f53389d6@redhat.com> (raw)
In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14E3ADCB9@SHSMSX152.ccr.corp.intel.com>
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
next prev parent reply other threads:[~2019-01-08 17:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20181214101043.14067-1-takahiro.akashi@linaro.org>
[not found] ` <20181214101043.14067-3-takahiro.akashi@linaro.org>
[not found] ` <eaa42b61-8335-e6f1-87c5-b9be79d32982@gmx.de>
[not found] ` <20181217011626.GC14562@linaro.org>
[not found] ` <84b6f3fd-ed68-a541-7727-69e5392984e6@suse.de>
[not found] ` <20181225083024.GC14405@linaro.org>
2019-01-07 14:09 ` [RESEND PATCH v2 2/6] efi_loader: Initial HII database protocols Leif Lindholm
2019-01-07 18:29 ` Laszlo Ersek
2019-01-07 19:22 ` Leif Lindholm
2019-01-08 0:28 ` Laszlo Ersek
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:45 ` Leif Lindholm
2019-01-08 17:15 ` Laszlo Ersek [this message]
2019-01-08 15:02 ` Bi, Dandan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea2253e4-7cdd-b06f-5319-5dc4f53389d6@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox