From: Willy Tarreau Date: Wed, 11 Mar 2020 23:31:18 +0000 (+0100) Subject: BUG/MEDIUM: random: align the state on 2*64 bits for ARM64 X-Git-Tag: v2.1.4~31 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=48fcec9640cec7f04cf57cb3e8f45eb963ede2bd;p=haproxy-2.1.git BUG/MEDIUM: random: align the state on 2*64 bits for ARM64 x86_64 and ARM64 do support the double-word atomic CAS. However on ARM it must be done only on aligned data. The random generator makes use of such double-word atomic CAS when available but didn't enforce alignment, which causes ARM64 to crash early in the startup since commit 52bf839 ("BUG/MEDIUM: random: implement a thread-safe and process-safe PRNG"). This commit just unconditionally aligns the arrays. It must be backported to all branches where the commit above is backported (likely till 2.0). (cherry picked from commit 1544c14c57f4e77df2a8dcc27bc7eaaba8bbb833) Signed-off-by: Willy Tarreau --- diff --git a/src/standard.c b/src/standard.c index 5a641be..5c96b8c 100644 --- a/src/standard.c +++ b/src/standard.c @@ -4362,7 +4362,7 @@ int varint_bytes(uint64_t v) } /* Random number generator state, see below */ -static uint64_t ha_random_state[2]; +static uint64_t ha_random_state[2] ALIGNED(2*sizeof(uint64_t)); /* This is a thread-safe implementation of xoroshiro128** described below: * http://prng.di.unimi.it/ @@ -4374,8 +4374,8 @@ static uint64_t ha_random_state[2]; uint64_t ha_random64() { uint64_t result; - uint64_t old[2]; - uint64_t new[2]; + uint64_t old[2] ALIGNED(2*sizeof(uint64_t)); + uint64_t new[2] ALIGNED(2*sizeof(uint64_t)); #if defined(USE_THREAD) && (!defined(HA_CAS_IS_8B) || !defined(HA_HAVE_CAS_DW)) static HA_SPINLOCK_T rand_lock;