Bug 1489572 - Apply upstream patch to valgrind to fix some false positives. r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Sun, 02 Dec 2018 01:03:41 +0000
changeset 508632 134001f7ca7fb0a6cfd32d56ea1a324d31fb62e1
parent 508631 7c58f1010e376df70c61afd96dfb531ca9145374
child 508633 1d3c0e917ed7306012e6d7408111067a6e2c6393
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1489572
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1489572 - Apply upstream patch to valgrind to fix some false positives. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D13509
build/debian-packages/valgrind-wheezy.diff
--- a/build/debian-packages/valgrind-wheezy.diff
+++ b/build/debian-packages/valgrind-wheezy.diff
@@ -1,12 +1,19 @@
 diff -Nru valgrind-3.14.0/debian/changelog valgrind-3.14.0/debian/changelog
 --- valgrind-3.14.0/debian/changelog	2018-11-15 09:21:43.000000000 +0900
-+++ valgrind-3.14.0/debian/changelog	2018-11-15 11:45:25.000000000 +0900
-@@ -1,3 +1,14 @@
++++ valgrind-3.14.0/debian/changelog	2018-11-30 15:20:10.000000000 +0900
+@@ -1,3 +1,21 @@
++valgrind (1:3.14.0-1.deb7moz2) wheezy; urgency=medium
++
++  * debian/patches/vg401112: Cherry-pick upstream revision
++    f2c03ce3babe51eecbf03735f726c4028a162857.
++
++ -- Mike Hommey <glandium@debian.org>  Fri, 30 Nov 2018 15:20:10 +0900
++
 +valgrind (1:3.14.0-1.deb7moz1) wheezy; urgency=medium
 +
 +  * Mozilla backport for wheezy.
 +  * debian/control, debian/compat: Drop debhelper compat back to 7, which
 +    requires adding back an explicit dependency on dh-autoreconf.
 +  * debian/rules: Debhelper only defaulted to --parallel in compat >= 10, so
 +    add --parallel back.
 +  * debian/valgrind-mpi.install: Use non-multiarch path.
@@ -30,16 +37,175 @@ diff -Nru valgrind-3.14.0/debian/control
  Priority: optional
  Maintainer: Alessandro Ghedini <ghedo@debian.org>
 -Build-Depends: debhelper (>= 11),
 +Build-Depends: debhelper (>= 7.0.50~),
 + dh-autoreconf,
   gdb,
   gcc-multilib [amd64],
   libc6-dev-i386 [amd64],
+diff -Nru valgrind-3.14.0/debian/patches/series valgrind-3.14.0/debian/patches/series
+--- valgrind-3.14.0/debian/patches/series	2018-11-15 09:21:43.000000000 +0900
++++ valgrind-3.14.0/debian/patches/series	2018-11-30 15:19:14.000000000 +0900
+@@ -5,3 +5,4 @@
+ 08_fix-spelling-in-manpage.patch
+ 09_fix-armhf-detect.patch
+ 10_mpi-pkg-config.patch
++vg401112
+diff -Nru valgrind-3.14.0/debian/patches/vg401112 valgrind-3.14.0/debian/patches/vg401112
+--- valgrind-3.14.0/debian/patches/vg401112	1970-01-01 09:00:00.000000000 +0900
++++ valgrind-3.14.0/debian/patches/vg401112	2018-11-30 15:19:46.000000000 +0900
+@@ -0,0 +1,147 @@
++From f2c03ce3babe51eecbf03735f726c4028a162857 Mon Sep 17 00:00:00 2001
++From: Julian Seward <jseward@acm.org>
++Date: Wed, 28 Nov 2018 14:15:06 +0100
++Subject: [PATCH] Bug 401112 - LLVM 5.0 generates comparison against partially
++ initialized data.
++
++This generalises the existing spec rules for W of 32 bits:
++
++             W  <u   0---(N-1)---0 1 0---0  or
++
++(that is, B/NB after SUBL, where dep2 has the above form), to also cover
++
++             W  <=u  0---(N-1)---0 0 1---1
++
++(that is, BE/NBE after SUBL, where dept2 has the specified form).
++
++Patch from Nicolas B. Pierron (nicolas.b.pierron@nbp.name).
++---
++ VEX/priv/guest_amd64_helpers.c | 90 ++++++++++++++++++++++++++++++------------
++ 2 files changed, 66 insertions(+), 25 deletions(-)
++
++diff --git a/VEX/priv/guest_amd64_helpers.c b/VEX/priv/guest_amd64_helpers.c
++index a2b0789..30e82db 100644
++--- a/VEX/priv/guest_amd64_helpers.c
+++++ b/VEX/priv/guest_amd64_helpers.c
++@@ -1013,13 +1013,10 @@ static inline Bool isU64 ( IRExpr* e, ULong n )
++           && e->Iex.Const.con->Ico.U64 == n;
++ }
++ 
++-/* Returns N if E is an immediate of the form 1 << N for N in 1 to 31,
+++/* Returns N if W64 is a value of the form 1 << N for N in 1 to 31,
++    and zero in any other case. */
++-static Int isU64_1_shl_N ( IRExpr* e )
+++static Int isU64_1_shl_N_literal ( ULong w64 )
++ {
++-   if (e->tag != Iex_Const || e->Iex.Const.con->tag != Ico_U64)
++-      return 0;
++-   ULong w64 = e->Iex.Const.con->Ico.U64;
++    if (w64 < (1ULL << 1) || w64 > (1ULL << 31))
++       return 0;
++    if ((w64 & (w64 - 1)) != 0)
++@@ -1036,6 +1033,30 @@ static Int isU64_1_shl_N ( IRExpr* e )
++    return 0;
++ }
++ 
+++/* Returns N if E is an immediate of the form 1 << N for N in 1 to 31,
+++   and zero in any other case. */
+++static Int isU64_1_shl_N ( IRExpr* e )
+++{
+++   if (e->tag != Iex_Const || e->Iex.Const.con->tag != Ico_U64)
+++      return 0;
+++   ULong w64 = e->Iex.Const.con->Ico.U64;
+++   return isU64_1_shl_N_literal(w64);
+++}
+++
+++/* Returns N if E is an immediate of the form (1 << N) - 1 for N in 1 to 31,
+++   and zero in any other case. */
+++static Int isU64_1_shl_N_minus_1 ( IRExpr* e )
+++{
+++  if (e->tag != Iex_Const || e->Iex.Const.con->tag != Ico_U64)
+++    return 0;
+++  ULong w64 = e->Iex.Const.con->Ico.U64;
+++  // This isn't actually necessary since isU64_1_shl_N_literal will return
+++  // zero given a zero argument, but still ..
+++  if (w64 == 0xFFFFFFFFFFFFFFFFULL)
+++     return 0;
+++  return isU64_1_shl_N_literal(w64 + 1);
+++}
+++
++ IRExpr* guest_amd64_spechelper ( const HChar* function_name,
++                                  IRExpr** args,
++                                  IRStmt** precedingStmts,
++@@ -1258,32 +1279,51 @@ IRExpr* guest_amd64_spechelper ( const HChar* function_name,
++         /* It appears that LLVM 5.0 and later have a new way to find out
++            whether the top N bits of a word W are all zero, by computing
++ 
++-             W  <u  0---(N-1)---0 1 0---0
+++             W  <u   0---(N-1)---0 1 0---0  or
+++             W  <=u  0---(N-1)---0 0 1---1
++ 
++            In particular, the result will be defined if the top N bits of W
++            are defined, even if the trailing bits -- those corresponding to
++-           the 0---0 section -- are undefined.  Rather than make Memcheck
++-           more complex, we detect this case where we can and shift out the
++-           irrelevant and potentially undefined bits. */
+++           the rightmost 0---0 / 1---1 section -- are undefined.  Rather than
+++           make Memcheck more complex, we detect this case where we can and
+++           shift out the irrelevant and potentially undefined bits. */
++         Int n = 0;
++-        if (isU64(cc_op, AMD64G_CC_OP_SUBL)
++-            && (isU64(cond, AMD64CondB) || isU64(cond, AMD64CondNB))
++-            && (n = isU64_1_shl_N(cc_dep2)) > 0) {
++-           /* long sub/cmp, then B (unsigned less than),
++-              where dep2 is a power of 2:
++-                -> CmpLT32(dep1, 1 << N)
++-                -> CmpEQ32(dep1 >>u N, 0)
++-              and
++-              long sub/cmp, then NB (unsigned greater than or equal),
++-              where dep2 is a power of 2:
++-                -> CmpGE32(dep1, 1 << N)
++-                -> CmpNE32(dep1 >>u N, 0)
++-              This avoids CmpLT32U/CmpGE32U being applied to potentially
++-              uninitialised bits in the area being shifted out. */
+++        Bool is_NB_or_NBE = False;
+++        if (isU64(cc_op, AMD64G_CC_OP_SUBL)) {
+++           if (isU64(cond, AMD64CondB) || isU64(cond, AMD64CondNB)) {
+++              /* long sub/cmp, then B (unsigned less than),
+++                 where dep2 is a power of 2:
+++                   -> CmpLT32U(dep1, 1 << N)
+++                   -> CmpEQ32(dep1 >>u N, 0)
+++                 and
+++                 long sub/cmp, then NB (unsigned greater than or equal),
+++                 where dep2 is a power of 2:
+++                   -> CmpGE32U(dep1, 1 << N)
+++                   -> CmpNE32(dep1 >>u N, 0)
+++                 This avoids CmpLT32U/CmpGE32U being applied to potentially
+++                 uninitialised bits in the area being shifted out. */
+++              n = isU64_1_shl_N(cc_dep2);
+++              is_NB_or_NBE = isU64(cond, AMD64CondNB);
+++           } else if (isU64(cond, AMD64CondBE) || isU64(cond, AMD64CondNBE)) {
+++              /* long sub/cmp, then BE (unsigned less than or equal),
+++                 where dep2 is a power of 2 minus 1:
+++                  -> CmpLE32U(dep1, (1 << N) - 1)
+++                  -> CmpEQ32(dep1 >>u N, 0)
+++                 and
+++                 long sub/cmp, then NBE (unsigned greater than),
+++                 where dep2 is a power of 2 minus 1:
+++                   -> CmpGT32U(dep1, (1 << N) - 1)
+++                   -> CmpNE32(dep1 >>u N, 0)
+++                 This avoids CmpLE32U/CmpGT32U being applied to potentially
+++                 uninitialised bits in the area being shifted out. */
+++              n = isU64_1_shl_N_minus_1(cc_dep2);
+++              is_NB_or_NBE = isU64(cond, AMD64CondNBE);
+++           }
+++        }
+++        if (n > 0) {
++            vassert(n >= 1 && n <= 31);
++-           Bool isNB = isU64(cond, AMD64CondNB);
++            return unop(Iop_1Uto64,
++-                       binop(isNB ? Iop_CmpNE32 : Iop_CmpEQ32,
+++                       binop(is_NB_or_NBE ? Iop_CmpNE32 : Iop_CmpEQ32,
++                              binop(Iop_Shr32, unop(Iop_64to32, cc_dep1),
++                                               mkU8(n)),
++                              mkU32(0)));
++-- 
++2.9.3
++
 diff -Nru valgrind-3.14.0/debian/rules valgrind-3.14.0/debian/rules
 --- valgrind-3.14.0/debian/rules	2018-11-15 09:21:43.000000000 +0900
 +++ valgrind-3.14.0/debian/rules	2018-11-15 11:45:25.000000000 +0900
 @@ -11,7 +11,7 @@
  LDFLAGS  = $(shell dpkg-buildflags --get LDFLAGS)
  
  %:
 -	dh $@ --with=autoreconf