Re: alignment and packed structs
On Wed, 6 Jan 2021, Patrick Welche wrote: I just tried to compile if_iwn as a module. It failed with dev/pci/if_iwn.c:2685:6: error: converting a packed 'struct iwn_fw_dump' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Werror=address-of-packed-member] I got around it with ... Why isn't this necessary when building if_iwn.c as part of a kernel? This isn't an isolated case. I recently built some other (Intel DRM) code as modules and had to "fix " the code in 3 or 4 places for the whole kernel/module compilation to complete successfully. I figured it was a case of slightly different compiler flags being used for the monolithic vs. modular kernel builds. -RVP
alignment and packed structs
I just tried to compile if_iwn as a module. It failed with dev/pci/if_iwn.c:2685:6: error: converting a packed 'struct iwn_fw_dump' pointer (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may result in an unaligned pointer value [-Werror=address-of-packed-member] I got around it with diff -u -r1.17 if_iwnreg.h --- if_iwnreg.h 19 Jul 2017 16:55:12 - 1.17 +++ if_iwnreg.h 6 Jan 2021 17:24:01 - @@ -1447,7 +1447,7 @@ uint32_tsrc_line; uint32_ttsf; uint32_ttime[2]; -} __packed; +} __attribute__((aligned(4),packed)); /* TLV firmware header. */ struct iwn_fw_tlv_hdr { Why isn't this necessary when building if_iwn.c as part of a kernel? Is the above the right solution? Cheers, Patrick