This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Mark packed structure element used with atomic operation aligned
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: <libc-alpha at sourceware dot org>
- Date: Fri, 28 Jun 2013 17:23:09 +0000
- Subject: Re: Mark packed structure element used with atomic operation aligned
- References: <Pine dot LNX dot 4 dot 64 dot 1306281632350 dot 27363 at digraph dot polyomino dot org dot uk> <20130628171004 dot C644E2C099 at topped-with-meat dot com>
On Fri, 28 Jun 2013, Roland McGrath wrote:
> The change is fine but it needs comments in the code, rather than some
> mailing list archive, to explain why it is both necessary and correct.
How does this version with a comment seem?
2013-06-28 Nathan Froyd <froydnj@codesourcery.com>
Joseph Myers <joseph@codesourcery.com>
* elf/dl-profile.c (struct here_cg_arc_record): Declare 'count'
as being properly aligned.
diff --git a/elf/dl-profile.c b/elf/dl-profile.c
index 9034be2..8fa6efc 100644
--- a/elf/dl-profile.c
+++ b/elf/dl-profile.c
@@ -131,7 +131,18 @@ struct here_cg_arc_record
{
uintptr_t from_pc;
uintptr_t self_pc;
- uint32_t count;
+ /* The count field is atomically incremented in _dl_mcount, which
+ requires it to be properly aligned for its type, and for this
+ alignment to be visible to the compiler. The amount of data
+ before an array of this structure is calculated as
+ expected_size in _dl_start_profile. Everything in that
+ calculation is a multiple of 4 bytes (in the case of
+ kcountsize, because it is derived from a subtraction of
+ page-aligned values, and the corresponding calculation in
+ __monstartup also ensures it is at least a multiple of the size
+ of u_long), so all copies of this field do in fact have the
+ appropriate alignment. */
+ uint32_t count __attribute__ ((aligned (__alignof__ (uint32_t))));
} __attribute__ ((packed));
static struct here_cg_arc_record *data;
--
Joseph S. Myers
joseph@codesourcery.com