Re: Architectures with strict alignment?
- From: Bernd Walter <ticso@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 31 Dec 2007 09:18:00 +0100
On Sun, Dec 30, 2007 at 11:18:08PM -0500, Mike Meyer wrote:
On Sun, 30 Dec 2007 20:37:18 +0100 Bernd Walter <ticso@xxxxxxxxxxxxxxxxxx> wrote:
On Sun, Dec 30, 2007 at 01:55:06PM -0500, Mike Meyer wrote:
Ok, I'm a bit confused. Since you're talking about moving code fromNot in every case.
the x86 to the alpha, I'm assuming you're talking about C code. Isn't
it the *compilers* job to enforce alignment issues, unless the
programmer specifically asks for byte-specific control of the layout
of a set of variables?
It is not unusual to read raw bytes from e.g. network and use
a struct pointer to it.
But in case of network data it may be missaligned and if the struct
contains anything else then bytes you may be doing missaligned accesses.
Actually, network data is the most common case where the programmer
has to ask for byte-specific control of the layout. As far as I know,
the proper way to do this is to declare the struct properly - with a
compiler-dependent request for packing - then read the data into
that. If you could be reading more than one type of struct into it,
then set up the appropriate unions for all of them. In either case,
the compiler should DTRT.
reading into a struct is one way.
The other way is pointing into a read buffer.
But it sounds like this people just read raw bytes, and then
disassembled them by hand, which I would say qualifies as "crappy
software."
It has it's reasons, but you have to be carefull if doing this and
that's what people fail with - or better said other people fail with
their software.
In the same class of bugs we now have problems with arm from time to
time, since arm pads single bytes to full 32bit aligment unless the
struct is declared as being packed.
Or are these the issue, and the problem is that people do that andNo - they just don't think about alignment when parsing data from random
then don't use the appropriate APIs to pull data from them, thus
causing you headaches?
source.
That seems to be common: if something doesn't matter on their
platform, programmers tend not to worry about it. I saw plenty of
evidence of that as Unix moved from 16 bit systems to 32 bit ones, and
again as it went to 64 bits (though not quite so bad).
Yes - only for the last few years with all those amd64 systems out
there those kind of problems are rare.
But unlike missalignment bugs the compiler catches many of them as
long as they are not reading random source data into structs...
--
B.Walter http://www.bwct.de http://www.fizon.de
bernd@xxxxxxx info@xxxxxxx support@xxxxxxxx
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"
- References:
- Architectures with strict alignment?
- From: Ivan Voras
- Re: Architectures with strict alignment?
- From: M. Warner Losh
- Re: Architectures with strict alignment?
- From: Wilko Bulte
- Re: Architectures with strict alignment?
- From: Dag-Erling Smørgrav
- Re: Architectures with strict alignment?
- From: Bernd Walter
- Re: Architectures with strict alignment?
- From: Mike Meyer
- Re: Architectures with strict alignment?
- From: Bernd Walter
- Re: Architectures with strict alignment?
- From: Mike Meyer
- Architectures with strict alignment?
- Prev by Date: Re: Architectures with strict alignment?
- Next by Date: Re: Architectures with strict alignment?
- Previous by thread: Re: Architectures with strict alignment?
- Next by thread: Re: Architectures with strict alignment?
- Index(es):
Relevant Pages
|