Bugzilla – Bug 1142456
gcc9 gives false positive about unaligned packed member address
Last modified: 2019-07-23 09:14:32 UTC
https://build.opensuse.org/package/live_build_log/home:michals/skiboot.Leap/openSUSE_Factory_PowerPC/ppc64le [ 52s] hw/fsp/fsp-elog-write.c: In function 'opal_elog_read': [ 52s] hw/fsp/fsp-elog-write.c:213:12: error: taking address of packed member of 'struct errorlog' may result in an unaligned pointer value [-Werror=address-of-packed-member] [ 52s] 213 | list_del(&log_data->link); [ 52s] | ^~~~~~~~~~~~~~~ [ 52s] hw/fsp/fsp-elog-write.c:214:43: error: taking address of packed member of 'struct errorlog' may result in an unaligned pointer value [-Werror=address-of-packed-member] [ 52s] 214 | list_add(&elog_write_to_host_processed, &log_data->link); [ 52s] | ^~~~~~~~~~~~~~~ Looks aligned to me.
Please attach preprocessed source. Note the usual issue is that the formal parameter of list_add has type T * and thus expects to point to a naturally aligned T but the member in *log_data isn't aligned naturally. Note that on some targets alignment within a structure is less than standalone, for example powerpc64 big-endian (not sure about LE) aligns a double inside a struct to 4 bytes but natural alignment of double is 8 bytes.
The problem is probably that packed struct has natural alignment of 1 ( or < 8 at least) and while the members are naturally aligned WRT struct start there is no guarantee struct start is aligned. Adding alignment to the whole struct resolves the issue.