From be56e836e3686c589414bc4465ecb3fe0cfbdd6561c51b4d888f179f3fa03258 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Tue, 6 Feb 2024 08:33:38 +0000 Subject: [PATCH] Accepting request 1144266 from devel:gcc:next - VEX-x86-nop-pattern.patch: bko#478624 - Valgrind incompatibility with binutils-2.42 on x86 with new nop patterns (unhandled instruction bytes: 0x2E 0x8D 0xB4 0x26) OBS-URL: https://build.opensuse.org/request/show/1144266 OBS-URL: https://build.opensuse.org/package/show/devel:tools/valgrind?expand=0&rev=277 --- VEX-x86-nop-pattern.patch | 136 ++++++++++++++++++++++++++++++++++++++ valgrind.changes | 7 ++ valgrind.spec | 4 +- 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 VEX-x86-nop-pattern.patch diff --git a/VEX-x86-nop-pattern.patch b/VEX-x86-nop-pattern.patch new file mode 100644 index 0000000..58bf947 --- /dev/null +++ b/VEX-x86-nop-pattern.patch @@ -0,0 +1,136 @@ +From d35005cef8ad8207542738812705ceabf137d7e0 Mon Sep 17 00:00:00 2001 +From: Paul Floyd +Date: Sun, 17 Dec 2023 14:18:51 +0100 +Subject: [PATCH] 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. +--- + .gitignore | 1 + + 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/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/valgrind.changes b/valgrind.changes index e79965d..8e48c0d 100644 --- a/valgrind.changes +++ b/valgrind.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Mon Feb 5 13:26:28 UTC 2024 - Andreas Schwab + +- VEX-x86-nop-pattern.patch: bko#478624 - Valgrind incompatibility with + binutils-2.42 on x86 with new nop patterns (unhandled instruction bytes: + 0x2E 0x8D 0xB4 0x26) + ------------------------------------------------------------------- Fri Nov 24 09:07:29 UTC 2023 - Dirk Müller diff --git a/valgrind.spec b/valgrind.spec index 93aa8b3..4a9b44c 100644 --- a/valgrind.spec +++ b/valgrind.spec @@ -1,7 +1,7 @@ # # spec file # -# Copyright (c) 2023 SUSE LLC +# Copyright (c) 2024 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -44,6 +44,8 @@ Patch1: VEX-x86-pinsrd.patch Patch2: armv6-support.diff Patch9: parallel-lto.patch Patch10: dhat-use-datadir.patch +# bko#478624 - Valgrind incompatibility with binutils-2.42 on x86 with new nop patterns (unhandled instruction bytes: 0x2E 0x8D 0xB4 0x26) +Patch11: VEX-x86-nop-pattern.patch BuildRequires: automake BuildRequires: pkgconfig %if %{suse_version} == 1600 && !0%{?is_opensuse}