Browse Source

initial package creation

Signed-off-by: Toshaan Bharvani <toshaan@powerel.org>
master
Toshaan Bharvani 1 year ago
parent
commit
0789abf490
  1. 25
      SOURCES/valgrind-3.19.0-ld-so-strncmp.patch
  2. 231
      SOURCES/valgrind-3.19.0-s390x-memmem.patch
  3. 103
      SPECS/valgrind.spec

25
SOURCES/valgrind-3.19.0-ld-so-strncmp.patch

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
commit 947388eb043ea1c44b37df94046e1eee790ad776
Author: Mike Crowe <mac@mcrowe.com>
Date: Mon Sep 9 14:16:16 2019 +0100

Intercept strncmp for glibc ld.so v2.28+
In glibc 5aad5f617892e75d91d4c8fb7594ff35b610c042 (first released in
v2.28) a call to strncmp was added to dl-load.c:is_dst. This causes
valgrind to complain about glibc's highly-optimised strncmp performing
sixteen-byte reads on short strings in ld.so. Let's intercept strncmp in
ld.so too so we use valgrind's simple version to avoid this problem.

diff --git a/shared/vg_replace_strmem.c b/shared/vg_replace_strmem.c
index 3b42b3a87..5396e83be 100644
--- a/shared/vg_replace_strmem.c
+++ b/shared/vg_replace_strmem.c
@@ -710,6 +710,8 @@ static inline void my_exit ( int x )
STRNCMP(VG_Z_LIBC_SONAME, __GI_strncmp)
STRNCMP(VG_Z_LIBC_SONAME, __strncmp_sse2)
STRNCMP(VG_Z_LIBC_SONAME, __strncmp_sse42)
+ STRNCMP(VG_Z_LD_LINUX_SO_2, strncmp)
+ STRNCMP(VG_Z_LD_LINUX_X86_64_SO_2, strncmp)
#elif defined(VGO_freebsd)
STRNCMP(VG_Z_LIBC_SONAME, strncmp)

231
SOURCES/valgrind-3.19.0-s390x-memmem.patch

@ -0,0 +1,231 @@ @@ -0,0 +1,231 @@
From 42ca1c480a5bca408a54c6a24d2be2c081d121ac Mon Sep 17 00:00:00 2001
From: Andreas Arnez <arnez@linux.ibm.com>
Date: Thu, 19 May 2022 13:54:06 +0200
Subject: [PATCH] Bug 454040 - Add intercept for memmem on s390x

Since memcheck may report false positives in an optimized version of memmem on
s390x, add an intercept for memmem on s390x platforms.
---
shared/vg_replace_strmem.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)

diff --git a/shared/vg_replace_strmem.c b/shared/vg_replace_strmem.c
index 5396e83be..d28e74206 100644
--- a/shared/vg_replace_strmem.c
+++ b/shared/vg_replace_strmem.c
@@ -103,6 +103,7 @@
20430 WMEMCHR
20440 WCSNLEN
20450 WSTRNCMP
+ 20460 MEMMEM
*/
#if defined(VGO_solaris)
@@ -1785,6 +1786,41 @@ static inline void my_exit ( int x )
#endif
+/*---------------------- memmem ----------------------*/
+
+#define MEMMEM(soname, fnname) \
+ void* VG_REPLACE_FUNCTION_EZU(20460,soname,fnname) \
+ (const void* haystack, SizeT hlen, const void* needle, SizeT nlen); \
+ void* VG_REPLACE_FUNCTION_EZU(20460,soname,fnname) \
+ (const void* haystack, SizeT hlen, const void* needle, SizeT nlen) \
+ { \
+ const HChar* h = haystack; \
+ const HChar* n = needle; \
+ \
+ /* If the needle is the empty string, match immediately. */ \
+ if (nlen == 0) return CONST_CAST(void *,h); \
+ \
+ HChar n0 = n[0]; \
+ \
+ for (; hlen >= nlen; hlen--, h++) { \
+ if (h[0] != n0) continue; \
+ \
+ UWord i; \
+ for (i = 1; i < nlen; i++) { \
+ if (n[i] != h[i]) \
+ break; \
+ } \
+ if (i == nlen) \
+ return CONST_CAST(HChar *,h); \
+ \
+ } \
+ return NULL; \
+ }
+
+#if defined(VGP_s390x_linux)
+ MEMMEM(VG_Z_LIBC_SONAME, memmem)
+#endif
+
/*---------------------- strpbrk ----------------------*/
--
2.31.1

From 4d675f309bcd2d4e9e2b9e6f4aba30f85116bb9b Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Thu, 19 May 2022 18:08:40 -0400
Subject: [PATCH] Add memmem memcheck tests

---
memcheck/tests/Makefile.am | 3 ++
memcheck/tests/filter_memmem | 5 ++
memcheck/tests/memmem.c | 81 ++++++++++++++++++++++++++++++++
memcheck/tests/memmem.stderr.exp | 2 +
memcheck/tests/memmem.vgtest | 3 ++
5 files changed, 94 insertions(+)
create mode 100755 memcheck/tests/filter_memmem
create mode 100644 memcheck/tests/memmem.c
create mode 100644 memcheck/tests/memmem.stderr.exp
create mode 100644 memcheck/tests/memmem.vgtest

diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am
index eb9487272..4d181c1ac 100644
--- a/memcheck/tests/Makefile.am
+++ b/memcheck/tests/Makefile.am
@@ -79,6 +79,7 @@ dist_noinst_SCRIPTS = \
filter_strchr \
filter_varinfo3 \
filter_memcheck \
+ filter_memmem \
filter_overlaperror \
filter_malloc_free \
filter_sized_delete
@@ -220,6 +221,7 @@ EXTRA_DIST = \
memalign2.stderr.exp memalign2.vgtest \
memcmptest.stderr.exp memcmptest.stderr.exp2 \
memcmptest.stdout.exp memcmptest.vgtest \
+ memmem.stderr.exp memmem.vgtest \
mempool.stderr.exp mempool.vgtest \
mempool2.stderr.exp mempool2.vgtest \
metadata.stderr.exp metadata.stdout.exp metadata.vgtest \
@@ -417,6 +419,7 @@ check_PROGRAMS = \
malloc_usable malloc1 malloc2 malloc3 manuel1 manuel2 manuel3 \
match-overrun \
memalign_test memalign2 memcmptest mempool mempool2 mmaptest \
+ memmem \
mismatches new_override metadata \
nanoleak_supp nanoleak2 new_nothrow \
noisy_child \
diff --git a/memcheck/tests/filter_memmem b/memcheck/tests/filter_memmem
new file mode 100755
index 000000000..f4a40b2d1
--- /dev/null
+++ b/memcheck/tests/filter_memmem
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+# Too many memmem implementations and overrides.
+# So just keep the main file lines.
+./filter_stderr "$@" | grep " main (memmem.c:"
diff --git a/memcheck/tests/memmem.c b/memcheck/tests/memmem.c
new file mode 100644
index 000000000..d627076e3
--- /dev/null
+++ b/memcheck/tests/memmem.c
@@ -0,0 +1,81 @@
+#define _GNU_SOURCE
+#include <assert.h>
+#include <string.h>
+#include <stdlib.h>
+
+/* mallocs an mem block and fills it with A. A needs to be a zero
+ terminated string. The A string chars, minus the terminating zero
+ are copied into the returned mem block. */
+static void *
+create_mem (const char *a)
+{
+ size_t len = strlen (a);
+ void *mem = malloc (len);
+ memcpy (mem, a, len);
+ return mem;
+}
+
+int
+main ()
+{
+ char *haystack;
+ char *needle;
+
+ haystack = create_mem ("a");
+ needle = create_mem ("a");
+ assert (memmem (haystack, 0, needle, 0) == haystack);
+ assert (memmem (haystack, 1, needle, 0) == haystack);
+ assert (memmem (haystack, 0, needle, 1) == NULL);
+ assert (memmem (haystack, 1, needle, 1) == haystack);
+ free (haystack);
+ free (needle);
+
+ haystack = create_mem ("abc");
+ needle = create_mem ("bc");
+ assert (memmem (haystack, 3, needle, 0) == haystack);
+ assert (memmem (haystack, 3, needle, 2) == haystack + 1);
+ assert (memmem (haystack + 1, 2, needle, 2) == haystack + 1);
+ assert (memmem (haystack + 2, 1, needle, 2) == NULL);
+ free (haystack);
+ free (needle);
+
+ haystack = create_mem ("abcabcabc");
+ needle = create_mem ("bca");
+ assert (memmem (haystack, 9, needle, 3) == haystack + 1);
+ free (haystack);
+ free (needle);
+
+ haystack = create_mem ("abcabcabc");
+ needle = create_mem ("bcad");
+ assert (memmem (haystack, 9, needle, 4) == NULL);
+ free (haystack);
+ free (needle);
+
+ haystack = create_mem ("xxxxxxxxxxxxxxxxxABC");
+ needle = create_mem ("ABCD");
+ assert (memmem (haystack, 20, needle, 2) == haystack + 17);
+ assert (memmem (haystack + 3, 17, needle, 2) == haystack + 17);
+ assert (memmem (haystack + 15, 5, needle, 2) == haystack + 17);
+ assert (memmem (haystack, 20, needle, 3) == haystack + 17);
+ assert (memmem (haystack + 3, 17, needle, 3) == haystack + 17);
+ assert (memmem (haystack + 15, 5, needle, 3) == haystack + 17);
+ assert (memmem (haystack, 20, needle, 4) == NULL);
+ assert (memmem (haystack + 3, 5, needle, 4) == NULL);
+ assert (memmem (haystack + 15, 5, needle, 4) == NULL);
+ free (haystack);
+ free (needle);
+
+ haystack = malloc (1);
+ needle = create_mem ("a");
+ assert (memmem (haystack, 1, needle, 1) == NULL);
+ free (haystack);
+ free (needle);
+
+ haystack = create_mem ("A");
+ needle = malloc (1);
+ assert (memmem (haystack, 1, needle, 1) == NULL);
+ free (haystack);
+ free (needle);
+
+ return 0;
+}
diff --git a/memcheck/tests/memmem.stderr.exp b/memcheck/tests/memmem.stderr.exp
new file mode 100644
index 000000000..b4612fbd4
--- /dev/null
+++ b/memcheck/tests/memmem.stderr.exp
@@ -0,0 +1,2 @@
+ by 0x........: main (memmem.c:70)
+ by 0x........: main (memmem.c:76)
diff --git a/memcheck/tests/memmem.vgtest b/memcheck/tests/memmem.vgtest
new file mode 100644
index 000000000..6d12895df
--- /dev/null
+++ b/memcheck/tests/memmem.vgtest
@@ -0,0 +1,3 @@
+prog: memmem
+vgopts: -q
+stderr_filter: filter_memmem
--
2.18.4

103
SPECS/valgrind.spec

@ -1,12 +1,12 @@ @@ -1,12 +1,12 @@
%{?scl:%scl_package valgrind}

Summary: Tool for finding memory management bugs in programs
Summary: Dynamic analysis tools to detect memory or thread bugs and profile
Name: %{?scl_prefix}valgrind
Version: 3.18.1
Release: 9%{?dist}
Version: 3.19.0
Release: 3%{?dist}
Epoch: 1
License: GPLv2+
URL: http://www.valgrind.org/
URL: https://www.valgrind.org/

# Only necessary for RHEL, will be ignored on Fedora

@ -77,71 +77,19 @@ Source0: https://sourceware.org/pub/valgrind/valgrind-%{version}.tar.bz2 @@ -77,71 +77,19 @@ Source0: https://sourceware.org/pub/valgrind/valgrind-%{version}.tar.bz2
Patch1: valgrind-3.9.0-cachegrind-improvements.patch

# Make ld.so supressions slightly less specific.
Patch3: valgrind-3.9.0-ldso-supp.patch
Patch2: valgrind-3.9.0-ldso-supp.patch

# Add some stack-protector
Patch4: valgrind-3.16.0-some-stack-protector.patch
Patch3: valgrind-3.16.0-some-stack-protector.patch

# Add some -Wl,z,now.
Patch5: valgrind-3.16.0-some-Wl-z-now.patch
Patch4: valgrind-3.16.0-some-Wl-z-now.patch

# KDE#444495 dhat/tests/copy fails on s390x
Patch6: valgrind-3.18.1-dhat-tests-copy.patch
# KDE#434764 # iconv_open causes ld.so v2.28+ to execute optimised strncmp
Patch5: valgrind-3.19.0-ld-so-strncmp.patch

# KDE#444242 s390x: Sign-extend "relative long" offset in EXRL
Patch7: valgrind-3.18.1-s390x-EXRL.patch

# KDE#444571 - PPC, fix lxsibzx and lxsihzx
Patch8: valgrind-3.18.1-ppc64-lxsibzx-lxsihzx.patch

# commit ae8c6de01417023e78763de145b1c0e6ddd87277
# commit 3950c5d661ee09526cddcf24daf5fc22bc83f70c
# Fix for the prefixed stq instruction in PC relative mode.
# KDE#444836 pstq instruction for R=1 is not storing to the correct address
Patch9: valgrind-3.18.1-ppc-pstq.patch
Patch10: valgrind-3.18.1-ppc-pstq-tests.patch

# commit 64ab89162906d5b9e2de6c3afe476fec861ef7ec
# gdbserver_tests: Filter out glibc hwcaps libc.so
Patch11: valgrind-3.18.1-gdbserver_tests-hwcap.patch

# KDE#445184 Rust v0 symbol demangling is broken
Patch12: valgrind-3.18.1-rust-v0-demangle.patch

# KDE#445354 arm64 backend: incorrect code emitted for doubleword CAS
Patch13: valgrind-3.18.1-arm64-doubleword-cas.patch

# KDE#444399 arm64: unhandled instruction LD{,A}XP and ST{,L}XP
Patch14: valgrind-3.18.1-arm64-ldaxp-stlxp.patch

# KDE#445415 arm64 front end: alignment checks missing for atomic instructions.
Patch15: valgrind-3.18.1-arm64-atomic-align.patch

# commit 595341b150312d2407bd43304449bf39ec3e1fa8
# amd64 front end: add more spec rules
Patch16: valgrind-3.18.1-amd64-more-spec-rules.patch

# KDE#445504 Using C++ condition_variable results in bogus
# "mutex is locked simultaneously by two threads" warning
Patch17: valgrind-3.18.1-condvar.patch

# KDE#445668 Inline stack frame generation is broken for Rust binaries
Patch18: valgrind-3.18.1-demangle-namespace.patch

# KDE#405377 Handle new Linux kernel feature: Restartable Sequences ("rseq")
Patch19: valgrind-3.18.1-rseq-enosys.patch

# KDE#444481 gdb_server test failures on s390x
Patch20: valgrind-3.18.1-s390x-vdso.patch

# KDE#447995 Valgrind segfault on power10 due to hwcap checking code
Patch21: valgrind-3.18.1-ppc-hwcaps.patch

# KDE#447991 s390x: Valgrind indicates illegal instruction on wflrx
Patch22: valgrind-3.18.1-s390x-wflrx.patch

# KDE#449494 arm64: Mismatch detected between RDMA and atomics features
Patch23: valgrind-3.18.1-arm64-atomics-rdm.patch
# KDE#454040 s390x: False-positive memcheck:cond in memmem on arch13 systems
Patch6: valgrind-3.19.0-s390x-memmem.patch

BuildRequires: make
BuildRequires: glibc-devel
@ -272,32 +220,16 @@ Valgrind User Manual for details. @@ -272,32 +220,16 @@ Valgrind User Manual for details.
%setup -q -n %{?scl:%{pkg_name}}%{!?scl:%{name}}-%{version}

%patch1 -p1
%patch3 -p1
%patch2 -p1

# Old rhel gcc doesn't have -fstack-protector-strong.
%if 0%{?fedora} || 0%{?rhel} >= 7
%patch3 -p1
%patch4 -p1
%patch5 -p1
%endif

%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
%patch17 -p1
%patch18 -p1
%patch19 -p1
%patch20 -p1
%patch21 -p1
%patch22 -p1
%patch23 -p1

%build
# LTO triggers undefined symbols in valgrind. Valgrind has a --enable-lto
@ -527,6 +459,13 @@ fi @@ -527,6 +459,13 @@ fi
%endif

%changelog
* Wed May 25 2022 Mark Wielaard <mjw@redhat.com> - 3.19.0-3
- Add valgrind-3.19.0-s390x-memmem.patch
- Add valgrind-3.19.0-ld-so-strncmp.patch

* Tue Apr 19 2022 Mark Wielaard <mjw@redhat.com> - 3.19.0-1
- Upgrade to valgrind 3.19.0. Drop old patches.

* Thu Feb 10 2022 Mark Wielaard <mjw@redhat.com> - 3.18.1-9
- Add valgrind-3.18.1-arm64-atomics-rdm.patch


Loading…
Cancel
Save