Re: [PATCH v3 1/3] vdso: Switch get/put unaligned from packed struct to memcpy
From: David Laight
Date: Wed Jul 23 2025 - 18:14:18 EST
On Tue, 22 Jul 2025 10:00:51 -0700
Ian Rogers <irogers@xxxxxxxxxx> wrote:
...
> Oh, the actual warning is "leaves the object uninitialized". It is
> possible to silence this by changing:
>
> const U16 __get_unaligned_ctrl_type __always_unused;
>
> to something like:
>
> const U16 __get_unaligned_ctrl_type __always_unused = 0;
>
> You then get complained at that the code is using 0 instead of NULL
> when instead of U16 the type of the __get_unaligned_t is a pointer.
> Basically I've entered into an analysis tool wac-a-mole and I don't
> have a combination to make them all happy.
Can you embed the variable inside a struct and then initialise with {} ?
Does this code actually work all the time?
There have always been 'problems' because gcc remembers the alignment
of pointers through (void *) casts.
So if your misaligned pointer has a type that should be aligned
them memcpy(&dest, (void *)misaligned_int_ptr, 4) will still do an
aligned read.
You also really need the compiler to optimise the memcpy into two
memory reads, some shifts, masks and ors, and a single write to a
register.
I'm not at all sure that is going to happen.
(Especially since I've never seen it optimised to only two reads
even when reading 'packed' variables.
David
>
> Thanks,
> Ian
>