Date: Sun, 12 Nov 2006 21:28:49 +0530 From: "Joseph Koshy" <joseph.koshy@gmail.com> To: "Giorgos Keramidas" <keramida@freebsd.org> Cc: arm@freebsd.org, current@freebsd.org Subject: Re: [head tinderbox] failure on arm/arm Message-ID: <84dead720611120758r4f1cc6e8l8ca4432ba56f3f7f@mail.gmail.com> In-Reply-To: <20061112151150.GA2988@kobe.laptop> References: <20061112142710.GE91556@wombat.fafoe.narf.at> <20061112133929.9194773068@freebsd-current.sentex.ca> <20061112140010.GA47660@rambler-co.ru> <20061112144230.GC2331@kobe.laptop> <20061112145151.GC49703@rambler-co.ru> <20061112151150.GA2988@kobe.laptop>
next in thread | previous in thread | raw e-mail | index | archive | help
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/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?84dead720611120758r4f1cc6e8l8ca4432ba56f3f7f>