This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
problem with unaligned access on Alpha
- To: egcs at egcs dot cygnus dot com,axp-list at redhat dot com
- Subject: problem with unaligned access on Alpha
- From: "Christian Groessler" <cpg at aladdin dot de>
- Date: Tue, 22 Jun 1999 11:59:46 +0100
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