From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753873AbbCBKCy (ORCPT ); Mon, 2 Mar 2015 05:02:54 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:3191 "EHLO mx0a-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751462AbbCBKCu (ORCPT ); Mon, 2 Mar 2015 05:02:50 -0500 From: Lino Sanfilippo To: , CC: , , Lino Sanfilippo Subject: [RFC PATCH 1/1] ARM: Ensure correct structure alignment when using compiler attribute "section" Date: Mon, 2 Mar 2015 11:01:42 +0100 Message-ID: <1425290502-2322-2-git-send-email-lsanfil@marvell.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1425290502-2322-1-git-send-email-lsanfil@marvell.com> References: <1425290502-2322-1-git-send-email-lsanfil@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.13.68,1.0.33,0.0.0000 definitions=2015-03-02_01:2015-02-27,2015-03-01,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1503020108 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In some cases structures are placed into dedicated sections by means of the "section" compiler attribute and then accessed as elements of an array (e.g when the __clk_of_table is set up which contains all potential clock providers - see CLK_OF_DECLARE). But even if the size of such a structure is a multiple of the processors word size, the linker may decide to use an even greater alignment and thus use padding in between the structures. In this case accessing a structure as an array element is not possible. To avoid such padding and thus allow to access such a structure as an array element enforce an alignment of processor word size by means of the "aligned" attribute. Signed-off-by: Lino Sanfilippo --- include/linux/compiler.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 33063f8..6f32128 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -371,7 +371,8 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s /* Simple shorthand for a section definition */ #ifndef __section -# define __section(S) __attribute__ ((__section__(#S))) +# define __section(S) __attribute__ ((__section__(#S))) \ + __aligned(sizeof(void *)) #endif #ifndef __visible -- 1.9.1 From mboxrd@z Thu Jan 1 00:00:00 1970 From: lsanfil@marvell.com (Lino Sanfilippo) Date: Mon, 2 Mar 2015 11:01:42 +0100 Subject: [RFC PATCH 1/1] ARM: Ensure correct structure alignment when using compiler attribute "section" In-Reply-To: <1425290502-2322-1-git-send-email-lsanfil@marvell.com> References: <1425290502-2322-1-git-send-email-lsanfil@marvell.com> Message-ID: <1425290502-2322-2-git-send-email-lsanfil@marvell.com> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org In some cases structures are placed into dedicated sections by means of the "section" compiler attribute and then accessed as elements of an array (e.g when the __clk_of_table is set up which contains all potential clock providers - see CLK_OF_DECLARE). But even if the size of such a structure is a multiple of the processors word size, the linker may decide to use an even greater alignment and thus use padding in between the structures. In this case accessing a structure as an array element is not possible. To avoid such padding and thus allow to access such a structure as an array element enforce an alignment of processor word size by means of the "aligned" attribute. Signed-off-by: Lino Sanfilippo --- include/linux/compiler.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 33063f8..6f32128 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -371,7 +371,8 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s /* Simple shorthand for a section definition */ #ifndef __section -# define __section(S) __attribute__ ((__section__(#S))) +# define __section(S) __attribute__ ((__section__(#S))) \ + __aligned(sizeof(void *)) #endif #ifndef __visible -- 1.9.1