From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22269 invoked by alias); 26 Jul 2005 05:04:32 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 22258 invoked by uid 22791); 26 Jul 2005 05:04:28 -0000 Received: from nondot.cs.uiuc.edu (HELO nondot.org) (128.174.245.159) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 26 Jul 2005 05:04:28 +0000 Received: by nondot.org (Postfix, from userid 501) id 867051037EF; Tue, 26 Jul 2005 00:04:41 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by nondot.org (Postfix) with ESMTP id 826641077C4; Tue, 26 Jul 2005 00:04:41 -0500 (CDT) Date: Tue, 26 Jul 2005 05:04:00 -0000 From: Chris Lattner To: corey taylor Cc: Ian Lance Taylor , gcc-help@gcc.gnu.org Subject: Re: attribute aligned(4) ignored In-Reply-To: <2e393d080507252202628525d5@mail.gmail.com> Message-ID: References: <2e393d080507252202628525d5@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-SW-Source: 2005-07/txt/msg00276.txt.bz2 On Tue, 26 Jul 2005, corey taylor wrote: > Does the placement of the aligned and packed structure member affect the result? > > What happens when the double D is at the end of the structure? The Darwin ABI specifies that doubles that are not the initial element already have 4-byte alignment. -Chris > On 7/25/05, Chris Lattner wrote: >> On Mon, 25 Jul 2005, Ian Lance Taylor wrote: >>> Chris Lattner writes: >>>> Hi All, I'm trying to reduce the alignment of the double in this >>>> structure to 4 bytes (from 8) on Darwin. The goal of doing this is to >>>> reduce the structure to 12 bytes in size. Here is my testcase: >>>> >>>> struct Test { >>>> double D __attribute__((aligned(4))); // only 4 bytes, not 8! >>>> int X; >>>> }; >>>> >>>> int X() { >>>> return sizeof(struct Test); // Should return 12, not 16. >>>> } >>>> >>>> Despite my attempt above, the structure is still 16 bytes in size, due >>>> to the tail padding required to pad the structure to ensure 8-byte >>>> alignment. >>>> >>>> Does anyone know how to reduce the alignment of the double, >>>> eliminating the tail padding? >>> >>> How about >>> >>> double D __attribute__((aligned(4), packed)); >> >> This is exactly the sort of thing I want to do. My structs can be >> arbitrarily complex, and can have a bunch of stuff in them that should not >> be packed. This means that I don't want to use attribute packed on the >> structure itself, but using it on the member would be fine. >> >> However, when I try this: >> >> struct Test { >> double D __attribute__((packed,aligned(4))); >> short X; >> }; >> >> ... the struct maintains its 8-byte alignment even though nothing inside >> of it requires 8-byte alignment any more. In this particular case, for >> example, I want the struct to be 12-bytes, not 10: just reducing the >> alignment requirement of the double, without eliminating all intra-struct >> padding. This is why I don't think I can use attribute packed on the >> struct itself. >> >> Unfortunately, I'm not sure if this is possible, at least without using >> 'packed' on the struct, then inserting a bunch of dummy members to >> explicitly insert the intra-field packing. I hope there is a better way >> though, as this is really nasty and fragile. >> >> Thanks, >> >> -Chris >> >> -- >> http://nondot.org/sabre/ >> http://llvm.org/ >> > -Chris -- http://nondot.org/sabre/ http://llvm.org/