Re: [Regression] [PATCH v5 2/4] vdso: Switch get/put unaligned from packed struct to memcpy
From: David Laight
Date: Tue Oct 20 2026 - 06:01:49 EST
On Tue, 20 Oct 2026 10:41:27 +0200
"Arnd Bergmann" <arnd@xxxxxxxx> wrote:
> On Tue, Oct 20, 2026, at 10:36, David Laight wrote:
> >
> > Historically it has definitely done that.
> > And you can't 'cast away' the alignment implicit in a type.
> > The alignment can get tracked into an inlined function.
> > Plenty of crashes on sparc32 from that one.
> >
> > Any structure that might be misaligned in memory better be packed.
> >
> > But what is actually wrong with using byte access? eg:
> > u32 get_le32(u8 *p) { return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; }
> > On x86, arm64, ppc (etc) both gcc and clang generate a single memory read
> > (byteswapped if necessary).
> >
> > https://godbolt.org/z/d33hvesr8
>
> IIRC this is one of the versions we had in the past on some architectures,
> but the packed struct version ended up being better in some cases and
> never worse. It is possible that on new compilers are just as good with this
> version, and if someone can show that being true I think we can do
> that here as well.
I was only looking that is generated reasonable code on x86.
(Ok today, but I'm sure gcc didn't optimise it last time I looked, my
memory must be going.)
An alternative would be to use OPTIMIZER_HIDE_VAR() on the pointer with
a (partial) memory clobber and the packed struct version.
(You need the memory clobber after the write as well as before.)
That might add a register-register move (and so a spill).
David
>
> Arnd