[SLOF] [PATCH] libnet: Fix compiler warnings with GCC 9

Segher Boessenkool segher at kernel.crashing.org
Mon Sep 23 21:38:21 AEST 2019


On Mon, Sep 23, 2019 at 09:29:24AM +0200, Thomas Huth wrote:
> No. "packed" guarantees that there is no *padding* between the struct
> members,

(Except between bitfield and non-bitfield members).

> but it does not make any guarantees about *alignments*.

Actually, it does: it is what it does directly, everything *else* is a
side-effect:

'packed'
     The 'packed' attribute specifies that a structure member should
     have the smallest possible alignment--one bit for a bit-field and
     one byte otherwise, unless a larger value is specified with the
     'aligned' attribute.  The attribute does not apply to non-member
     objects.

> Yeah, code like that also forced us to compile with -fno-strict-aliasing
> in the past already, IIRC.

/me makes signs warding off evil :-/

(If you need this option, you ignored too many compiler warnings).

> >>> Or disable this particular warning. What exactly
> >>> does it protect against?
> >> If I've googled it right, assigning an unaligned pointer value is
> >> undefined behavior according to the C standard. So the compiler could do
> >> weird stuff if we simply ignore it.
> > 
> > Huh. Well. There we go - no taking references of struct members.

Taking the address of one is fine.  Converting it to a pointer to another
object type is not.  Pointer to char (or void) is fine.


Segher


More information about the SLOF mailing list