[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <38114d1b752c497eba1640360daf5b9e@AcuMS.aculab.com>
Date: Tue, 27 Sep 2022 15:58:33 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'YingChi Long' <me@...lyc.cn>
CC: "bp@...en8.de" <bp@...en8.de>,
"chang.seok.bae@...el.com" <chang.seok.bae@...el.com>,
"dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>,
"hpa@...or.com" <hpa@...or.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"mingo@...hat.com" <mingo@...hat.com>,
"ndesaulniers@...gle.com" <ndesaulniers@...gle.com>,
"pbonzini@...hat.com" <pbonzini@...hat.com>,
"tglx@...utronix.de" <tglx@...utronix.de>,
"x86@...nel.org" <x86@...nel.org>
Subject: RE: [PATCH v2] x86/fpu: use _Alignof to avoid UB in TYPE_ALIGN
From: YingChi Long
> Sent: 27 September 2022 16:34
>
> WG14 N2350 made very clear that it is an UB having type definitions with
> in "offsetof". This patch change the implementation of macro
> "TYPE_ALIGN" to builtin "_Alignof" to avoid undefined behavior.
Interesting - what justification do they give?
Linux kernel requires that the compiler add no unnecessary padding
so that structure definitions are well defined.
IIRC that standard allows arbitrary padding between members.
So using a type definition inside offsetof() won't give a
useful value - but it still isn't really UB.
...
> #define CHECK_MEMBER_AT_END_OF(TYPE, MEMBER) \
> - BUILD_BUG_ON(sizeof(TYPE) != ALIGN(offsetofend(TYPE, MEMBER), \
> - TYPE_ALIGN(TYPE)))
> + BUILD_BUG_ON(sizeof(TYPE) != \
> + ALIGN(offsetofend(TYPE, MEMBER), _Alignof(TYPE)))
Has that ever worked?
Given:
struct foo {
int a;
char b;
char c;
};
I think CHECK_MEMBER_AT_END_OF_TYPE(struct foo, b) is true.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists