On Thu, 2025-12-18 at 19:17 -0500, Benjamin Marzinski wrote:
> On Wed, Dec 17, 2025 at 10:21:09PM +0100, Martin Wilck wrote:
> > The macro BITFIELD used a cast of a pointer to a different
> > anonymous struct
> > to (struct bitfield *). This violates strict aliasing rules,
> > because the
> > two structs aren't compatible types in the sense of the language
> > specification. With -O2, gcc 15.1 generates code that makes th
> > pgcmp()
> > function fail, because the compiler doesn't initialize bf->len aka
> > __storage_for__bf.len to 64.
> >
> > The problem will show through error messages like this:
> >
> > multipathd[1974208]: is_bit_set_in_bitfield: bitfield overflow: 1
> > >= 0
> >
> > Fix this by using a union
> >
> > Fixes: 9a2f173 ("libmpathutil: change STATIC_BITFIELD to BITFIELD")
> > Signed-off-by: Martin Wilck <[email protected]>
> > ---
> > libmpathutil/util.c | 8 ++++----
> > libmpathutil/util.h | 41 +++++++++++++++++++++++------------
> > ----
> > libmultipath/configure.c | 4 ++--
> > libmultipath/pgpolicies.c | 2 +-
> > tests/util.c | 10 +++++-----
> > 5 files changed, 36 insertions(+), 29 deletions(-)
> >
> > diff --git a/libmpathutil/util.c b/libmpathutil/util.c
> > index 37412c6..5e45750 100644
> > --- a/libmpathutil/util.c
> > +++ b/libmpathutil/util.c
> > */
> > +#define BITFIELD(name,
> > length) \
> > + union bitfield __storage_for__ ## name =
> > { \
> > + .__bits = { 0
> > }, \
> > + .__len =
> > (length), \
> > }; \
>
> It looks like this only allocates one bitfield_t, regardless of
> length.
> Am I missing something here?
Hm, yes. While this is kind of intentional, the code is confusing. The
whole BITFIELD thing is a mess. Given that it's only used in two lines,
I guess I might as well just remove it.
Martin