[collectd] [PATCH] Fix gcc-4.4 strict-aliasing issue

Alan Pevec apevec at gmail.com
Wed Mar 11 00:50:19 CET 2009


On Fri, Mar 6, 2009 at 7:21 PM, Florian Forster <octo at verplant.org> wrote:
> I have doubts about using the unions in that way though because I don't
> quite see the advantage. I suspect `-fstrict-aliasing' will work when
> using GCC on this file. Does the rest of collectd compile with
> `-fstrict-aliasing'? I'd be surprised, to be honest, because I'm sure we
> use similar casts in other places. Is that optimization turned on by

indeed, taking a closer look, in Fedora11 build log
http://kojipkgs.fedoraproject.org/packages/collectd/4.5.3/2.fc11/data/logs/x86_64/build.log
there are similar warnings for libiptc/libip*tc.c and ntpd.c which I
missed before:

 libiptc.c:390: warning: dereferencing type-punned pointer will break
strict-aliasing rules
...
 ntpd.c:903: warning: dereferencing pointer 'sa_ptr' does break
strict-aliasing rules
...

It's just that in src/liboping/Makefile -Werror survived, in Fedora
.spec there's sed -i.orig -e 's|-Werror||g' Makefile.in */Makefile.in
We could either add */*/Makefile.in or, better, fix all warnings and
remove that sed workaround :)
There are few other warnings

> default when using GCC 4.4?

Yes, this showed up during Fedora rawhide mass-rebuild with gcc-4.4
see https://www.redhat.com/archives/fedora-devel-list/2009-February/msg00180.html
It doesn't show up in F10 with older gcc, cf
http://kojipkgs.fedoraproject.org/packages/collectd/4.5.3/1.fc10/data/logs/x86_64/build.log

I found the union approach in a libvirt patch:
http://git.et.redhat.com/?p=libvirt.git;a=commitdiff;h=07a0ff22d5869794e6d721a1706aa9dd46760858;hp=05dc4c6062d07a34678133d5dc68280d500db10d

Union is still cleaner than direct pointer casting, imho, and could
help compiler optimizations,
see http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html



More information about the collectd mailing list