From aa76174e0a77b5f8b655eefd2e6b591641eb8809 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sun, 2 Dec 2018 00:53:12 +0100 Subject: [PATCH] Add valgrind-3.14.0-wcsncmp.patch (#1645971) --- valgrind-3.14.0-wcsncmp.patch | 89 +++++++++++++++++++++++++++++++++++ valgrind.spec | 7 +++ 2 files changed, 96 insertions(+) create mode 100644 valgrind-3.14.0-wcsncmp.patch diff --git a/valgrind-3.14.0-wcsncmp.patch b/valgrind-3.14.0-wcsncmp.patch new file mode 100644 index 0000000..8940910 --- /dev/null +++ b/valgrind-3.14.0-wcsncmp.patch @@ -0,0 +1,89 @@ +commit 5fdabb72fdcba6bcf788eaa19c1ee557c13b8a7a +Author: Mark Wielaard +Date: Sat Dec 1 23:54:40 2018 +0100 + + Bug 401627 - Add wcsncmp override and testcase. + + glibc 2.28 added an avx2 optimized variant of wstrncmp which memcheck + cannot proof correct. Add a simple override in vg_replace_strmem.c. + +diff --git a/memcheck/tests/wcs.c b/memcheck/tests/wcs.c +index 15730ad..538304b 100644 +--- a/memcheck/tests/wcs.c ++++ b/memcheck/tests/wcs.c +@@ -1,5 +1,6 @@ +-// Uses various wchar_t * functions that have hand written SSE assembly +-// implementations in glibc. wcslen, wcscpy, wcscmp, wcsrchr, wcschr. ++// Uses various wchar_t * functions that have hand written SSE and/or AVX2 ++// assembly implementations in glibc. ++// wcslen, wcscpy, wcscmp, wcsncmp, wcsrchr, wcschr. + + #include + #include +@@ -18,6 +19,8 @@ int main(int argc, char **argv) + c = wcscpy (b, a); + + fprintf (stderr, "wcscmp equal: %d\n", wcscmp (a, b)); // wcscmp equal: 0 ++ fprintf (stderr, ++ "wcsncmp equal: %d\n", wcsncmp (a, b, l)); // wcsncmp equal: 0 + + d = wcsrchr (a, L'd'); + e = wcschr (a, L'd'); +diff --git a/memcheck/tests/wcs.stderr.exp b/memcheck/tests/wcs.stderr.exp +index 41d74c8..d5b5959 100644 +--- a/memcheck/tests/wcs.stderr.exp ++++ b/memcheck/tests/wcs.stderr.exp +@@ -1,3 +1,4 @@ + wcslen: 53 + wcscmp equal: 0 ++wcsncmp equal: 0 + wcsrchr == wcschr: 1 +diff --git a/shared/vg_replace_strmem.c b/shared/vg_replace_strmem.c +index d6927f0..89a7dcc 100644 +--- a/shared/vg_replace_strmem.c ++++ b/shared/vg_replace_strmem.c +@@ -103,6 +103,7 @@ + 20420 STPNCPY + 20430 WMEMCHR + 20440 WCSNLEN ++ 20450 WSTRNCMP + */ + + #if defined(VGO_solaris) +@@ -1927,6 +1928,36 @@ static inline void my_exit ( int x ) + WCSCMP(VG_Z_LIBC_SONAME, wcscmp) + #endif + ++/*---------------------- wcsncmp ----------------------*/ ++ ++// This is a wchar_t equivalent to strncmp. We don't ++// have wchar_t available here, but in the GNU C Library ++// wchar_t is always 32 bits wide and wcsncmp uses signed ++// comparison, not unsigned as in strncmp function. ++ ++#define WCSNCMP(soname, fnname) \ ++ int VG_REPLACE_FUNCTION_EZU(20450,soname,fnname) \ ++ ( const Int* s1, const Int* s2, SizeT nmax ); \ ++ int VG_REPLACE_FUNCTION_EZU(20450,soname,fnname) \ ++ ( const Int* s1, const Int* s2, SizeT nmax ) \ ++ { \ ++ SizeT n = 0; \ ++ while (True) { \ ++ if (n >= nmax) return 0; \ ++ if (*s1 == 0 && *s2 == 0) return 0; \ ++ if (*s1 == 0) return -1; \ ++ if (*s2 == 0) return 1; \ ++ \ ++ if (*s1 < *s2) return -1; \ ++ if (*s1 > *s2) return 1; \ ++ \ ++ s1++; s2++; n++; \ ++ } \ ++ } ++#if defined(VGO_linux) ++ WCSNCMP(VG_Z_LIBC_SONAME, wcsncmp) ++#endif ++ + /*---------------------- wcscpy ----------------------*/ + + // This is a wchar_t equivalent to strcpy. We don't diff --git a/valgrind.spec b/valgrind.spec index 0d35170..d5f1082 100644 --- a/valgrind.spec +++ b/valgrind.spec @@ -128,6 +128,9 @@ Patch14: valgrind-3.14.0-ppc-frontend-new-IROps.patch Patch15: valgrind-3.14.0-transform-popcount64-ctznat64.patch Patch16: valgrind-3.14.0-enable-ppc-Iop_Sar_Shr8.patch +# KDE#401627 memcheck errors with glibc avx2 optimized wcsncmp +Patch17: valgrind-3.14.0-wcsncmp.patch + %if %{build_multilib} # Ensure glibc{,-devel} is installed for both multilib arches BuildRequires: /lib/libc.so.6 /usr/lib/libc.so /lib64/libc.so.6 /usr/lib64/libc.so @@ -276,6 +279,7 @@ Valgrind User Manual for details. %patch14 -p1 %patch15 -p1 %patch16 -p1 +%patch17 -p1 %build CC=gcc @@ -510,6 +514,9 @@ fi %endif %changelog +* Sat Dec 1 2018 Mark Wielaard +- Add valgrind-3.14.0-wcsncmp.patch (#1645971) + * Fri Nov 23 2018 Mark Wielaard - 3.14.0-4 - Add valgrind-3.14.0-get_otrack_shadow_offset_wrk-ppc.patch, valgrind-3.14.0-new-strlen-IROps.patch,