This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

problem with unaligned access on Alpha





Hello,

while fixing a (intel-) program to work on Alpha, I've encountered
something,
I think it's a compiler bug.

Consider the following example program:

-----------------------
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>

#define READ_WORD(a)          (*(unsigned short *)(a))

int main(void)
{
  char * sepp,* xadr;
  int fd;
  int i;
  unsigned short val;

  fd=open("/dev/zero",O_RDWR);
  if (fd == -1) {
  xxx:
    fprintf(stderr,"cannot open : %s\n",strerror(errno));
    return(99);
  }
  sepp = mmap(0,0x10000,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0);
  if (sepp == -1) goto xxx;
  printf("mapped at address %p\n",sepp);

  xadr = sepp + 0x7bf;
  for (i=0; i< 0x7d0; i++) *(sepp + i) = 0xcc;

  printf("OK, now accessing %p....\n",xadr);
  val = READ_WORD(xadr);

  printf("val read = %04x\n",val);
  return(1);
}
-----------------------

I would expect the "val=READ_WORD()" line to generate an unaligned access
exception,
but this doesn't happen. Instead, only one _byte_ at address xadr is read,
resulting
in val=0xcc. Val is 0xcccc on intel machines.

I looked at the generated assembler code (with my little only alpha
assembler knowledge),
and it seems that the compiler is generating code for unaligned access but
somehow
forgets to get the byte at (adress+1).

This was reproduced on RH Linux 5.2 with egcs-1.0.3 and NetBSD 1.4C with
egcs-1.1.2.

Any comments?

regards,
chris



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]