Update memory allocation in sysstat to be 16 byte aligned.
sysstat declares 16 byte alignment for many structs. But
has unsafe pointer casts. This forces a 16 byte data alignement to
avoid crashes on ARM.
Discussion about crash and SIMD loads on ARM.
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-May/504731.html
BUG=b:37469743
TEST=No more crashes
Change-Id: I2ae9f0ee5bb27738d9e5601ce003d009203b0071
Reviewed-on: https://chromium-review.googlesource.com/496366
Commit-Ready: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Grant Grundler <grundler@chromium.org>
Reviewed-by: Grant Grundler <grundler@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
(cherry picked from commit 28369cc80852cc4863a2e4a332a9e177ab2b41fa)
Reviewed-on: https://chromium-review.googlesource.com/498967
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Trybot-Ready: Grant Grundler <grundler@chromium.org>
diff --git a/app-admin/sysstat/files/sysstat-align.patch b/app-admin/sysstat/files/sysstat-align.patch
new file mode 100644
index 0000000..d4859e7
--- /dev/null
+++ b/app-admin/sysstat/files/sysstat-align.patch
@@ -0,0 +1,38 @@
+sysstat declares 16 bytes alignment for many structs. But realloc does
+not guarantee 16 byte alignment. Because of declared 16 byte alignement,
+compiler is free to generate SIMD 16 byte loads which require aligned
+addresses. Use posix_memalign instead to enforce 16 bytes data alignment
+to avoid crashes.
+diff -Naur sysstat-10.2.0/common.h sysstat-10.2.0_b/common.h
+--- sysstat-10.2.0/common.h 2013-09-13 00:01:47.000000000 -0700
++++ sysstat-10.2.0_b/common.h 2017-05-04 11:42:17.908311386 -0700
+@@ -11,6 +11,7 @@
+
+ #include <time.h>
+ #include <sched.h> /* For __CPU_SETSIZE */
++#include <stdlib.h>
+ #include "rd_stats.h"
+
+ /*
+@@ -91,13 +92,19 @@
+ TYPE *_p_; \
+ _p_ = S; \
+ if (SIZE) { \
+- if ((S = (TYPE *) realloc(S, (SIZE))) == NULL) { \
++ void *_ptr = NULL; \
++ int error = posix_memalign(&_ptr, 16, SIZE); \
++ if (error || _ptr == NULL) { \
+ perror("realloc"); \
+ exit(4); \
+ } \
++ S = (TYPE *)_ptr; \
+ /* If the ptr was null, then it's a malloc() */ \
+- if (!_p_) \
++ if (!_p_) { \
+ memset(S, 0, (SIZE)); \
++ } else { \
++ memcpy(S, _p_, SIZE); \
++ } \
+ } \
+ } while (0)
+
diff --git a/app-admin/sysstat/sysstat-10.2.0.ebuild b/app-admin/sysstat/sysstat-10.2.0-r1.ebuild
similarity index 97%
rename from app-admin/sysstat/sysstat-10.2.0.ebuild
rename to app-admin/sysstat/sysstat-10.2.0-r1.ebuild
index a46bc5e..850d7d3 100644
--- a/app-admin/sysstat/sysstat-10.2.0.ebuild
+++ b/app-admin/sysstat/sysstat-10.2.0-r1.ebuild
@@ -43,6 +43,7 @@
fi
epatch "${FILESDIR}"/${PN}-10.0.4-flags.patch
epatch "${FILESDIR}"/${PN}-10.2.0-systemd.patch
+ epatch "${FILESDIR}"/sysstat-align.patch
}
src_configure() {