Page MenuHomeFreeBSD

gcc9: quiet Waddress-of-packed-member for kernel build
ClosedPublic

Authored by rlibby on Dec 19 2019, 9:50 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Oct 23, 7:50 AM
Unknown Object (File)
Oct 5 2024, 10:46 AM
Unknown Object (File)
Oct 3 2024, 6:26 AM
Unknown Object (File)
Oct 2 2024, 9:23 AM
Unknown Object (File)
Oct 1 2024, 5:14 PM
Unknown Object (File)
Oct 1 2024, 2:08 PM
Unknown Object (File)
Sep 30 2024, 8:29 AM
Unknown Object (File)
Sep 30 2024, 8:19 AM
Subscribers

Details

Summary

This is lame, but it's what we already do for the clang build. We take
misaligned pointers into network header structures in many places.

Test Plan

make CROSS_TOOLCHAIN=amd64-gcc9 buildkernel

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Yeah, it kinda looks like gcc 9 is just catching up by adding a warning clang has had for a while.

This revision is now accepted and ready to land.Dec 19 2019, 5:44 PM

Maybe include share/mk/bsd.sys.mk at the same time as userland needs it as well (at least it did for me)?

In D22876#501221, @jhb wrote:

Maybe include share/mk/bsd.sys.mk at the same time as userland needs it as well (at least it did for me)?

Yes, I just ended up putting it in a different review, D22889, because I wasn't sure at first how widespread it would be.

head/sys/conf/kern.mk
75

This should have been no-error... we want the warnings, just don't want them to kill the build.

I can prepare a follow up. What I did here was exactly what we already do for clang. I will change both. And then I assume you'd have the same comment for the user build?

I can prepare a follow up. What I did here was exactly what we already do for clang. I will change both. And then I assume you'd have the same comment for the user build?

Before we do that, I guess I should ask how noisy that makes the build? If the clang warnings broke with usual practice then there might have been a reason.

I had followed what we did for clang as well in my local patches. I think it is an overly noisy warning. It basically warns if you ever take a pointer to any member that isn't assigned to a void * or a char * pointer (since it wants an alignment of 1). Often times we use packed for structures to fix a layout (e.g. structures mandated by hardware), but the structures themselves are aligned and the members have suitable alignment within the structure such that the warning is a false positive.

In D22876#501377, @jhb wrote:

I had followed what we did for clang as well in my local patches. I think it is an overly noisy warning. It basically warns if you ever take a pointer to any member that isn't assigned to a void * or a char * pointer (since it wants an alignment of 1). Often times we use packed for structures to fix a layout (e.g. structures mandated by hardware), but the structures themselves are aligned and the members have suitable alignment within the structure such that the warning is a false positive.

Sometimes I think we should tag the expected alignment. For x86 it doesn't matter, but for arm64 there may be a few that point out real bugs... we do need to be careful, though, because we don't want to pessimize accesses by getting the alignment wrong.

So that sounds like a good reason to depart for now....

Here's what changing it to no-error for the clang build does (amd64):

buildkernel KERNCONF=GENERIC:

vali% zgrep address-of-packed-member buildkernel-noerror.1.log.gz | wc -l                                               
     524
vali% zgrep address-of-packed-member buildkernel-noerror.1.log.gz | sed 's/.*: warning: //' | sort | uniq -c | sort -n | tail -n 5
  16 taking address of packed member 'ip_dst' of class or structure 'ip' may result in an unaligned pointer value [-Waddress-of-packed-member]
  17 taking address of packed member 'mld_addr' of class or structure 'mld_hdr' may result in an unaligned pointer value [-Waddress-of-packed-member]
  18 taking address of packed member 'ip_src' of class or structure 'ip' may result in an unaligned pointer value [-Waddress-of-packed-member]
 185 taking address of packed member 'ip6_dst' of class or structure 'ip6_hdr' may result in an unaligned pointer value [-Waddress-of-packed-member]
 186 taking address of packed member 'ip6_src' of class or structure 'ip6_hdr' may result in an unaligned pointer value [-Waddress-of-packed-member]

buildworld:

vali% zgrep address-of-packed-member buildworld-noerror.1.log.gz | wc -l                                                         
      59
vali% zgrep address-of-packed-member buildworld-noerror.1.log.gz | sed 's/.*: warning: //' | sort | uniq -c | sort -n 
   1 taking address of packed member 'rpu_prefix' of class or structure 'rr_pco_use' may result in an unaligned pointer value [-Waddress-of-packed-member]
   2 taking address of packed member 'rpm_prefix' of class or structure 'rr_pco_match' may result in an unaligned pointer value [-Waddress-of-packed-member]
   3 taking address of packed member 'nd_opt_pi_prefix' of class or structure 'nd_opt_prefix_info' may result in an unaligned pointer value [-Waddress-of-packed-member]
   3 taking address of packed member 'tss_ist1' of class or structure 'amd64tss' may result in an unaligned pointer value [-Waddress-of-packed-member]
   4 taking address of packed member 'ip6_src' of class or structure 'ip6_hdr' may result in an unaligned pointer value [-Waddress-of-packed-member]
   4 taking address of packed member 'ip_dst' of class or structure 'ip' may result in an unaligned pointer value [-Waddress-of-packed-member]
   5 taking address of packed member 'ip6_dst' of class or structure 'ip6_hdr' may result in an unaligned pointer value [-Waddress-of-packed-member]
  10 taking address of packed member 'ip_src' of class or structure 'ip' may result in an unaligned pointer value [-Waddress-of-packed-member]
  27 taking address of packed member 'status' of class or structure 'nvme_completion' may result in an unaligned pointer value [-Waddress-of-packed-member]

The kernel build would be pretty noisy. In the kernel, there are many places where we are reaching into an mbuf, and I think they really may not be aligned. The user build is maybe not "too" noisy.