Re: alignment errors on armel: what to do?
On 9/29/09, Daniel Kahn Gillmor <dkg@fifthhorseman.net> wrote:
> char f[4];
>
> void test(char* x, short z) {
> short* y = (short*)x;
> *y=z;
> }
>
> int main(int argc, const char* argv[]) {
> test(f,argc);
> return 0;
> }
>
> any idea why gcc would lay out the memory differently for armel than for
> i386? i haven't tried it on the old arm architecture.
Well, char arrays are char-aligned, so no surprise there! If you put
an "int i" before the "char f[]" you get char f[] word-aligned.
It turns out that something in the C startup needs a byte of data, so
your array comes after that at an odd address
$ nm a.out | sort
...
000105ac A __bss_start__
000105ac A _edata
000105ac b completed.5827
000105ad B f
000105b4 A __bss_end__
000105b4 A _bss_end__
...
Though quite what completed.5827 may be I have no idea!
M
Reply to: