Bug 1142456 - gcc9 gives false positive about unaligned packed member address
gcc9 gives false positive about unaligned packed member address
Status: RESOLVED INVALID
Classification: openSUSE
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Development
Current
Other Other
: P5 - None : Normal (vote)
: ---
Assigned To: Michael Matz
E-mail List
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2019-07-23 07:48 UTC by Michal Suchanek
Modified: 2019-07-23 09:14 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michal Suchanek 2019-07-23 07:48:46 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.
Comment 1 Richard Biener 2019-07-23 07:58:24 UTC
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.
Comment 2 Michal Suchanek 2019-07-23 09:14:32 UTC
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.