Compiler Memory Alignment Issue

Johannes Stezenbach js@sig21.net
Fri Feb 3 14:14:00 GMT 2012


Hi Yann,

On Fri, Feb 03, 2012 at 02:21:23PM +0100, Yann E. MORIN wrote:
> On Friday 03 February 2012 11:16:27 Bob Dunlop wrote:
> > On Thu, Feb 02 at 01:15, Richard Koch wrote:
> > > I'm seeing an alignment issue when I'm incrementing a pointer.
> 
> I Just tried your .config and your sample C code, and it seems to work here
> (with the buffer overflow fixed):

As Martin Guy pointed out the issue may be caused
by wrong alignment.  In fact the behaviour of the code
is undefined according to C99 if buffer is not suitably aligned:
https://www.securecoding.cert.org/confluence/display/seccode/EXP36-C.+Do+not+convert+pointers+into+more+strictly+aligned+pointer+types

I'd suggest to add a printf for the buffer address.

For ARM, unaligned access is supported for ARMv6+, in ARMv5
unaligned write is UNPREDICTABLE (unaligned read is
defined as rotated read from aligned address).
Not sure what's the default CPU for qemu-arm but
Richard has ARMv5.  I know Linux on ARM926EJ-S can
fix it up in sw like Martin described, but I'm not
sure every ARMv5 CPU supports alignment trap.


Johannes

--
For unsubscribe information see http://sourceware.org/lists.html#faq



More information about the crossgcc mailing list