From owner-freebsd-arm@FreeBSD.ORG Sun Nov 12 16:00:09 2006 Return-Path: X-Original-To: arm@freebsd.org Delivered-To: freebsd-arm@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id ED8FD16A403 for ; Sun, 12 Nov 2006 16:00:09 +0000 (UTC) (envelope-from joseph.koshy@gmail.com) Received: from nz-out-0102.google.com (nz-out-0102.google.com [64.233.162.202]) by mx1.FreeBSD.org (Postfix) with ESMTP id 52D4543D45 for ; Sun, 12 Nov 2006 15:58:55 +0000 (GMT) (envelope-from joseph.koshy@gmail.com) Received: by nz-out-0102.google.com with SMTP id i11so577900nzh for ; Sun, 12 Nov 2006 07:58:50 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=hrMMllOgmJrcLHJJhQbDsiUgL2Ea2K7LnqBp3tFRB5anCPsYj1K8VbfILccj78Cgha9/o+EvsyjnW54z/0vqQpW9v7Ryak1WlkV6FvtZYLowKO8TUqIRQIqVTeEXdNWOGIwaxg1LPTcasxkGBUdzuD6Geev17g1VrpIqQ8FldEg= Received: by 10.64.199.2 with SMTP id w2mr6271488qbf.1163347129719; Sun, 12 Nov 2006 07:58:49 -0800 (PST) Received: by 10.64.204.15 with HTTP; Sun, 12 Nov 2006 07:58:49 -0800 (PST) Message-ID: <84dead720611120758r4f1cc6e8l8ca4432ba56f3f7f@mail.gmail.com> Date: Sun, 12 Nov 2006 21:28:49 +0530 From: "Joseph Koshy" To: "Giorgos Keramidas" In-Reply-To: <20061112151150.GA2988@kobe.laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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> Cc: arm@freebsd.org, current@freebsd.org Subject: Re: [head tinderbox] failure on arm/arm X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the StrongARM Processor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Nov 2006 16:00:10 -0000 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 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 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
: ... snip ... 20: e59f0010 ldr r0, [pc, #16] ; 38 <.text+0x38> 24: e3a01004 mov r1, #4 ; 0x4 28: ebfffffe bl 28 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/