Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220521082246.GA20105@voyager>
Date: Sat, 21 May 2022 10:22:46 +0200
From: Markus Wichmann <nullplan@....net>
To: musl@...ts.openwall.com
Subject: Re: add loongarch64 port v3

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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.