public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Sam James <sam@gentoo.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] socket: Use may_alias on sockaddr structs (bug 19622)
Date: Tue, 07 May 2024 14:01:05 +0200	[thread overview]
Message-ID: <87bk5h7rwe.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <87pltxalna.fsf@gentoo.org> (Sam James's message of "Tue, 07 May 2024 12:47:53 +0100")

* Sam James:

> Sam James <sam@gentoo.org> writes:
>
>> Florian Weimer <fweimer@redhat.com> writes:
>>
>>> This supports common coding paddings.  GCC before version 8
>>> rejects the may_alias attribute on a struct definition if it was
>>> not present in a previous forward declaration, so this attribute
>>> can only be conditionally applied.
>>>
>>> Tested on i686-linux-gnu, x86_64-linux-gnu.  Built with
>>> build-many-glibcs.py.
>>>
>>> Suggested-by: Marek Polacek <polacek@redhat.com>
>>> Suggested-by: Jakub Jelinek <jakub@redhat.com>
>>
>> Reviewed-by: Sam James <sam@gentoo.org>

Thanks.

> Also, on reflection, consider citing the POSIX change I mentioned on
> Bugzilla in the commit message too.
>
> I think it's useful in making clear this isn't (just) a QoI change?
>
> (https://austingroupbugs.net/view.php?id=1641)

I'm not sure we implement this today, particularly this part:

| Similarly, when a pointer to a sockaddr_storage or sockaddr structure
| is converted to a pointer to a protocol-specific address structure,
| the compiler shall treat an access (using this converted pointer) to
| the stored value of any member of the protocol-specific structure as
| permissible.

This seems to suggest that accessing uninitialized data or fields not
present in the original object (after casting to larger struct) has some
defined behavior, without actually assigning any meaning to it.

POSIX could have said that the implementation should behave as if there
is a definition

union
{
  struct sockaddr sa;
  struct sockaddr_in sin;
  struct sockaddr_in6 sin6;
  …
  struct sockaddr_storage ss;
} <implementation-specified>;

in every program.  Then the desired behavior would follow from C's
impossible-to-implement rule about union members and aliasing.

I can perhaps say that it partially addresses Austin Groups issue 1641.

Thanks,
Florian


      reply	other threads:[~2024-05-07 12:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-07  9:29 Florian Weimer
2024-05-07 11:38 ` Sam James
2024-05-07 11:47   ` Sam James
2024-05-07 12:01     ` Florian Weimer [this message]

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=87bk5h7rwe.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=sam@gentoo.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).