Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Dec 2007 23:18:08 -0500
From:      Mike Meyer <mwm-keyword-freebsdhackers2.e313df@mired.org>
To:        freebsd-hackers@freebsd.org
Cc:        ticso@cicely.de
Subject:   Re: Architectures with strict alignment?
Message-ID:  <20071230231808.4eaa93d5@bhuda.mired.org>
In-Reply-To: <20071230193718.GH31522@cicely12.cicely.de>
References:  <fl4c8o$vpu$1@ger.gmane.org> <20071229.122221.-432830441.imp@bsdimp.com> <20071229193034.GA73845@freebie.xs4all.nl> <86prwp161k.fsf@ds4.des.no> <20071230093432.GF31522@cicely12.cicely.de> <20071230135506.47beac58@bhuda.mired.org> <20071230193718.GH31522@cicely12.cicely.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 30 Dec 2007 20:37:18 +0100 Bernd Walter <ticso@cicely12.cicely.de> =
wrote:
> On Sun, Dec 30, 2007 at 01:55:06PM -0500, Mike Meyer wrote:
> > On Sun, 30 Dec 2007 10:34:33 +0100 Bernd Walter <ticso@cicely12.cicely.=
de> wrote:
> > > On Sat, Dec 29, 2007 at 11:37:27PM +0100, Dag-Erling Sm=C3=B8rgrav wr=
ote:
> > > > Wilko Bulte <wb@freebie.xs4all.nl> writes:
> > > > > In the past the alpha port had it too.
> > > >=20
> > > > No, it was optional and defaulted to off.
> > >=20
> > > It was never optional, since no alpha CPU can do missaligned access
> > > Alphas can fix missaligned access by software trap handlers in the sa=
me
> > > way as most other strong alignment architectures can and we did this
> > > for userland, but not in kernel.
> >=20
> > > Nevertheless it is horribly slow to do this, but was required since
> > > there was so many crappy software that days - fortunately this has
> > > changed over time, although I still see aligment traps on new software
> > > as well.
> > > Sadly said we never implemented missaligment traps for x86 so
> > [...]
> >=20
> > Ok, I'm a bit confused. Since you're talking about moving code from
> > 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?
> Not in every case.
> 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.

But it sounds like this people just read raw bytes, and then
disassembled them by hand, which I would say qualifies as "crappy
software."

> > Or are these the issue, and the problem is that people do that and
> > then don't use the appropriate APIs to pull data from them, thus
> > causing you headaches?
> No - they just don't think about alignment when parsing data from random
> 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).

      Thanks,
      <mike
--=20
Mike Meyer <mwm@mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071230231808.4eaa93d5>