All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lino Sanfilippo <lsanfil@marvell.com>
To: <linux@arm.linux.org.uk>, <linux-arm-kernel@lists.infradead.org>
Cc: <linux-kernel@vger.kernel.org>, <LinoSanfilippo@gmx.de>,
	Lino Sanfilippo <lsanfil@marvell.com>
Subject: [RFC PATCH 1/1] ARM: Ensure correct structure alignment when using compiler attribute "section"
Date: Mon, 2 Mar 2015 11:01:42 +0100	[thread overview]
Message-ID: <1425290502-2322-2-git-send-email-lsanfil@marvell.com> (raw)
In-Reply-To: <1425290502-2322-1-git-send-email-lsanfil@marvell.com>

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 <lsanfil@marvell.com>
---
 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


WARNING: multiple messages have this Message-ID (diff)
From: lsanfil@marvell.com (Lino Sanfilippo)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 1/1] ARM: Ensure correct structure alignment when using compiler attribute "section"
Date: Mon, 2 Mar 2015 11:01:42 +0100	[thread overview]
Message-ID: <1425290502-2322-2-git-send-email-lsanfil@marvell.com> (raw)
In-Reply-To: <1425290502-2322-1-git-send-email-lsanfil@marvell.com>

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 <lsanfil@marvell.com>
---
 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

  reply	other threads:[~2015-03-02 10:02 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-02 10:01 [RFC PATCH 0/1] Wrong structure alignment due to compiler attribute "section" Lino Sanfilippo
2015-03-02 10:01 ` Lino Sanfilippo
2015-03-02 10:01 ` Lino Sanfilippo [this message]
2015-03-02 10:01   ` [RFC PATCH 1/1] ARM: Ensure correct structure alignment when using " Lino Sanfilippo
2015-03-03 14:41 ` [RFC PATCH 0/1] Wrong structure alignment due to " Dave Martin
2015-03-03 14:41   ` Dave Martin
2015-03-04 11:40   ` sanfilippo
2015-03-04 11:40     ` sanfilippo
2015-03-04 14:35     ` Dave Martin
2015-03-04 14:35       ` Dave Martin
2015-03-04 16:29       ` Lino Sanfilippo
2015-03-04 16:29         ` Lino Sanfilippo
2015-03-05 12:26         ` Dave Martin
2015-03-05 12:26           ` Dave Martin
2015-03-05 13:20           ` Lino Sanfilippo
2015-03-05 13:20             ` Lino Sanfilippo
2015-03-05 13:47             ` Dave Martin
2015-03-05 13:47               ` Dave Martin
2015-03-05 15:32               ` Lino Sanfilippo
2015-03-05 15:32                 ` Lino Sanfilippo
2015-03-05 17:33                 ` Dave Martin
2015-03-05 17:33                   ` Dave Martin
2015-03-06 14:02                   ` Lino Sanfilippo
2015-03-06 14:02                     ` Lino Sanfilippo
2015-03-06 18:20                     ` Lino Sanfilippo
2015-03-06 18:20                       ` Lino Sanfilippo
2015-03-22  0:56                       ` Lino Sanfilippo
2015-03-22  0:56                         ` Lino Sanfilippo
2015-03-24 12:07                         ` Dave Martin
2015-03-24 12:07                           ` Dave Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1425290502-2322-2-git-send-email-lsanfil@marvell.com \
    --to=lsanfil@marvell.com \
    --cc=LinoSanfilippo@gmx.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.