This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Network programming for eCos under linux
Grant Edwards wrote:
>
> On Wed, Aug 08, 2001 at 03:51:17PM +0200, Andrew Lunn wrote:
>
> > > I'm not sure this is a compiler bug - I would suspect the linux
> > > compiler can't access non-aligned memory either, but at a guess
> > > the kernel catches the exception and emulates it for you. If
> > > that is the case, it's best avoided as performance would suck.
> >
> > I don't remeber the exact details. The code was something like...
> >
> > static int
> > func(char * msg, char * name ; short rr_type) {
> >
> > char *ptr;
> > int len;
> >
> > strcpy(msg,name);
> > ptr = msg + strlen(name);
> >
> > *ptr++ = ((char *)&rr_type)[0];
> > *ptr++ = ((char *)&rr_type)[1];
> >
> > len = ptr - msg;
> >
> > return len;
> > }
>
> AFAICT, that should work on an ARM. If it doesn't, it is a
> compiler bug.
Agreed. It would be different if you were accessing a more strictly aligned
type through a less strictly aligned type, e.g. casting a char * to a short
* and dereferencing; as Grant says...
> > Maybe i don't have the casts correct.
>
> There are other casts that are not going to work on ARM
> architecture (accessing words on non-word boundaries, for
> example). That's not a compiler error, it's just another way
> to shoot yourself in the foot with C.
Although it's worth mentioning that not all architectures disallow
unaligned accesses which is why people think they can get away with it :).
> > Anyway, i found the ptr was not being incremented when ptr was
> > not word aligned before the first *ptr++ operation. This could
> > happen because name can be any length. It worked fine on i386,
> > but not on arm-elf. To me, this is a compile bug. I got around
> > it by using shifts and ands instead of casts and array access.
>
> Did you report the bug to the gcc guys? If it really is a bug,
> they'd love to hear about it.
Especially now that the release cycle for gcc 3.0.1 is drawing to a close.
Jifl
--
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine