mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: [musl] add loongarch64 port v3
Date: Sat, 21 May 2022 10:22:46 +0200	[thread overview]
Message-ID: <20220521082246.GA20105@voyager> (raw)
In-Reply-To: <5fe467cd-4b68-2841-8aae-c485e7570267@loongson.cn>

On Sat, May 21, 2022 at 02:38:20PM +0800, 王洪亮 wrote:
>
> 在 2022/5/16 下午10:27, Rich Felker 写道:
> > Again, [0] is not valid C. If the extension field is going to be
> > declared at all it needs to be declared in a way it can be accessed
> > without invoking UB, e.g. as a FAM.
>
> [0] is allowed in GNU C, we can not use it in musl ?
>
> I don't understand  UB ?  e.g. as a FAM ?
>

musl tries to stay within ISO C as much as possible, and not use GNU C
extensions if it possibly can. In this case, zero-sized arrays do the
same thing as flexible array members, so there is absolutely no reason
to use the extension over the standard way.

UB = undefined behavior
FAM = flexible array member. If the last member of a structure is an
array, it can have indeterminate size. It will then not count towards
the size of the structure (only towards its alignment, possibly), and
can be indexed arbitrarily. This is a C99 feature.

So basically, just nix the 0 in that line.

> > I'm also not clear on how
> > specifying the alignment here helps since any object created in a way
> > that the alignment would affect cannot have the FAM present.
> >
> the __aligned__(16)  here used to save 128bit vector later.

But it has no effect, right? The array member is offset an integer
multiple of sixteen bytes from the start of the structure, so it is
already aligned with respect to that, and the declaration adds no
further padding (and if it did, common style in both Linux and musl is
to explicate the padding). And the pointer to the structure comes from
the kernel.

The only thing this alignment directive does is raise the alignment
requirement of the structure up to sixteen, but that only possibly
matters for variables of the structure type, be they automatic or
program life time. But from here it is hard to see why the alignment
should matter in either of those cases, since those would only possibly
be local buffers of the kernel-provided mcontext. And the kernel
provides the mcontext already with all the alignment it needs. I am not
aware of any kernel API that receives a user provided mcontext. And even
if there was one, the kernel would have to copy it into kernel space
before doing anything with it, anyway.

And, BTW, if the alignment really is needed on the mcontext_t itself, it
might be better to put the alignment tag on the type, not one of the
members.

Ciao,
Markus

  reply	other threads:[~2022-05-21  8:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-05  3:21 王洪亮
2022-05-09  1:34 ` [musl] " 王洪亮
2022-05-11 13:37   ` Rich Felker
2022-05-11 16:08     ` Arnd Bergmann
2022-05-16 14:27 ` [musl] " Rich Felker
2022-05-21  6:38   ` 王洪亮
2022-05-21  8:22     ` Markus Wichmann [this message]
2022-05-24  9:08       ` 王洪亮
2022-05-24 12:32         ` Rich Felker
2022-05-25 10:08           ` 王洪亮
2022-05-25 12:32             ` Rich Felker
2022-05-26  3:07               ` 王洪亮
2022-05-29  6:34                 ` Szabolcs Nagy

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=20220521082246.GA20105@voyager \
    --to=nullplan@gmx.net \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).