ARM compiler misbehaves ?
Svein-Erik Skjelbred
ixdp425@skjelbred.com
Wed Apr 28 22:03:00 GMT 2004
Hello
We are encontering something that we think is a compiler bug. Running on
a normal PC it works. We have taken everything out of normal code and
made the following sample code.
typedef struct
{
unsigned char test_char;
unsigned short test_short;
} __attribute__ ((__packed__)) test_struct;
int main(void)
{
test_struct test_var = {0x12, 0x3456};
unsigned short* test_pointer;
printf("test_var.test_char %x\n", test_var.test_char);
printf("test_var.test_short %x\n", test_var.test_short);
test_pointer = &test_var.test_short;
*test_pointer = 0x789A;
printf("test_var.test_char %x\n", test_var.test_char);
printf("test_var.test_short %x\n", test_var.test_short);
return 0;
}
ON A LINUX PC
$ gcc --version
gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc test.c
$ ./a.out
test_var.test_char 12
test_var.test_short 3456
test_var.test_char 12
test_var.test_short 789a
$ armv5b-linux-gcc --version
armv5b-linux-gcc (GCC) 3.3.3
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ armv5b-linux-gcc --static test.c
<Transfer to target>
# ./a.out
test_var.test_char 12
test_var.test_short 3456
test_var.test_char 78 -----------------> Short started 1 byte to early
test_var.test_short 9a56
#
We think that the compiler takes the odd address and maskes out the east
significant bit.
Svein-Erik Skjelbred
------
Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com
More information about the crossgcc
mailing list