Porting issue .
i have an issue here. i have been stuck with this problem
for quite sometime now. The following code runs smoothly on Linux , when
run on my PC ( intel x86 ). But, when i run it after cross compiling it
for ARM processor, it seg faults. After doing some trails , i'am of the
1) the program causes a segmentation fault only if it writes [ *blkPtr
= ((char*) blkPtr + 8) ] to an address which is not divisible by four,
and hence when i try to retrieve the value from such a location ( blkPtr
= *blkPtr) i get the swapped values ( i.e if *blkPtr was 0x11223344, i
would get it as 0x44112233
in blkPtr ).
And the next time thru the loop , *blkPtr would obviously point to some
memory location much outside the allocated (malloc'ed) range, and thus
the program seg faults,when it tries to de-reference that address.
Now, in my program i would want to write to locations which are not divisible
by 4 and still want the program to work properly. i have tried some compiler
options too, but of no use.
Could someone bail me out of this ?
The following code works fine on my PC running Linux kernel version 2.4,
gcc - 2.96.
arm-linux-gcc test.c to cross compile it for ARM. And arm-linux-gcc is
built by someone else.
Buffer = (char *) malloc(10000); // i get an address divisible by
4 consistently , i.e (Buffer % 4 ) is always 0.
// Buffer++; if i leave this uncommented and run it on ARM,
blkPtr = (void **)Buffer;
*blkPtr =(void *) ((char *) blkPtr + 8);
printf("<1> *blkPtr = %X \n",*blkPtr);
blkPtr = (void **) *blkPtr;
printf("<2> blkPtr = %X \n",blkPtr);
PS: This code runs smoothly on an ARM if i make sure i write to word boundaries
. i.e if i comment out Buffer++.
Hope its a known problem and someone helps
And the ARM iam running it on is configured as Little-Endian.