Linux and aliasing?

David S. Miller davem@redhat.com
Wed Jun 30 15:43:00 GMT 1999


   Date: Sun, 6 Jun 1999 15:07:18 -0700 (PDT)
   From: Ross Harvey <ross@ghs.com>

   Umm, the ice is getting thin, here. From time to time, I have to change
   kernel code FROM things like ``a = ntohl((u32 *) p);'' TO things like
   ``memcpy (&a, p, sizeof a);  a = ntohl (a);''.

   Why? Because it's illegal for a reason, and the alpha platform I support
   has alignment requirements for which I have a guarantee that the memcpy
   approach will work and be reasonably efficient. The cast can generate a
   kernel alignment fault and will either panic or have a hideous run-time
   fixup cost.

This assumes you haven't setup your packet input processing to make
the data end up aligned by the time the header parsing gets at it.

The cast references work just fine and incur no traps on Alpha in the
Linux networking, so I have no idea what you are talking about.

Later,
David S. Miller
davem@redhat.com



More information about the Gcc mailing list