From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20295 invoked by alias); 7 Nov 2010 22:42:13 -0000 Received: (qmail 20282 invoked by uid 22791); 7 Nov 2010 22:42:11 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_DD,TW_OV X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 07 Nov 2010 22:42:06 +0000 From: "pageexec at freemail dot hu" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/46354] New: attribute((aligned(...))) can incorrectly decrease structure field alignment X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pageexec at freemail dot hu X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Sun, 07 Nov 2010 22:42:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-11/txt/msg00853.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46354 Summary: attribute((aligned(...))) can incorrectly decrease structure field alignment Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: pageexec@freemail.hu while investigating a clang error when compiling the linux kernel i narrowed the problem down to what seems to be a gcc bug. what happens is that despite what the gcc documentation says about the aligned attribute, gcc does decrease structure field alignment even when the packed attribute is not specified. the attached example shows that the issue is only with the attribute attached to a typedef. the relevant part of the generated asm looks like this for gcc: movq xx+8(%rip), %rax addq x+4(%rip), %rax <==== bug, should be +8 addq p+2(%rip), %rax <==== should it be +4? addq pp+4(%rip), %rax and for clang: movq xx+8(%rip), %rax addq x+8(%rip), %rax addq p+2(%rip), %rax addq pp+4(%rip), %rax the tested gcc versions so far: gcc version 4.4.5 (Gentoo 4.4.5 p1.0, pie-0.4.5) gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC) note that fixing this bug will have a non-trivial effect on linux as this construct is relied upon throughout the compat layer (that implements transforming syscall parameters between 32 bit userland and the 64 bit kernel) so when gcc stops decreasing the natural alignment of these structure fields, all such code will have to be changed to explicitly use the packed attribute lest the kernel/userland syscall ABI break... only to run into the next issue in that the packed attribute on the structure ignores the aligned attribute in the typedef (see the +2 above), both in gcc and clang (given both compilers are affected, i'm not sure if this is a bug or feature). more interestingly, if the aligned attribute is on the structure field itself then it is properly taken into account, both in gcc and clang. so this looks like a fine mess to clean up if/when the root bug gets fixed.