Linux, politics, and other interesting things
I recently had some problems with unaligned access on IA64, messages about unaligned access were being logged via printk and I couldn’t determine the cause – or even how to track it down. To test what an unaligned access means (which wasn’t documented anywhere that a quick google search could find) I wrote the test program in the second half of this post. Below is the output of the test program which accesses an integer at various offsets. As you can see it’s addresses that are congruent to 5, 6, and 7 mod 8 that cause the errors. At the int is 4 bytes long it seems that the cause of an unaligned access error is an access to a data type that crosses an 8 byte boundary. So a pointer or long long would have to be aligned to an 8 byte boundary, an int has to be at an address that is congruent to 4 or less mod 8, and a character can be anywhere.
Also if the sysctl /proc/sys/kernel/ignore-unaligned-usertrap is set to 1 then these messages will be disabled. But you really don’t want to do that, such errors apparently cause a significant performance loss so you want to file bug reports against programs that do this.
a.out(10393): unaligned access to 0x607fffffff34ee25, ip=0x4000000000000961
a.out(10393): unaligned access to 0x607fffffff34ee26, ip=0x4000000000000961
a.out(10393): unaligned access to 0x607fffffff34ee27, ip=0x4000000000000961
a.out(10393): unaligned access to 0x607fffffff34ee2d, ip=0x4000000000000961
a.out(10393): unaligned access to 0x607fffffff34ee2e, ip=0x4000000000000961
a.out(10393): unaligned access to 0x607fffffff34ee2f, ip=0x4000000000000961
Below is the test program I used:
void doit(int *foo)
memcpy(&bar, foo, sizeof(bar));
if(*foo == 1234)
for(i=0; i<sizeof(buf); i++)
printf("index: %d\n", i);
Multipurpose Blog Theme By Buy WordPress Template