tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Avoid maximum alignment in _RuneStatePriv



I propose the following patch to remove attribute setting maximum target
specific alignment:

http://netbsd.org/~kamil/patch-00252-avoid-maximum-alignment.txt

mbstate_t has 64-bit alignment, __attribute__ ((aligned)) sets 128-bit
alignment and this leads to a lot of reports of UBSan on NetBSD/amd64.

This is reproduced with GCC and Clang.

Undefined Behavior in
/usr/src/lib/libc/compat/../locale/multibyte.h:75:37, member access
within misaligned address 0x7f7ff6dbe498 for type 'const _RuneState'
(aka 'const union _RuneState') which requires 16 byte alignment
Undefined Behavior in
/usr/src/lib/libc/compat/../locale/multibyte.h:75:37, load of misaligned
address 0x7f7ff6dbe498 for type '_RuneLocale *const' (aka 'struct
_RuneLocale *const') which requires 16 byte alignment
Undefined Behavior in
/usr/src/lib/libc/compat/../locale/multibyte.h:109:24, member access
within misaligned address 0x7f7ff6dbe498 for type '_RuneState' (aka
'union _RuneState') which requires 16 byte alignment
Undefined Behavior in
/usr/src/lib/libc/compat/../locale/multibyte.h:109:24, store to
misaligned address 0x7f7ff6dbe498 for type '_RuneLocale *' (aka 'struct
_RuneLocale *') which requires 16 byte alignment
Undefined Behavior in
/usr/src/lib/libc/compat/../locale/multibyte.h:94:40, member access
within misaligned address 0x7f7ff6dbe498 for type '_RuneState' (aka
'union _RuneState') which requires 16 byte alignment

After local tests, this patch fixed the reports and I don't see any
regressions. Every application using locales is affected.

Attachment: signature.asc
Description: OpenPGP digital signature



Home | Main Index | Thread Index | Old Index