Compiler Memory Alignment Issue
Yann E. MORIN
yann.morin.1998@free.fr
Fri Feb 3 13:21:00 GMT 2012
Richard, Bob, All,
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):
$ arm-none-linux-gnueabi-gcc -o ess ess.c
$ qemu-arm -L ..../arm-none-linux-gnueabi/sysroot ./ess
size of int is: 4
buffer[0]=ff
buffer[1]=ff
buffer[2]=ff
buffer[3]=ff
buffer[4]=34
buffer[5]=12
buffer[6]=0
buffer[7]=0
The assembly code corresponding to the assignment is (from gdb's disas /m):
14 *(ptr + 1) = 0x1234;
0x00008400 <+56>: ldr r3, [r11, #-16]
0x00008404 <+60>: add r2, r3, #4
0x00008408 <+64>: mov r3, #4608 ; 0x1200
0x0000840c <+68>: add r3, r3, #52 ; 0x34
0x00008410 <+72>: str r3, [r2]
As you can see for @0x8404, an offset of #4 is added to the address of the
array.
Regards,
Yann E. MORIN.
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +0/33 662376056 | Software Designer | \ / CAMPAIGN | ^ |
| --==< O_o >==-- '------------.-------: X AGAINST | /e\ There is no |
| http://ymorin.is-a-geek.org/ | (*_*) | / \ HTML MAIL | """ conspiracy. |
'------------------------------'-------'------------------'--------------------'
--
For unsubscribe information see http://sourceware.org/lists.html#faq
More information about the crossgcc
mailing list