Bug 493004 - amd64: Support lods rep prefixes
Summary: amd64: Support lods rep prefixes
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: vex (show other bugs)
Version: 3.23 GIT
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-09-12 06:36 UTC by Matt Borgerson
Modified: 2024-09-19 00:25 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Patch (1.56 KB, patch)
2024-09-12 06:36 UTC, Matt Borgerson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Borgerson 2024-09-12 06:36:32 UTC
Created attachment 173577 [details]
Patch

SUMMARY

Attached patch adds support for rep prefixes on the lods instruction.

STEPS TO REPRODUCE

Build and run https://github.com/qemu/qemu/blob/master/tests/tcg/i386/test-i386.c

OBSERVED RESULT

Instruction is not repeated as expected. See below:

```
$ diff <(./test-i386) <(~/valgrind-src/bin/valgrind ./test-i386)
==38992== Memcheck, a memory error detector
==38992== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==38992== Using Valgrind-3.24.0.GIT and LibVEX; rerun with -h for copyright info
==38992== Command: ./test-i386
==38992== 
==38992== 
==38992== HEAP SUMMARY:
==38992==     in use at exit: 0 bytes in 0 blocks
==38992==   total heap usage: 1 allocs, 1 frees, 4,096 bytes allocated
==38992== 
==38992== All heap blocks were freed -- no leaks are possible
==38992== 
==38992== For lists of detected and suppressed errors, rerun with: -s
==38992== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
9122,9225c9122,9225
...
< rep lodsb  ESI=00005e41fb9f5931 EDI=00005e41fb9f5930 EAX=1234fdb512345678 ECX=0000000000000000 EFL=0000
< rep lodsw  ESI=00005e41fb9f5942 EDI=00005e41fb9f5930 EAX=1234fdb512345678 ECX=0000000000000000 EFL=0000
< rep lodsl  ESI=00005e41fb9f5964 EDI=00005e41fb9f5930 EAX=0000000012345678 ECX=0000000000000000 EFL=0000
< rep lodsq  ESI=00005e41fb9f59a8 EDI=00005e41fb9f5930 EAX=1234fdb512345678 ECX=0000000000000000 EFL=0000
< rep lodsb  ESI=00005e41fb9f590f EDI=00005e41fb9f5930 EAX=1234fdb512345678 ECX=0000000000000000 EFL=0000
< rep lodsw  ESI=00005e41fb9f58fe EDI=00005e41fb9f5930 EAX=1234fdb512345678 ECX=0000000000000000 EFL=0000
< rep lodsl  ESI=00005e41fb9f58dc EDI=00005e41fb9f5930 EAX=0000000012345678 ECX=0000000000000000 EFL=0000
< rep lodsq  ESI=00005e41fb9f5898 EDI=00005e41fb9f5930 EAX=dddcdbdad9d8d7d6 ECX=0000000000000000 EFL=0000
---
> rep lodsb  ESI=0000000000127921 EDI=0000000000127930 EAX=1234fdb512345678 ECX=0000000000000011 EFL=0000
> rep lodsw  ESI=0000000000127922 EDI=0000000000127930 EAX=1234fdb512345678 ECX=0000000000000011 EFL=0000
> rep lodsl  ESI=0000000000127924 EDI=0000000000127930 EAX=0000000012345678 ECX=0000000000000011 EFL=0000
> rep lodsq  ESI=0000000000127928 EDI=0000000000127930 EAX=1234fdb512345678 ECX=0000000000000011 EFL=0000
> rep lodsb  ESI=000000000012791f EDI=0000000000127930 EAX=1234fdb512345678 ECX=0000000000000011 EFL=0000
> rep lodsw  ESI=000000000012791e EDI=0000000000127930 EAX=1234fdb512345678 ECX=0000000000000011 EFL=0000
> rep lodsl  ESI=000000000012791c EDI=0000000000127930 EAX=0000000012345678 ECX=0000000000000011 EFL=0000
> rep lodsq  ESI=0000000000127918 EDI=0000000000127930 EAX=1234fdb512345678 ECX=0000000000000011 EFL=0000
> movsb      ESI=0000000000127921 EDI=0000000000127931 EAX=1234fdb512345678 ECX=0000000000000011 EFL=0000
```

EXPECTED RESULT

lods should be executed repeatedly, with the values observed on the left of the diff (minus ASLR differences)

SOFTWARE/OS VERSIONS
Valgrind: VALGRIND_3_23_0-108-g5d404b97d

ADDITIONAL INFORMATION

Discovered via QEMU differential tests. A version of these tests, with these particular cases commented out, are in Valgrind at /VEX/test/test-amd64.c, but the test in Valgrind repo does not compile.
Comment 1 Paul Floyd 2024-09-16 07:28:24 UTC
Do any of these recent items occur in real world compiled code or are they all just from synthetic qemu testcases?
Comment 2 Matt Borgerson 2024-09-19 00:25:24 UTC
(In reply to Paul Floyd from comment #1)
> Do any of these recent items occur in real world compiled code or are they
> all just from synthetic qemu testcases?

Paul Floyd: The recent issues/patches I've posted to the Valgrind bug tracker were discovered after running [QEMU's unit tests](https://github.com/qemu/qemu/blob/master/tests/tcg/i386/test-i386.c). I've not measured 'real world compiled code' prevalence for these items