https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84108

--- Comment #3 from Arnd Bergmann <arnd at linaro dot org> ---
(In reply to Jakub Jelinek from comment #1)
> I vaguely remember the behavior of packed + aligned(N) kept changing in the
> past, some versions of GCC treated it just like packed, others as aligned.
> Is this in the kernel?

Yes. The example I showed corresponds to include/linux/sysv_fs.h, which
probably has very few users, if any. If this was inconsistent in the past, it
may have gone unnoticed. OTOH, there is a compile-time assertion in the code to
ensure that the structure has the right size:

#define __packed2__     __attribute__((packed,aligned(2)))
#define XENIX_NICINOD   100     /* number of inode cache entries */
#define XENIX_NICFREE   100     /* number of free block list chunk entries */
struct xenix_super_block {
        __fs16          s_isize; /* index of first data zone */
        __fs32          s_fsize __packed2__; /* total number of zones of this
fs */
        /* the start of the free block list: */
        __fs16          s_nfree;        /* number of free blocks in s_free, <=
XENIX_NICFREE */
        sysv_zone_t     s_free[XENIX_NICFREE]; /* first free block list chunk
*/
        /* the cache of free inodes: */
        __fs16          s_ninode; /* number of free inodes in s_inode, <=
XENIX_NICINOD */
        sysv_ino_t      s_inode[XENIX_NICINOD]; /* some free inodes */
        /* locks, not used by Linux: */
        char            s_flock;        /* lock during free block list
manipulation */
        char            s_ilock;        /* lock during inode cache manipulation
*/
        char            s_fmod;         /* super-block modified flag */
        char            s_ronly;        /* flag whether fs is mounted read-only
*/
        __fs32          s_time __packed2__; /* time of last super block update
*/
        __fs32          s_tfree __packed2__; /* total number of free zones */
        __fs16          s_tinode;       /* total number of free inodes */
        __fs16          s_dinfo[4];     /* device information ?? */
        char            s_fname[6];     /* file system volume name */
        char            s_fpack[6];     /* file system pack name */
        char            s_clean;        /* set to 0x46 when filesystem is
properly unmounted */
        char            s_fill[371];
        s32             s_magic;        /* version of file system */
        __fs32          s_type;         /* type of file system: 1 for 512 byte
blocks
                                                                2 for 1024 byte
blocks
                                                                3 for 2048 byte
blocks */

};
BUILD_BUG_ON(1024 != sizeof (struct xenix_super_block));

Two other variations of this warning that I ran into are slightly different:
fs/ubifs/ubifs-media.h and include/scsi/libsas.h define a structure with
__attribute__((packed)) and use that structure as a member in another
structure, with that member being marked __attribute__((aligned)). I would hope
that this behavior has never changed.

Reply via email to