Mark Wielaard 448316
commit c5a5bea00af75f6ac50da10967d956f117b956f1
Mark Wielaard 448316
Author: Mark Wielaard <mark@klomp.org>
Mark Wielaard 448316
Date:   Sat Dec 8 13:47:43 2018 -0500
Mark Wielaard 448316
Mark Wielaard 448316
    memcheck: Allow unaligned loads of words on ppc64[le].
Mark Wielaard 448316
    
Mark Wielaard 448316
    On powerpc partial unaligned loads of words from partially invalid
Mark Wielaard 448316
    addresses are OK and could be generated by our translation of ldbrx.
Mark Wielaard 448316
    
Mark Wielaard 448316
    Adjust partial_load memcheck tests to allow partial loads of words
Mark Wielaard 448316
    on powerpc64.
Mark Wielaard 448316
    
Mark Wielaard 448316
    Part of resolving bug #386945.
Mark Wielaard 448316
Mark Wielaard 448316
diff --git a/memcheck/mc_main.c b/memcheck/mc_main.c
Mark Wielaard 448316
index 3ef7cb9..737f79d 100644
Mark Wielaard 448316
--- a/memcheck/mc_main.c
Mark Wielaard 448316
+++ b/memcheck/mc_main.c
Mark Wielaard 448316
@@ -1508,6 +1508,9 @@ ULong mc_LOADVn_slow ( Addr a, SizeT nBits, Bool bigendian )
Mark Wielaard 448316
 #  if defined(VGA_mips64) && defined(VGABI_N32)
Mark Wielaard 448316
    if (szB == VG_WORDSIZE * 2 && VG_IS_WORD_ALIGNED(a)
Mark Wielaard 448316
        && n_addrs_bad < VG_WORDSIZE * 2)
Mark Wielaard 448316
+#  elif defined(VGA_ppc64be) || defined(VGA_ppc64le)
Mark Wielaard 448316
+   /* On power unaligned loads of words are OK. */
Mark Wielaard 448316
+   if (szB == VG_WORDSIZE && n_addrs_bad < VG_WORDSIZE)
Mark Wielaard 448316
 #  else
Mark Wielaard 448316
    if (szB == VG_WORDSIZE && VG_IS_WORD_ALIGNED(a)
Mark Wielaard 448316
        && n_addrs_bad < VG_WORDSIZE)
Mark Wielaard 448316
diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am
Mark Wielaard 448316
index 2af4dd1..70b8ada 100644
Mark Wielaard 448316
--- a/memcheck/tests/Makefile.am
Mark Wielaard 448316
+++ b/memcheck/tests/Makefile.am
Mark Wielaard 448316
@@ -235,8 +235,10 @@ EXTRA_DIST = \
Mark Wielaard 448316
 	partiallydefinedeq.stdout.exp \
Mark Wielaard 448316
 	partial_load_ok.vgtest partial_load_ok.stderr.exp \
Mark Wielaard 448316
 		partial_load_ok.stderr.exp64 \
Mark Wielaard 448316
+		partial_load_ok.stderr.exp-ppc64 \
Mark Wielaard 448316
 	partial_load_dflt.vgtest partial_load_dflt.stderr.exp \
Mark Wielaard 448316
 		partial_load_dflt.stderr.exp64 \
Mark Wielaard 448316
+		partial_load_dflt.stderr.exp-ppc64 \
Mark Wielaard 448316
 	partial_load_dflt.stderr.expr-s390x-mvc \
Mark Wielaard 448316
 	pdb-realloc.stderr.exp pdb-realloc.vgtest \
Mark Wielaard 448316
 	pdb-realloc2.stderr.exp pdb-realloc2.stdout.exp pdb-realloc2.vgtest \
Mark Wielaard 448316
diff --git a/memcheck/tests/partial_load.c b/memcheck/tests/partial_load.c
Mark Wielaard 448316
index 0b2f10b..685ca8d 100644
Mark Wielaard 448316
--- a/memcheck/tests/partial_load.c
Mark Wielaard 448316
+++ b/memcheck/tests/partial_load.c
Mark Wielaard 448316
@@ -1,14 +1,14 @@
Mark Wielaard 448316
-
Mark Wielaard 448316
+#include <stdio.h>
Mark Wielaard 448316
 #include <stdlib.h>
Mark Wielaard 448316
 #include <assert.h>
Mark Wielaard 448316
 
Mark Wielaard 448316
 int main ( void )
Mark Wielaard 448316
 {
Mark Wielaard 448316
-  long  w;
Mark Wielaard 448316
-  int   i;
Mark Wielaard 448316
-  char* p;
Mark Wielaard 448316
-
Mark Wielaard 448316
+  long  w; int   i; char* p;
Mark Wielaard 448316
   assert(sizeof(long) == sizeof(void*));
Mark Wielaard 448316
+#if defined(__powerpc64__)
Mark Wielaard 448316
+  fprintf (stderr, "powerpc64\n"); /* Used to select correct .exp file.  */
Mark Wielaard 448316
+#endif
Mark Wielaard 448316
 
Mark Wielaard 448316
   /* partial load, which --partial-loads-ok=yes should suppress */
Mark Wielaard 448316
   p = calloc( sizeof(long)-1, 1 );
Mark Wielaard 448316
@@ -16,7 +16,7 @@ int main ( void )
Mark Wielaard 448316
   w = *(long*)p;
Mark Wielaard 448316
   free(p);
Mark Wielaard 448316
 
Mark Wielaard 448316
-  /* partial but misaligned, cannot be suppressed */
Mark Wielaard 448316
+  /* partial but misaligned, ppc64[le] ok, but otherwise cannot be suppressed */
Mark Wielaard 448316
   p = calloc( sizeof(long), 1 );
Mark Wielaard 448316
   assert(p);
Mark Wielaard 448316
   p++;
Mark Wielaard 448316
diff --git a/memcheck/tests/partial_load_dflt.stderr.exp-ppc64 b/memcheck/tests/partial_load_dflt.stderr.exp-ppc64
Mark Wielaard 448316
new file mode 100644
Mark Wielaard 448316
index 0000000..cf32bcf
Mark Wielaard 448316
--- /dev/null
Mark Wielaard 448316
+++ b/memcheck/tests/partial_load_dflt.stderr.exp-ppc64
Mark Wielaard 448316
@@ -0,0 +1,23 @@
Mark Wielaard 448316
+
Mark Wielaard 448316
+powerpc64
Mark Wielaard 448316
+Invalid read of size 2
Mark Wielaard 448316
+   at 0x........: main (partial_load.c:30)
Mark Wielaard 448316
+ Address 0x........ is 0 bytes inside a block of size 1 alloc'd
Mark Wielaard 448316
+   at 0x........: calloc (vg_replace_malloc.c:...)
Mark Wielaard 448316
+   by 0x........: main (partial_load.c:28)
Mark Wielaard 448316
+
Mark Wielaard 448316
+Invalid read of size 8
Mark Wielaard 448316
+   at 0x........: main (partial_load.c:37)
Mark Wielaard 448316
+ Address 0x........ is 0 bytes inside a block of size 8 free'd
Mark Wielaard 448316
+   at 0x........: free (vg_replace_malloc.c:...)
Mark Wielaard 448316
+   by 0x........: main (partial_load.c:36)
Mark Wielaard 448316
+
Mark Wielaard 448316
+
Mark Wielaard 448316
+HEAP SUMMARY:
Mark Wielaard 448316
+    in use at exit: ... bytes in ... blocks
Mark Wielaard 448316
+  total heap usage: ... allocs, ... frees, ... bytes allocated
Mark Wielaard 448316
+
Mark Wielaard 448316
+For a detailed leak analysis, rerun with: --leak-check=full
Mark Wielaard 448316
+
Mark Wielaard 448316
+For counts of detected and suppressed errors, rerun with: -v
Mark Wielaard 448316
+ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Mark Wielaard 448316
diff --git a/memcheck/tests/partial_load_ok.stderr.exp-ppc64 b/memcheck/tests/partial_load_ok.stderr.exp-ppc64
Mark Wielaard 448316
new file mode 100644
Mark Wielaard 448316
index 0000000..cf32bcf
Mark Wielaard 448316
--- /dev/null
Mark Wielaard 448316
+++ b/memcheck/tests/partial_load_ok.stderr.exp-ppc64
Mark Wielaard 448316
@@ -0,0 +1,23 @@
Mark Wielaard 448316
+
Mark Wielaard 448316
+powerpc64
Mark Wielaard 448316
+Invalid read of size 2
Mark Wielaard 448316
+   at 0x........: main (partial_load.c:30)
Mark Wielaard 448316
+ Address 0x........ is 0 bytes inside a block of size 1 alloc'd
Mark Wielaard 448316
+   at 0x........: calloc (vg_replace_malloc.c:...)
Mark Wielaard 448316
+   by 0x........: main (partial_load.c:28)
Mark Wielaard 448316
+
Mark Wielaard 448316
+Invalid read of size 8
Mark Wielaard 448316
+   at 0x........: main (partial_load.c:37)
Mark Wielaard 448316
+ Address 0x........ is 0 bytes inside a block of size 8 free'd
Mark Wielaard 448316
+   at 0x........: free (vg_replace_malloc.c:...)
Mark Wielaard 448316
+   by 0x........: main (partial_load.c:36)
Mark Wielaard 448316
+
Mark Wielaard 448316
+
Mark Wielaard 448316
+HEAP SUMMARY:
Mark Wielaard 448316
+    in use at exit: ... bytes in ... blocks
Mark Wielaard 448316
+  total heap usage: ... allocs, ... frees, ... bytes allocated
Mark Wielaard 448316
+
Mark Wielaard 448316
+For a detailed leak analysis, rerun with: --leak-check=full
Mark Wielaard 448316
+
Mark Wielaard 448316
+For counts of detected and suppressed errors, rerun with: -v
Mark Wielaard 448316
+ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Mark Wielaard 448316
diff -ur valgrind-3.14.0.orig/memcheck/tests/Makefile.in valgrind-3.14.0/memcheck/tests/Makefile.in
Mark Wielaard 448316
--- valgrind-3.14.0.orig/memcheck/tests/Makefile.in	2018-12-12 23:17:07.525501080 +0100
Mark Wielaard 448316
+++ valgrind-3.14.0/memcheck/tests/Makefile.in	2018-12-12 23:18:13.404014757 +0100
Mark Wielaard 448316
@@ -1546,8 +1546,10 @@
Mark Wielaard 448316
 	partiallydefinedeq.stdout.exp \
Mark Wielaard 448316
 	partial_load_ok.vgtest partial_load_ok.stderr.exp \
Mark Wielaard 448316
 		partial_load_ok.stderr.exp64 \
Mark Wielaard 448316
+		partial_load_ok.stderr.exp-ppc64 \
Mark Wielaard 448316
 	partial_load_dflt.vgtest partial_load_dflt.stderr.exp \
Mark Wielaard 448316
 		partial_load_dflt.stderr.exp64 \
Mark Wielaard 448316
+		partial_load_dflt.stderr.exp-ppc64 \
Mark Wielaard 448316
 	partial_load_dflt.stderr.expr-s390x-mvc \
Mark Wielaard 448316
 	pdb-realloc.stderr.exp pdb-realloc.vgtest \
Mark Wielaard 448316
 	pdb-realloc2.stderr.exp pdb-realloc2.stdout.exp pdb-realloc2.vgtest \