From owner-freebsd-alpha@FreeBSD.ORG Sun Mar 14 23:32:35 2004 Return-Path: Delivered-To: freebsd-alpha@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AEC8916A4CE; Sun, 14 Mar 2004 23:32:35 -0800 (PST) Received: from srv1.cosmo-project.de (srv1.cosmo-project.de [213.83.6.106]) by mx1.FreeBSD.org (Postfix) with ESMTP id F323443D41; Sun, 14 Mar 2004 23:32:34 -0800 (PST) (envelope-from ticso@cicely12.cicely.de) Received: from cicely5.cicely.de (cicely5.cicely.de [IPv6:3ffe:400:8d0:301:200:92ff:fe9b:20e7]) (authenticated bits=0) i2F7ToUS085097 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Mon, 15 Mar 2004 08:29:56 +0100 (CET) (envelope-from ticso@cicely12.cicely.de) Received: from cicely12.cicely.de (cicely12.cicely.de [IPv6:3ffe:400:8d0:301::12]) by cicely5.cicely.de (8.12.10/8.12.10) with ESMTP id i2F7Snhn059539 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 15 Mar 2004 08:28:50 +0100 (CET) (envelope-from ticso@cicely12.cicely.de) Received: from cicely12.cicely.de (localhost [127.0.0.1]) by cicely12.cicely.de (8.12.10/8.12.10) with ESMTP id i2F7Snc5072133; Mon, 15 Mar 2004 08:28:49 +0100 (CET) (envelope-from ticso@cicely12.cicely.de) Received: (from ticso@localhost) by cicely12.cicely.de (8.12.10/8.12.10/Submit) id i2F7SnHq072132; Mon, 15 Mar 2004 08:28:49 +0100 (CET) (envelope-from ticso) Date: Mon, 15 Mar 2004 08:28:49 +0100 From: Bernd Walter To: Alexander Nedotsukov Message-ID: <20040315072848.GW55325@cicely12.cicely.de> References: <405554D9.4000208@FreeBSD.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <405554D9.4000208@FreeBSD.org> X-Operating-System: FreeBSD cicely12.cicely.de 5.2-CURRENT alpha User-Agent: Mutt/1.5.6i X-Spam-Status: No, hits=-4.9 required=3.0 tests=BAYES_00 autolearn=ham version=2.63 X-Spam-Report: * -4.9 BAYES_00 BODY: Bayesian spam probability is 0 to 1% * [score: 0.0000] X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on cicely12.cicely.de cc: alpha@freebsd.org Subject: Re: Is the way static data alligned correct? X-BeenThere: freebsd-alpha@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: ticso@cicely.de List-Id: Porting FreeBSD to the Alpha List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Mar 2004 07:32:35 -0000 On Mon, Mar 15, 2004 at 04:01:45PM +0900, Alexander Nedotsukov wrote: > Guys, > > Recently doing some development I hit alignment problem on alpha > machines. Problem solved but the way I did it in fact the reason why I > asking pros to judge who is wrong here. > Inside code I have linked-in data blocks generated by external tool. > They looks like this: > const unsigned char raw_data_block[] = { bla-bla-bla }; > Internal block content is 8 bytes aligned. Each block resides in a > single .c file. So after compilation I have a set of .o files linked > later into single shared object (library). Taking an address of such > data block and casting it to pointer to some real structure was a > problem because it is not necesary 8 byte aligned. Obvious solution was > to ask explicitly for such alignment: > const unsigned char raw_data_block[] __attribute__ ((alligned(8))) = > { bla-bla-bla }; > But I wonder is this gcc bug or space optimization for char arrays only? You request an array of bytes and you get the natural alignment of bytes - why should the compiler waste bytes that are not required for the variable you define? A portable way would be to define it as a union with an int64_t. But the real point is that you shouldn't access any variable with stricter alignment than they are. If you have const data as in your example then define it as the correct structure. If it's not constant data then bcopy it into your structure or directly read it in a malloc'ed buffer. -- B.Walter BWCT http://www.bwct.de ticso@bwct.de info@bwct.de