Re: [RFC v2 2/3] atomic: Specify alignment for atomic_t and atomic64_t

From: Arnd Bergmann

Date: Mon Sep 22 2025 - 11:22:07 EST


On Mon, Sep 22, 2025, at 10:16, Finn Thain wrote:
>
> Yes, I noticed that also, after I started building with defconfigs.
> I pushed a new patch to my github repo.
>
> https://github.com/fthain/linux/tree/atomic_t

I had a look at that repository, and I think the extra
annotations you added on a lot of structures have the
same mistake that I made when looking at annotating
ABI structures for -malign-int earlier:

Adding __aligned__((sizeof(long))) to a structure definition
only changes the /outer/ alignment of the structure itself,
so e.g.

struct {
short a;
int b;
} __attribute__((aligned(sizeof(long))));

creates a structure with 4-byte alignment and 8-byte
size when building with -mno-align-int, but the padding
is added after 'b', which is still misaligned.

In order to align members the same way that -malign-int does,
each unaligned member needs a separate attribute to force
aligning it, like

struct {
short a;
int b __attribute__((aligned(sizeof(int))));
};

This is different from how __attribute__((packed)) works,
as that is always applied to each member of the struct
if you add it to the end.

Arnd