Re: [head tinderbox] failure on arm/arm

From: Joseph Koshy <joseph.koshy_at_gmail.com>
Date: Sun, 12 Nov 2006 21:28:49 +0530
ru> Still doesn't make much sense to me.  If all structure
ru> members are chars (like is the case with "struct ar_hdr"
ru> from <ar.h> which GCC complains about, and in my example,
ru> the required alignment shouldn't be more than sizeof(char).
ru> What am I missing?

gk> You are missing that inside bubu() the compiler
gk> 'believes' that:
gk>     * The `s' pointer is (char *)-aligned.
gk>     * The sizeof(struct foo) is >1.
gk>     * You are trying to assign `s' (with it's possibly
gk>       misaligned value) to the `return value' place,
gk>       whose type is (at least, as far as the compiler
gk>       knows) is (struct foo *).

gk> That may break alignment assumptions the compiler is making
gk> inside bubu(), especially about the `s' pointer, hence the
gk> warning.

The following program prints `1' on the AMD64, i386 and on
sparc64.

----- SNIP ----
#include <stdio.h>

struct foo {
        char x;
};

int
main(int c, char **v)
{
        printf("align=%d\n", __alignof__(struct foo));
}
---- SNIP ---

I don't have a way of running ARM binaries, but
disassembly of the binary shows:
00000000 <main>:
  ... snip ...
  20:   e59f0010        ldr     r0, [pc, #16]   ; 38 <.text+0x38>
  24:   e3a01004        mov     r1, #4  ; 0x4
  28:   ebfffffe        bl      28 <main+0x28>
  2c:   e1a00003        mov     r0, r3
  ... snip ...

If I am reading the assembly correctly, GCC thinks that
the alignment for struct foo is '4'. However, changing
the program print `__alignof__(foo.x)' results in a value
of `1' being loaded into R1.

And then `sizeof (struct foo)` appears to be 4 with GCC/arm
and 1 on the other architectures.

GCC/arm also thinks that the alignment requirement for
`char a[1]' is `4', even though `sizeof(char a[1])`
remains at 1.

This doesn't make sense at many levels.

--
FreeBSD Volunteer,     http://people.freebsd.org/~jkoshy/
Received on Sun Nov 12 2006 - 15:00:02 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:02 UTC