byteorder.h and strict aliasing
Andrew Bartlett
abartlet at samba.org
Thu Nov 14 19:22:09 MST 2013
On Thu, 2013-11-14 at 18:42 +0100, Andreas Schneider wrote:
> Hello,
>
> if you compile Samba with optimization on i686 you get 342 warnings like this:
>
> lib/util/genrand.c:294:2: warning: dereferencing type-punned pointer will
> break strict-aliasing rules [-Wstrict-aliasing]
>
> These warnings normally mean that the compiler can't optimize the code. For
> the long answer read [1].
>
> The reason is that we have a define CAREFUL_ALIGNMENT in byteorder.h. There is
> a comment which states:
>
> --------------
> The distinction between 386 and other architectures is only there as
> an optimisation. You can take it out completely and it will make no
> difference. The routines (macros) in byteorder.h are totally byteorder
> independent. The 386 optimsation just takes advantage of the fact that
> the x86 processors don't care about alignment, so we don't have to
> align ints on int boundaries etc. If there are other processors out
> there that aren't alignment sensitive then you could also define
> CAREFUL_ALIGNMENT=0 on those processors as well.
> --------------
>
> Well, to show that this is not an optimization but breaks the compiler
> optimization I wrote a test with it:
Very nice work! It's always great to challenge the old assumptions.
Andrew Bartlett
--
Andrew Bartlett
http://samba.org/~abartlet/
Authentication Developer, Samba Team http://samba.org
Samba Developer, Catalyst IT http://catalyst.net.nz
More information about the samba-technical
mailing list