Re: [PATCH 1/3] struct packed: Use gcc_struct on Windows

Pedro Alves
2022-07-21T18:15:33Z

On 2022-07-21 6:40 p.m., Eli Zaretskii wrote:
>> Cc: gdb-patches@sourceware.org
>> From: Pedro Alves <pedro@palves.net>
>> Date: Thu, 21 Jul 2022 18:05:55 +0100
>>
>> On 2022-07-21 5:03 p.m., Eli Zaretskii wrote:
>>>> From: Pedro Alves <pedro@palves.net>
>>>> Date: Thu, 21 Jul 2022 16:21:30 +0100
>>>>
>>>> The issue is that mingw gcc defaults to "-mms-bitfields", which
>>>> affects how bitfields are laid out. We can however tell GCC that we
>>>> want the regular GCC layout instead using attribute gcc_struct.
>>>
>>> Is that a good idea? It means the code emitted by GCC for this source
>>> file will be incompatible with any other library compiled with MinGW
>>> that GDB uses. So we are risking ABI incompatibilities here. Right?
>>>
>>
>> No. The attribute only changes the layout of that particular structure.
>
> And we are 110% sure that structure will never be passed to any other
> code?

What other code are you talking about? struct packed is used in GDB's internal
structures. Nothing outside GDB ever sees it. GDB doesn't export a C api.
And if it did, we probably wouldn't use struct packed in exported structures.

>
>>> Can you tell why we must have the regular GCC layout of bitfields
>>> here?
>>
>> Because without it the struct won't really be packed.
>
> Can you tell why is that necessary?
>
> In any case, I'm very uneasy about changes that break ABI
> compatibility between parts of a program.
>

But no ABI compatibility is broken.