public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/3] struct packed: Use gcc_struct on Windows
Date: Thu, 21 Jul 2022 19:38:54 +0100	[thread overview]
Message-ID: <a73c1fb1-64bb-0c3a-9c45-92e66fa0f9c5@palves.net> (raw)
In-Reply-To: <834jzamiaw.fsf@gnu.org>

On 2022-07-21 7:28 p.m., Eli Zaretskii wrote:
>> Cc: gdb-patches@sourceware.org
>> From: Pedro Alves <pedro@palves.net>
>> Date: Thu, 21 Jul 2022 19:18:20 +0100
>>
>> On 2022-07-21 6:40 p.m., Eli Zaretskii wrote:
>>>> Cc: gdb-patches@sourceware.org
>>>> From: Pedro Alves <pedro@palves.net>
>>
>>>> Because without it the struct won't really be packed.
>>>
>>> Can you tell why is that necessary?
>>
>> Somehow I missed this question.  It is necessary because that's the whole
>> point of "struct packed".  To wrap some other type and pack it.  We use it
>> in some size-sensitive structures, to make them are as small as possible.
>> This is described in the gdbsupport/packed.h header.
> 
> You mean, this part:
> 
>   /* Each instantiation and full specialization of the packed template
>      defines a type that behaves like a given scalar type, but that has
>      byte alignment, and, may optionally have a smaller size than the
>      given scalar type.  This is typically used as alternative to
>      bit-fields (and ENUM_BITFIELD), when the fields must have separate
>      memory locations to avoid data races.  */
> 
> I don't think I see the rationale here, except "make them as small as
> possible".  Is that the reason?  

Well, we use bit fields in structs that need to be as small as possible.
But using bit fields is problematic in cases that lead to data races.
Instead of fixing the problem in every stop that might need it, we added
struct packed, to abstract it out.  Keeping the type as small is possible
is part of the point, otherwise we wouldn't have struct packed at all.

> If so, what would happen if the size
> is somewhat larger?  If the only result is less efficient GDB, I'd be
> happier if we sustained the efficiency hit, but stayed compatible to
> the ABI.
> 

I'm sorry, but that doesn't make sense.  This is used in GDB internals.
There's no ABI worry here.  Every compilation of every C++ file in
GDB sees the same struct packed definition.  It must, otherwise,
it would be a C++ ODR violation, meaning we'd have an invalid C++ program.

Please stop worrying about ABI compatibility here.  It's not relevant here.

  reply	other threads:[~2022-07-21 18:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21 15:21 [PATCH 0/3] struct packed and Windows ports (PR build/29373) Pedro Alves
2022-07-21 15:21 ` [PATCH 1/3] struct packed: Use gcc_struct on Windows Pedro Alves
2022-07-21 16:03   ` Eli Zaretskii
2022-07-21 17:05     ` Pedro Alves
2022-07-21 17:40       ` Eli Zaretskii
2022-07-21 18:15         ` Pedro Alves
2022-07-21 18:23           ` Eli Zaretskii
2022-07-21 18:30             ` Pedro Alves
2022-07-21 18:45               ` Eli Zaretskii
2022-07-21 18:57                 ` Pedro Alves
2022-07-21 18:18         ` Pedro Alves
2022-07-21 18:28           ` Eli Zaretskii
2022-07-21 18:38             ` Pedro Alves [this message]
2022-07-21 15:21 ` [PATCH 2/3] struct packed: Unit tests and more operators Pedro Alves
2022-07-21 15:21 ` [PATCH 3/3] struct packed: Add fallback byte array implementation Pedro Alves
2022-07-25 14:58 ` [PATCH 0/3] struct packed and Windows ports (PR build/29373) Tom Tromey
2022-07-25 15:18   ` Pedro Alves

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-all 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=a73c1fb1-64bb-0c3a-9c45-92e66fa0f9c5@palves.net \
    --to=pedro@palves.net \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).