| Summary: | amd64: `xchg ax, r16` mistakenly clears rax[63:16] | ||
|---|---|---|---|
| Product: | [Developer tools] valgrind | Reporter: | Matt Borgerson <contact> |
| Component: | vex | Assignee: | Paul Floyd <pjfloyd> |
| Status: | REPORTED --- | ||
| Severity: | normal | CC: | pjfloyd |
| Priority: | NOR | ||
| Version First Reported In: | 3.23 GIT | ||
| Target Milestone: | --- | ||
| Platform: | Other | ||
| OS: | All | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
| Attachments: |
Patch
Patch |
||
|
Description
Matt Borgerson
2024-09-09 21:59:22 UTC
Comment on attachment 173510 [details] Patch >From 2b3142152cfc315bbdcd504d5d7cdc0ddaeb9b27 Mon Sep 17 00:00:00 2001 >From: Matt Borgerson <contact@mborgerson.com> >Date: Mon, 9 Sep 2024 14:48:12 -0700 >Subject: [PATCH] codegen_xchg_rAX_Reg: Preserve RAX[63:16] in `xchg ax, r16` > >Unlike 32-bit xchg, 16-bit `xchg ax, r16` should not modify the upper 48 >bits of operand registers. Before this patch, RAX[63:16] will be cleared >in call to putIReg16 for RAX assignment. > >This patch reworks codegen_xchg_rAX_Reg to unify size handling and use >putIRegRAX to handle this size-dependent extension correctly. >--- > VEX/priv/guest_amd64_toIR.c | 29 ++++++----------------------- > 1 file changed, 6 insertions(+), 23 deletions(-) > >diff --git a/VEX/priv/guest_amd64_toIR.c b/VEX/priv/guest_amd64_toIR.c >index 57a8a434b..f6f8d4abe 100644 >--- a/VEX/priv/guest_amd64_toIR.c >+++ b/VEX/priv/guest_amd64_toIR.c >@@ -1152,13 +1152,6 @@ static IRExpr* getIReg16 ( UInt regno ) > Ity_I64 )); > } > >-static void putIReg16 ( UInt regno, IRExpr* e ) >-{ >- vassert(typeOfIRExpr(irsb->tyenv,e) == Ity_I16); >- stmt( IRStmt_Put( integerGuestReg64Offset(regno), >- unop(Iop_16Uto64,e) ) ); >-} >- > static const HChar* nameIReg16 ( UInt regno ) > { > return nameIReg( 2, regno, False ); >@@ -8485,22 +8478,12 @@ void codegen_xchg_rAX_Reg ( Prefix pfx, Int sz, UInt regLo3 ) > IRTemp t2 = newTemp(ty); > vassert(sz == 2 || sz == 4 || sz == 8); > vassert(regLo3 < 8); >- if (sz == 8) { >- assign( t1, getIReg64(R_RAX) ); >- assign( t2, getIRegRexB(8, pfx, regLo3) ); >- putIReg64( R_RAX, mkexpr(t2) ); >- putIRegRexB(8, pfx, regLo3, mkexpr(t1) ); >- } else if (sz == 4) { >- assign( t1, getIReg32(R_RAX) ); >- assign( t2, getIRegRexB(4, pfx, regLo3) ); >- putIReg32( R_RAX, mkexpr(t2) ); >- putIRegRexB(4, pfx, regLo3, mkexpr(t1) ); >- } else { >- assign( t1, getIReg16(R_RAX) ); >- assign( t2, getIRegRexB(2, pfx, regLo3) ); >- putIReg16( R_RAX, mkexpr(t2) ); >- putIRegRexB(2, pfx, regLo3, mkexpr(t1) ); >- } >+ >+ assign( t1, getIRegRAX(sz) ); >+ assign( t2, getIRegRexB(sz, pfx, regLo3) ); >+ putIRegRAX( sz, mkexpr(t2) ); >+ putIRegRexB( sz, pfx, regLo3, mkexpr(t1) ); >+ > DIP("xchg%c %s, %s\n", > nameISize(sz), nameIRegRAX(sz), > nameIRegRexB(sz,pfx, regLo3)); >-- >2.43.0 > The above commented patch revision fixes a typo in the commit message (`unifify` -> `unify`). Unfortunately it appears I cannot edit the comment to fix formatting. Created attachment 173545 [details]
Patch
|