From 7f45dae583daf3a4d09880fc1d7efdb50d6073dd Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith [Google LLC]" Date: Wed, 5 May 2021 11:49:41 -0700 Subject: [PATCH 1/2] Disable unaligned memory access on ARM. --- .../next/Library/2021-05-05-11-44-49.bpo-36515.uOSa3q.rst | 2 ++ Modules/_sha3/sha3module.c | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2021-05-05-11-44-49.bpo-36515.uOSa3q.rst diff --git a/Misc/NEWS.d/next/Library/2021-05-05-11-44-49.bpo-36515.uOSa3q.rst b/Misc/NEWS.d/next/Library/2021-05-05-11-44-49.bpo-36515.uOSa3q.rst new file mode 100644 index 00000000000000..dd24474c2fde7e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-05-05-11-44-49.bpo-36515.uOSa3q.rst @@ -0,0 +1,2 @@ +The :mod:`hashlib` module no longer does unaligned memory accesses when +compiled for ARM platforms. diff --git a/Modules/_sha3/sha3module.c b/Modules/_sha3/sha3module.c index aba7f6d4b45c22..a4b1a66f29d0a3 100644 --- a/Modules/_sha3/sha3module.c +++ b/Modules/_sha3/sha3module.c @@ -64,6 +64,12 @@ #define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #endif +/* Bus error on 32-bit ARM due to un-aligned memory accesses; 64-bit ARM + * doesn't complain but un-aligned memory accesses are sub-optimal */ +#if defined(__arm__) || defined(__aarch64__) +#define NO_MISALIGNED_ACCESSES +#endif + /* mangle names */ #define KeccakF1600_FastLoop_Absorb _PySHA3_KeccakF1600_FastLoop_Absorb #define Keccak_HashFinal _PySHA3_Keccak_HashFinal From 588aaf84205b97e62737c299e74ad68550b0611f Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith [Google LLC]" Date: Wed, 5 May 2021 13:33:09 -0700 Subject: [PATCH 2/2] Use HAVE_ALIGNED_REQUIRED instead. --- Modules/_sha3/sha3module.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Modules/_sha3/sha3module.c b/Modules/_sha3/sha3module.c index a4b1a66f29d0a3..3974e0b6b47faa 100644 --- a/Modules/_sha3/sha3module.c +++ b/Modules/_sha3/sha3module.c @@ -64,9 +64,8 @@ #define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #endif -/* Bus error on 32-bit ARM due to un-aligned memory accesses; 64-bit ARM - * doesn't complain but un-aligned memory accesses are sub-optimal */ -#if defined(__arm__) || defined(__aarch64__) +/* Prevent bus errors on platforms requiring aligned accesses such ARM. */ +#if HAVE_ALIGNED_REQUIRED && !defined(NO_MISALIGNED_ACCESSES) #define NO_MISALIGNED_ACCESSES #endif