On 5/7/10, Shaun Pinney <shaun.pin...@bil.konicaminolta.us> wrote: > Essentially, we have code which works fine on x86/PowerPC but fails on ARM > due > to differences in how misaligned accesses are handled. The failures occur in > multiple large modules developed outside of our team and we need to find a > solution. The best question to sum this up is, how can we use the compiler > to > arrive at a complete solution to quickly identify all code locations which > generate misaligned accesses and/or prevent the compiler from generating > misaligned accesses?
Dunno about the compiler, but if you use the Linux kernel you can fiddle with /proc/cpu/alignment. By default it's set to 0, which silently gives garbage results when unaligned accesses are made. echo 3 > /proc/cpu/alignment will fix those misalignments using a kernel trap to emulate "correct" behaviour (i.e. loading from bytes (char *)a to (char *)a + 3 in the case of an int). Alternatively, echo 5 > /proc/cpu/alignment will make an unaligned access cause a Bus Error, which usually kills the process and you can identify the offending code by running it under gdb. Eliminating the unaligned accesses is tedious work, but the result will run slightly faster than relying on fixups, as well as making it portable to any word-aligned system. M