Re: Pointer typecasts may write to incorrect addresses on ARM?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Subramanyam Badri wrote:
Hi,
I am using a GCC compiler for ARM and see an alignment problem with pointer typecasting. We're porting code to ARM and found some writes to incorrect addresses. Can you help? For example: char * pChar = (char *)0x100000; /* hardcoded for example purposes */
pChar[0] = 0x0;
*(int *)&pChar[1] = 0x11223344;
/* We really want pChar[0] to equal 0x00, but it equals 0x44 on ARM!!!! */
printf ("pChar[0] = 0x%02x\n", pChar[0]);

My understanding is that non-aligned memory access is allowed on ARM, so it's not clear why typecasting and writing data adjusts the destination address.
Your understanding isn't the same as mine - I would expect the cpu to either trap on the unaligned access, or possibly just ignore the misalignment.

If you're *lucky* enough to be running under linux, you can echo 3 to /proc/cpu/alignment to enable the alignment fault handler. IIRC, its default is to do the wrong thing, leaving partial memory updates like you are seeing.

John

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux