Ignore:
Timestamp:
2023-10-22T15:53:32Z (7 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
71b4444, abb70fc3
Parents:
f4a42661
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-10-22 15:39:53)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-10-22 15:53:32)
Message:

Remove some inappropriate uses of attribute((packed))

attribute((packed)) means "ignore all alignment requirements
on members of this structure". This is useful if one needs to
map onto a structure in memory that has misaligned fields on purpose,
but those cases are extremely rare.

The side effect of the attribute is that taking a pointer to any
field longer than a single byte, and dereferencing that pointer,
is unsound and may crash the program on architectures that care
about memory alignment when reading/writing multibyte values.

Newer GCC versions can detect some of those unsafe cases and
produce a warning for it. This commit only removes those cases.

However, most, if not all, uses of ((packed)) in HelenOS
are unnecessary and a product of misunderstanding what the
attribute actually does. A common misconception is that it is
needed to avoid compiler adding arbitrary padding into the
structure, but that is simply not true. There is exactly one
correct memory layout for any C structure, because there must
be one layout for binary interoperability to exist and the one
everyone uses (except perhaps some goblin who just wants to break
things for fun) is the trivial best layout possible with given
constraints.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/include/ext4/types.h

    rf4a42661 r590cb6d2  
    141141        uint32_t encrypt_algos;             /* Encrypt algorithm in use */
    142142        uint32_t padding[105];              /* Padding to the end of the block */
    143 } __attribute__((packed)) ext4_superblock_t;
     143} ext4_superblock_t;
    144144
    145145#define EXT4_GOOD_OLD_REV 0
     
    335335                        uint32_t author;
    336336                } hurd2;
    337         } __attribute__((packed)) osd2;
     337        } osd2;
    338338
    339339        uint16_t extra_isize;
     
    345345        uint32_t crtime_extra;  /* Extra file creation time (nsec << 2 | epoch) */
    346346        uint32_t version_hi;    /* High 32 bits for 64-bit version */
    347 } __attribute__((packed)) ext4_inode_t;
     347} ext4_inode_t;
    348348
    349349#define EXT4_INODE_MODE_FIFO       0x1000
     
    418418                uint8_t name_length_high;  /* Higher 8 bits of name length */
    419419                uint8_t inode_type;        /* Type of referenced inode (in rev >= 0.5) */
    420         } __attribute__((packed));
     420        };
    421421
    422422        uint8_t name[EXT4_DIRECTORY_FILENAME_LEN];  /* Entry name */
    423 } __attribute__((packed)) ext4_directory_entry_ll_t;
     423} ext4_directory_entry_ll_t;
    424424
    425425typedef struct ext4_directory_iterator {
Note: See TracChangeset for help on using the changeset viewer.