This is the mail archive of the crossgcc@sourceware.org mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Compiler Memory Alignment Issue


Hello List,

I'm seeing an alignment issue when I'm incrementing a pointer.

Using the program below I found that the cross compiler I built from
crosstools-ng-1.13.3, interprets the "*(ptr + 1)" as adding 1 BYTE to ptr. It should
know that ptr is declared as a pointer to an integer and interpret "*(ptr + 1)"
as adding 4 BYTES to ptr.

An older cross compiler from Technologics, crosstool-linux-gnueabi-2005q3-2, doesn't
exhibit this problem and interprets the pointer addition correctly. So does the
native gcc on the target. I would prefer to use crosstools-ng.

The target is a Technologics TS-7350 ARM920T (EP9302).

I'm wondering if there may be something I haven't set properly in the crosstool-ng's
configuration?

The configuration file I'm using can be seen here:

??? http://home.comcast.net/~n1gp/ct_config

PROGRAM:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main()
{
??????? unsigned char buffer[8], i;
??????? int *ptr = (int *) buffer;

??????? printf("size of int is: %d\n", sizeof(int));
??????? memset(buffer, 0xff, sizeof buffer);

??????? *(ptr + 1) = 0x1234;

??????? for (i=0; i<(sizeof(buffer) +1); i++)
??????????????? printf("buffer[%d]=%x\n", i, buffer[i]);
}


RESULTS WITH crosstool-linux-gnueabi-2005q3-2:

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
buffer[8]=0

RESULTS WITH crosstools-ng:

size of int is: 4
buffer[0]=ff
buffer[1]=34
buffer[2]=12
buffer[3]=0
buffer[4]=0
buffer[5]=ff
buffer[6]=ff
buffer[7]=ff
buffer[8]=8

Thanks,

Rick


 		 	   		  

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]