From: Andrew Waterman Date: Wed, 21 Jan 2015 17:20:05 +0000 (+0000) Subject: Avoid misaligned atomic operations X-Git-Tag: releases/gcc-4.8.5~316 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15e148898ed542391a6f164717031ae8bcbeb405;p=thirdparty%2Fgcc.git Avoid misaligned atomic operations Andrew Waterman * fop_n.c (libat_fetch_op): Align address to word boundary. (libat_op_fetch): Likewise. From-SVN: r219956 --- diff --git a/libatomic/ChangeLog b/libatomic/ChangeLog index 1630dc0d84c7..858b6ea89606 100644 --- a/libatomic/ChangeLog +++ b/libatomic/ChangeLog @@ -1,3 +1,8 @@ +2015-01-21 Andrew Waterman + + * fop_n.c (libat_fetch_op): Align address to word boundary. + (libat_op_fetch): Likewise. + 2014-12-19 Release Manager * GCC 4.8.4 released. diff --git a/libatomic/fop_n.c b/libatomic/fop_n.c index 5e4b224aa5a4..2328e52e6d1a 100644 --- a/libatomic/fop_n.c +++ b/libatomic/fop_n.c @@ -112,9 +112,9 @@ SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel) pre_barrier (smodel); - wptr = (UWORD *)mptr; - shift = 0; - mask = -1; + wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE); + shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK); + mask = SIZE(MASK) << shift; wopval = (UWORD)opval << shift; woldval = __atomic_load_n (wptr, __ATOMIC_RELAXED); @@ -136,9 +136,9 @@ SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel) pre_barrier (smodel); - wptr = (UWORD *)mptr; - shift = 0; - mask = -1; + wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE); + shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK); + mask = SIZE(MASK) << shift; wopval = (UWORD)opval << shift; woldval = __atomic_load_n (wptr, __ATOMIC_RELAXED);