This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Mark packed structure element used with atomic operation aligned


Atomic operations can generally work only on data that is properly
aligned, and known to the compiler to be properly aligned; in
particular, not on members of packed structures.

dl-profile.c contains an atomic operation on a member of the packed
struct here_cg_arc_record.  This was previously observed to cause a
build failure for e500v2.  This patch marks the relevant structure
member with an "aligned" attribute to fix that.  A detailed rationale
for why this is safe is at
<http://www.eglibc.org/archives/patches/msg00126.html>.  I have
reviewed that rationale and believe everything there still applies to
current sources.  I would just add (a) dl-profile.c has a comment
saying the formulas are the same as in gmon.c, where kcountsize is in
fact calculated using ROUNDUP to make it a multiple of
sizeof(*p->froms) (i.e. sizeof(u_long)), so consistency checks would
have failed already if it were not a multiple of 4, and (b) as noted
above, on general principles, atomic operations should not be done on
packed data and so marking this field aligned seems right on those
grounds alone.

Tested on x86_64 that this patch causes no changes to the installed
shared libraries, as expected.

2013-06-28  Nathan Froyd  <froydnj@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..b804ee8 100644
--- a/elf/dl-profile.c
+++ b/elf/dl-profile.c
@@ -131,7 +131,7 @@ struct here_cg_arc_record
   {
     uintptr_t from_pc;
     uintptr_t self_pc;
-    uint32_t count;
+    uint32_t count __attribute__ ((aligned (__alignof__ (uint32_t))));
   } __attribute__ ((packed));
 
 static struct here_cg_arc_record *data;

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]