commit:     6c34ec2caafeb7e0f53f76dc06b01b02f73ccbaa
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 22 13:11:13 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Jan 22 13:11:20 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6c34ec2c

dev-debug/valgrind: fix compat w/ upcoming binutils-2.42

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...nitor.py-regular-expressions-should-use-r.patch |   2 +-
 ...valgrind-3.22.0-fails-on-assertion-when-l.patch |   2 +-
 .../0003-Add-fchmodat2-syscall-on-linux.patch      |   2 +-
 ...Valgrind-incompatibility-with-binutils-2..patch | 151 ++++++++++++++++++++
 dev-debug/valgrind/valgrind-3.22.0-r2.ebuild       | 158 +++++++++++++++++++++
 5 files changed, 312 insertions(+), 3 deletions(-)

diff --git 
a/dev-debug/valgrind/files/0001-valgrind-monitor.py-regular-expressions-should-use-r.patch
 
b/dev-debug/valgrind/files/0001-valgrind-monitor.py-regular-expressions-should-use-r.patch
index cc51bc219456..70bd723855ad 100644
--- 
a/dev-debug/valgrind/files/0001-valgrind-monitor.py-regular-expressions-should-use-r.patch
+++ 
b/dev-debug/valgrind/files/0001-valgrind-monitor.py-regular-expressions-should-use-r.patch
@@ -1,7 +1,7 @@
 From 027b649fdb831868e71be01cafdacc49a5f419ab Mon Sep 17 00:00:00 2001
 From: Mark Wielaard <m...@klomp.org>
 Date: Fri, 17 Nov 2023 14:01:21 +0100
-Subject: [PATCH 1/3] valgrind-monitor.py regular expressions should use raw
+Subject: [PATCH 1/4] valgrind-monitor.py regular expressions should use raw
  strings
 
 With python 3.12 gdb will produce the following SyntaxWarning when

diff --git 
a/dev-debug/valgrind/files/0002-Bug-476548-valgrind-3.22.0-fails-on-assertion-when-l.patch
 
b/dev-debug/valgrind/files/0002-Bug-476548-valgrind-3.22.0-fails-on-assertion-when-l.patch
index 40885a04d850..df6250ea81db 100644
--- 
a/dev-debug/valgrind/files/0002-Bug-476548-valgrind-3.22.0-fails-on-assertion-when-l.patch
+++ 
b/dev-debug/valgrind/files/0002-Bug-476548-valgrind-3.22.0-fails-on-assertion-when-l.patch
@@ -1,7 +1,7 @@
 From 1d00e5ce0fb069911c4b525ec38289fb5d9021b0 Mon Sep 17 00:00:00 2001
 From: Paul Floyd <pjfl...@wanadoo.fr>
 Date: Sat, 18 Nov 2023 08:49:34 +0100
-Subject: [PATCH 2/3] Bug 476548 - valgrind 3.22.0 fails on assertion when
+Subject: [PATCH 2/4] Bug 476548 - valgrind 3.22.0 fails on assertion when
  loading debuginfo file produced by mold
 
 (cherry picked from commit 9ea4ae66707a4dcc6f4328e11911652e4418c585)

diff --git a/dev-debug/valgrind/files/0003-Add-fchmodat2-syscall-on-linux.patch 
b/dev-debug/valgrind/files/0003-Add-fchmodat2-syscall-on-linux.patch
index a65178a585f4..568cc5302b63 100644
--- a/dev-debug/valgrind/files/0003-Add-fchmodat2-syscall-on-linux.patch
+++ b/dev-debug/valgrind/files/0003-Add-fchmodat2-syscall-on-linux.patch
@@ -1,7 +1,7 @@
 From a43e62dddcf51ec6578a90c5988a41e856b44b05 Mon Sep 17 00:00:00 2001
 From: Mark Wielaard <m...@klomp.org>
 Date: Sat, 18 Nov 2023 21:17:02 +0100
-Subject: [PATCH 3/3] Add fchmodat2 syscall on linux
+Subject: [PATCH 3/4] Add fchmodat2 syscall on linux
 
 fchmodat2 is a new syscall on linux 6.6. It is a variant of fchmodat
 that takes an extra flags argument.

diff --git 
a/dev-debug/valgrind/files/0004-Bug-478624-Valgrind-incompatibility-with-binutils-2..patch
 
b/dev-debug/valgrind/files/0004-Bug-478624-Valgrind-incompatibility-with-binutils-2..patch
new file mode 100644
index 000000000000..a1413916ea73
--- /dev/null
+++ 
b/dev-debug/valgrind/files/0004-Bug-478624-Valgrind-incompatibility-with-binutils-2..patch
@@ -0,0 +1,151 @@
+From 41ff9aa49f6c54c66d0e6b37f265fd9cb0176057 Mon Sep 17 00:00:00 2001
+From: Paul Floyd <pjfl...@wanadoo.fr>
+Date: Sun, 17 Dec 2023 14:18:51 +0100
+Subject: [PATCH 4/4] Bug 478624 - Valgrind incompatibility with binutils-2.42
+ on x86 with new nop patterns (unhandled instruction bytes: 0x2E 0x8D 0xB4
+ 0x26)
+
+It was a bit of a struggle to get the testcase to build
+with both clang and gcc (oddly enough gcc was more difficult) so
+I just resorted to using .byte arrays.
+
+(cherry picked from commit d35005cef8ad8207542738812705ceabf137d7e0)
+---
+ NEWS                                       |  2 ++
+ VEX/priv/guest_x86_toIR.c                  | 22 +++++++++++++-
+ none/tests/x86/Makefile.am                 |  2 ++
+ none/tests/x86/gnu_binutils_nop.c          | 34 ++++++++++++++++++++++
+ none/tests/x86/gnu_binutils_nop.stderr.exp |  0
+ none/tests/x86/gnu_binutils_nop.vgtest     |  2 ++
+ 7 files changed, 62 insertions(+), 1 deletion(-)
+ create mode 100644 none/tests/x86/gnu_binutils_nop.c
+ create mode 100644 none/tests/x86/gnu_binutils_nop.stderr.exp
+ create mode 100644 none/tests/x86/gnu_binutils_nop.vgtest
+
+diff --git a/NEWS b/NEWS
+index da0f8c1aa..86b0fe6b5 100644
+--- a/NEWS
++++ b/NEWS
+@@ -9,6 +9,8 @@ The following bugs have been fixed or resolved on this branch.
+         file produced by mold
+ 476708  valgrind-monitor.py regular expressions should use raw strings
+ 477198  Add fchmodat2 syscall on linux
++478624  Valgrind incompatibility with binutils-2.42 on x86 with new nop 
patterns
++        (unhandled instruction bytes: 0x2E 0x8D 0xB4 0x26)
+ 
+ To see details of a given bug, visit
+   https://bugs.kde.org/show_bug.cgi?id=XXXXXX
+diff --git a/VEX/priv/guest_x86_toIR.c b/VEX/priv/guest_x86_toIR.c
+index 5d6e6dc64..3b6efb387 100644
+--- a/VEX/priv/guest_x86_toIR.c
++++ b/VEX/priv/guest_x86_toIR.c
+@@ -8198,7 +8198,7 @@ DisResult disInstr_X86_WRK (
+          delta += 5;
+          goto decode_success;
+       }
+-      /* Don't barf on recent binutils padding,
++      /* Don't barf on recent (2010) binutils padding,
+          all variants of which are: nopw %cs:0x0(%eax,%eax,1)
+          66 2e 0f 1f 84 00 00 00 00 00
+          66 66 2e 0f 1f 84 00 00 00 00 00
+@@ -8223,6 +8223,26 @@ DisResult disInstr_X86_WRK (
+          }
+       }
+ 
++      /* bug478624 GNU binutils uses a leal of esi into itself with
++         a zero offset and CS prefix as an 8 byte no-op (Dec 2023).
++         Since the CS prefix is hardly ever used we don't do much
++         to decode it, just a few cases for conditional branches.
++         So add handling here with other pseudo-no-ops.
++       */
++      if (code[0] == 0x2E && code[1] == 0x8D) {
++         if (code[2] == 0x74 && code[3] == 0x26 && code[4] == 0x00) {
++            DIP("leal %%cs:0(%%esi,%%eiz,1),%%esi\n");
++            delta += 5;
++            goto decode_success;
++         }
++         if (code[2] == 0xB4 && code[3] == 0x26 && code[4] == 0x00
++             && code[5] == 0x00 && code[6] == 0x00 && code[7] == 0x00) {
++            DIP("leal %%cs:0(%%esi,%%eiz,1),%%esi\n");
++            delta += 8;
++            goto decode_success;
++         }
++      }
++
+       // Intel CET requires the following opcodes to be treated as NOPs
+       // with any prefix and ModRM, SIB and disp combination:
+       // "0F 19", "0F 1C", "0F 1D", "0F 1E", "0F 1F"
+diff --git a/none/tests/x86/Makefile.am b/none/tests/x86/Makefile.am
+index 3ecd1ad3c..dbae86571 100644
+--- a/none/tests/x86/Makefile.am
++++ b/none/tests/x86/Makefile.am
+@@ -52,6 +52,7 @@ EXTRA_DIST = \
+       fxtract.stdout.exp fxtract.stderr.exp fxtract.vgtest \
+       fxtract.stdout.exp-older-glibc \
+       getseg.stdout.exp getseg.stderr.exp getseg.vgtest \
++      gnu_binutils_nop.stderr.exp gnu_binutils_nop.vgtest \
+       incdec_alt.stdout.exp incdec_alt.stderr.exp incdec_alt.vgtest \
+       int.stderr.exp int.stdout.exp int.disabled \
+       $(addsuffix .stderr.exp,$(INSN_TESTS)) \
+@@ -100,6 +101,7 @@ check_PROGRAMS = \
+       fpu_lazy_eflags \
+       fxtract \
+       getseg \
++      gnu_binutils_nop \
+       incdec_alt \
+       $(INSN_TESTS) \
+       int \
+diff --git a/none/tests/x86/gnu_binutils_nop.c 
b/none/tests/x86/gnu_binutils_nop.c
+new file mode 100644
+index 000000000..412a4c2cb
+--- /dev/null
++++ b/none/tests/x86/gnu_binutils_nop.c
+@@ -0,0 +1,34 @@
++int main(void)
++{
++    // GNU binutils uses various opcodes as alternatives for nop
++    // the idea is that it is faster to execute one large opcode
++    // with no side-effects than multiple repetitions of the
++    // single byte 'nop'. This gives more choice when code
++    // needs to be padded.
++   
++   // the following is based on
++   // https://sourceware.org/cgit/binutils-gdb/tree/gas/config/tc-i386.c#n1256
++
++    // one byte
++    __asm__ __volatile__("nop");
++    // two bytes
++    __asm__ __volatile__("xchg %ax,%ax");
++    // three bytes
++    //__asm__ __volatile__("leal 0(%esi),%esi");
++    __asm__ __volatile__(".byte 0x8d,0x76,0x00");
++    // four bytes
++    //__asm__ __volatile__("leal 0(%esi,%eiz),%esi");
++    __asm__ __volatile__(".byte 0x8d,0x74,0x26,0x00");
++    // five bytes
++    //__asm__ __volatile__("leal %cs:0(%esi,%eiz),%esi");
++    __asm__ __volatile__(".byte 0x2e,0x8d,0x74,0x26,0x00");
++    // six bytes
++    //__asm__ __volatile__("leal 0L(%esi),%esi");
++    __asm__ __volatile__(".byte 0x8d,0xb6,0x00,0x00,0x00,0x00");
++    // seven bytes
++    //__asm__ __volatile__("leal 0L(%esi,%eiz),%esi");
++    __asm__ __volatile__(".byte 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00");
++    // eight bytes
++    //__asm__ __volatile__("leal %cs:0L(%esi,%eiz),%esi");
++    __asm__ __volatile__(".byte 0x2e,0x8d,0xb4,0x26,0x00,0x00,0x00,0x00");
++}
+diff --git a/none/tests/x86/gnu_binutils_nop.stderr.exp 
b/none/tests/x86/gnu_binutils_nop.stderr.exp
+new file mode 100644
+index 000000000..e69de29bb
+diff --git a/none/tests/x86/gnu_binutils_nop.vgtest 
b/none/tests/x86/gnu_binutils_nop.vgtest
+new file mode 100644
+index 000000000..7f378dd53
+--- /dev/null
++++ b/none/tests/x86/gnu_binutils_nop.vgtest
+@@ -0,0 +1,2 @@
++prog: gnu_binutils_nop
++vgopts: -q
+-- 
+2.43.0
+

diff --git a/dev-debug/valgrind/valgrind-3.22.0-r2.ebuild 
b/dev-debug/valgrind/valgrind-3.22.0-r2.ebuild
new file mode 100644
index 000000000000..fd4c4cea5a1d
--- /dev/null
+++ b/dev-debug/valgrind/valgrind-3.22.0-r2.ebuild
@@ -0,0 +1,158 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+# The Valgrind upstream maintainer also maintains it in Fedora and will
+# backport fixes there which haven't yet made it into a release. Keep an eye
+# on it for fixes we should cherry-pick too:
+# https://src.fedoraproject.org/rpms/valgrind/tree/rawhide
+#
+# Also check the ${PV}_STABLE branch upstream for backports.
+
+inherit autotools flag-o-matic toolchain-funcs multilib pax-utils
+
+DESCRIPTION="An open-source memory debugger for GNU/Linux"
+HOMEPAGE="https://valgrind.org";
+if [[ ${PV} == 9999 ]]; then
+       EGIT_REPO_URI="https://sourceware.org/git/${PN}.git";
+       inherit git-r3
+else
+       VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/valgrind.gpg
+       inherit verify-sig
+
+       MY_P="${P/_rc/.RC}"
+       SRC_URI="https://sourceware.org/pub/valgrind/${MY_P}.tar.bz2";
+       SRC_URI+=" verify-sig? ( 
https://sourceware.org/pub/valgrind/${MY_P}.tar.bz2.asc )"
+       S="${WORKDIR}"/${MY_P}
+
+       if [[ ${PV} != *_rc* ]] ; then
+               KEYWORDS="-* ~amd64 ~arm ~arm64 ~ppc ~ppc64 ~x86 ~amd64-linux 
~x86-linux ~x64-macos ~x64-solaris"
+       fi
+fi
+
+LICENSE="GPL-2"
+SLOT="0"
+IUSE="mpi"
+
+DEPEND="mpi? ( virtual/mpi )"
+RDEPEND="${DEPEND}"
+if [[ ${PV} != 9999 ]] ; then
+       BDEPEND="verify-sig? ( sec-keys/openpgp-keys-valgrind )"
+fi
+
+PATCHES=(
+       # Respect CFLAGS, LDFLAGS
+       "${FILESDIR}"/${PN}-3.7.0-respect-flags.patch
+       "${FILESDIR}"/${PN}-3.15.0-Build-ldst_multiple-test-with-fno-pie.patch
+       "${FILESDIR}"/${PN}-3.21.0-glibc-2.34-suppressions.patch
+       # From stable branch
+       
"${FILESDIR}"/0001-valgrind-monitor.py-regular-expressions-should-use-r.patch
+       
"${FILESDIR}"/0002-Bug-476548-valgrind-3.22.0-fails-on-assertion-when-l.patch
+       "${FILESDIR}"/0003-Add-fchmodat2-syscall-on-linux.patch
+       
"${FILESDIR}"/0004-Bug-478624-Valgrind-incompatibility-with-binutils-2..patch
+)
+
+src_prepare() {
+       # Correct hard coded doc location
+       sed -i -e "s:doc/valgrind:doc/${PF}:" docs/Makefile.am || die
+
+       # Don't force multiarch stuff on OSX, bug #306467
+       sed -i -e 's:-arch \(i386\|x86_64\)::g' Makefile.all.am || die
+
+       if [[ ${CHOST} == *-solaris* ]] ; then
+               # upstream doesn't support this, but we don't build with
+               # Sun/Oracle ld, we have a GNU toolchain, so get some things
+               # working the Linux/GNU way
+               find "${S}" -name "Makefile.am" -o -name "Makefile.tool.am" | 
xargs \
+                       sed -i -e 
's:-M,/usr/lib/ld/map.noexstk:-z,noexecstack:' || die
+               cp "${S}"/coregrind/link_tool_exe_{linux,solaris}.in
+       fi
+
+       default
+
+       eautoreconf
+}
+
+src_configure() {
+       local myconf=(
+               --with-gdbscripts-dir="${EPREFIX}"/usr/share/gdb/auto-load
+       )
+
+       # Respect ar, bug #468114
+       tc-export AR
+
+       # -fomit-frame-pointer  "Assembler messages: Error: junk `8' after 
expression"
+       #                       while compiling insn_sse.c in none/tests/x86
+       # -fstack-protector     more undefined references to __guard and 
__stack_smash_handler
+       #                       because valgrind doesn't link to glibc (bug 
#114347)
+       # -fstack-protector-all    Fails same way as 
-fstack-protector/-fstack-protector-strong.
+       #                          Note: -fstack-protector-explicit is a no-op 
for Valgrind, no need to strip it
+       # -fstack-protector-strong See -fstack-protector (bug #620402)
+       # -m64 -mx32                    for multilib-portage, bug #398825
+       # -fharden-control-flow-redundancy: breaks runtime ('jump to the 
invalid address stated on the next line')
+       # -flto*                fails to build, bug #858509
+       filter-flags -fomit-frame-pointer
+       filter-flags -fstack-protector
+       filter-flags -fstack-protector-all
+       filter-flags -fstack-protector-strong
+       filter-flags -m64 -mx32
+       filter-flags -fsanitize -fsanitize=*
+       filter-flags -fharden-control-flow-redundancy
+       append-cflags $(test-flags-CC -fno-harden-control-flow-redundancy)
+       filter-lto
+
+       if use amd64 || use ppc64; then
+               ! has_multilib_profile && myconf+=("--enable-only64bit")
+       fi
+
+       # Force bitness on darwin, bug #306467
+       use x64-macos && myconf+=("--enable-only64bit")
+
+       # Don't use mpicc unless the user asked for it (bug #258832)
+       if ! use mpi; then
+               myconf+=("--without-mpicc")
+       fi
+
+       econf "${myconf[@]}"
+}
+
+src_test() {
+       # fxsave.o, tronical.o have textrels
+       emake LDFLAGS="${LDFLAGS} -Wl,-z,notext" check
+}
+
+src_install() {
+       default
+
+       if [[ ${PV} == "9999" ]]; then
+               # Otherwise FAQ.txt won't exist:
+               emake -C docs FAQ.txt
+               mv docs/FAQ.txt . || die "Couldn't move FAQ.txt"
+       fi
+
+       dodoc FAQ.txt
+
+       pax-mark m "${ED}"/usr/$(get_libdir)/valgrind/*-*-linux
+
+       # See README_PACKAGERS
+       dostrip -x /usr/libexec/valgrind/vgpreload* 
/usr/$(get_libdir)/valgrind/*
+
+       if [[ ${CHOST} == *-darwin* ]] ; then
+               # fix install_names on shared libraries, can't turn them into 
bundles,
+               # as dyld won't load them any more then, bug #306467
+               local l
+               for l in "${ED}"/usr/lib/valgrind/*.so ; do
+                       install_name_tool -id 
"${EPREFIX}"/usr/lib/valgrind/${l##*/} "${l}"
+               done
+       fi
+}
+
+pkg_postinst() {
+       elog "Valgrind will not work if libc (e.g. glibc) does not have debug 
symbols."
+       elog "To fix this you can add splitdebug to FEATURES in make.conf"
+       elog "and remerge glibc. See:"
+       elog "https://bugs.gentoo.org/214065";
+       elog "https://bugs.gentoo.org/274771";
+       elog "https://bugs.gentoo.org/388703";
+}

Reply via email to