commit:     08b6896e6345db4ceb83e1718123e956522b4c27
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Mon Sep  2 07:20:45 2019 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Mon Sep  2 07:20:55 2019 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=08b6896e

app-arch/pixz: Avoid unaligned accesses

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 .../pixz-1.0.6-avoid-unaligned-accesses.patch      | 44 ++++++++++++++++++++++
 .../{pixz-1.0.6.ebuild => pixz-1.0.6-r1.ebuild}    |  4 ++
 2 files changed, 48 insertions(+)

diff --git a/app-arch/pixz/files/pixz-1.0.6-avoid-unaligned-accesses.patch 
b/app-arch/pixz/files/pixz-1.0.6-avoid-unaligned-accesses.patch
new file mode 100644
index 00000000000..24c53c9acc4
--- /dev/null
+++ b/app-arch/pixz/files/pixz-1.0.6-avoid-unaligned-accesses.patch
@@ -0,0 +1,44 @@
+https://github.com/vasi/pixz/pull/82
+
+From 8b9a198d86e435929ed0c2246217d241ed1e707c Mon Sep 17 00:00:00 2001
+From: Matt Turner <[email protected]>
+Date: Sun, 1 Sep 2019 23:58:26 -0700
+Subject: [PATCH] Avoid unaligned accesses
+
+Architectures like SPARC do not allow unaligned accesses. Avoid them by
+memcpy()ing the data to an aligned buffer. On x86 systems where
+unaligned loads are fast, the memcpy() will be compiled away and the
+same code generated as before.
+---
+ src/endian.c | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/src/endian.c b/src/endian.c
+index 51aea58..122c7da 100644
+--- a/src/endian.c
++++ b/src/endian.c
+@@ -13,6 +13,7 @@ void xle64enc(uint8_t *d, uint64_t n) {
+ #elif defined(__linux__) || defined(__FreeBSD__)
+ 
+ #include <stdint.h>
++#include <string.h>
+ #ifdef __linux__
+       #include <endian.h>
+       #include <byteswap.h>
+@@ -37,11 +38,14 @@ void xle64enc(uint8_t *d, uint64_t n) {
+ #endif
+ 
+ uint64_t xle64dec(const uint8_t *d) {
+-    return le64toh(*(uint64_t*)d);
++    uint64_t tmp;
++    memcpy(&tmp, d, sizeof(tmp));
++    return le64toh(tmp);
+ }
+ 
+ void xle64enc(uint8_t *d, uint64_t n) {
+-    *(uint64_t*)d = htole64(n);
++    uint64_t tmp = htole64(n);
++    memcpy(d, &tmp, sizeof(tmp));
+ }
+ 
+ #else

diff --git a/app-arch/pixz/pixz-1.0.6.ebuild 
b/app-arch/pixz/pixz-1.0.6-r1.ebuild
similarity index 94%
rename from app-arch/pixz/pixz-1.0.6.ebuild
rename to app-arch/pixz/pixz-1.0.6-r1.ebuild
index f4bb78275ca..7e207659629 100644
--- a/app-arch/pixz/pixz-1.0.6.ebuild
+++ b/app-arch/pixz/pixz-1.0.6-r1.ebuild
@@ -27,6 +27,10 @@ DEPEND="${RDEPEND}
        static? ( ${LIB_DEPEND} )"
 [[ ${PV} == "9999" ]] && DEPEND+=" app-text/asciidoc"
 
+PATCHES=(
+       "${FILESDIR}"/${P}-avoid-unaligned-accesses.patch
+)
+
 src_prepare() {
        default
        [[ ${PV} == "9999" ]] && eautoreconf

Reply via email to