ARM compiler misbehaves ?

Grant Edwards grante@visi.com
Thu Apr 29 01:14:00 GMT 2004


On Thu, Apr 29, 2004 at 12:04:15AM +0200, Svein-Erik Skjelbred wrote:

> We are encontering something that we think is a compiler bug.

No, it's a bug in your code.

> Running on a normal PC it works.

That's on an IA32.  It has different aligment requirements than
ARM.


> typedef struct
> {
> 	unsigned char test_char;
> 	unsigned short test_short;
> }  __attribute__ ((__packed__)) test_struct;

Warning: test_short is misaligned.  It almost certainly is on
an odd byte boundary.  Accessing it directly  like this:

test_struct.test_short = 0x1234;
printf("%04x\n", test_struct.test_short);

_may_ work.  I don't think it's guaranteed to work, though.

> 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 now points to an odd address. Dereferencing it
will almost certainly not work right, since the compiler
doesn't generate run-time checks for misaligned pointers.

> 	*test_pointer = 0x789A;

Doing a 16-bit access to an odd address is undefined on ARM.

>         printf("test_var.test_char %x\n", test_var.test_char);
>         printf("test_var.test_short %x\n", test_var.test_short);
> 
> 	return 0;
> }

> We think that the compiler takes the odd address and maskes
> out the east significant bit.

You think wrong.  You've generated 16-bit accesses to odd
addresses, and that doesn't work on the ARM architecture.

Don't do it.

-- 
Grant Edwards
grante@visi.com

------
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