[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <55d62419-3a0c-4f26-a260-06cf2dc44ec1@embeddedor.com>
Date: Tue, 12 Nov 2024 19:08:32 -0600
From: "Gustavo A. R. Silva" <gustavo@...eddedor.com>
To: Jakub Kicinski <kuba@...nel.org>,
"Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc: Michael Chan <michael.chan@...adcom.com>,
Andrew Lunn <andrew+netdev@...n.ch>, "David S. Miller"
<davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Paolo Abeni <pabeni@...hat.com>, Potnuri Bharat Teja <bharat@...lsio.com>,
Christian Benvenuti <benve@...co.com>, Satish Kharat <satishkh@...co.com>,
Manish Chopra <manishc@...vell.com>, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org,
Kees Cook <kees@...nel.org>
Subject: Re: [PATCH v2 1/2][next] UAPI: ethtool: Use __struct_group() in
struct ethtool_link_settings
On 11/11/24 16:22, Gustavo A. R. Silva wrote:
>
>
> On 09/11/24 12:02, Jakub Kicinski wrote:
>> On Tue, 29 Oct 2024 15:55:35 -0600 Gustavo A. R. Silva wrote:
>>> Use the `__struct_group()` helper to create a new tagged
>>> `struct ethtool_link_settings_hdr`. This structure groups together
>>> all the members of the flexible `struct ethtool_link_settings`
>>> except the flexible array. As a result, the array is effectively
>>> separated from the rest of the members without modifying the memory
>>> layout of the flexible structure.
>>>
>>> This new tagged struct will be used to fix problematic declarations
>>> of middle-flex-arrays in composite structs[1].
>>
>> Possibly a very noob question, but I'm updating a C++ library with
>> new headers and I think this makes it no longer compile.
>>
>> $ cat > /tmp/t.cpp<<EOF
>> extern "C" {
>> #include "include/uapi/linux/ethtool.h"
>> }
>> int func() { return 0; }
>> EOF
>>
>> $ g++ /tmp/t.cpp -I../linux -o /dev/null -c -W -Wall -O2
>> In file included from /usr/include/linux/posix_types.h:5,
>> from /usr/include/linux/types.h:9,
>> from ../linux/include/uapi/linux/ethtool.h:18,
>> from /tmp/t.cpp:2:
>> ../linux/include/uapi/linux/ethtool.h:2515:24: error: ‘struct ethtool_link_settings::<unnamed union>::ethtool_link_settings_hdr’ invalid; an anonymous union
>> may only have public non-static data members [-fpermissive]
>> 2515 | __struct_group(ethtool_link_settings_hdr, hdr, /* no attrs */,
>> | ^~~~~~~~~~~~~~~~~~~~~~~~~
>>
>>
This seems to work with Clang:
$ clang++-18 -fms-extensions /tmp/t.cpp -I../linux -o /dev/null -c -W -Wall -O2
However, `-fms-extensions` doesn't seem to work for this case with GCC:
https://godbolt.org/z/1shsPhz3s
-Gustavo
>> I don't know much about C++, tho, so quite possibly missing something
>> obvious.
>
> We are in the same situation here.
>
> It seems C++ considers it ambiguous to define a struct with a tag such
> as `struct TAG { MEMBERS } ATTRS NAME;` within an anonymous union.
>
> Let me look into this further...
> --
> Gustavo
>
Powered by blists - more mailing lists