Skip to content

Commit 213c90d

Browse files
authored
[win/asan] GetInstructionSize: Fix 41 81 7c ... to return 9. (#117828)
Trying to populate the recently added test for GetInstructionSize I stumbled over this. gdb and bddisasm have the opinion this instruction is 9 bytes. Also lldb shows this: ``` (lldb) disassemble --bytes --start-address 0x0000555555556004 --end-address 0x0000555555556024 0x555555556004: 41 81 7b 73 74 75 76 77 cmpl $0x77767574, 0x73(%r11) ; imm = 0x77767574 0x55555555600c: 41 81 7c 73 74 75 76 77 78 cmpl $0x78777675, 0x74(%r11,%rsi,2) ; imm = 0x78777675 0x555555556015: 41 81 7d 73 74 75 76 77 cmpl $0x77767574, 0x73(%r13) ; imm = 0x77767574 0x55555555601d: 00 00 addb %al, (%rax) ``` There is also a handy tool in llvm to directly feed in the byte sequence - `41 81 7c` also uses 9 bytes here: ``` $ echo -n -e "0x41, 0x81, 0x7b, 0x73, 0x74, 0x75, 0x76, 0x77, 0x90" | ./llvm/build/bin/llvm-mc --disassemble --show-encoding .text cmpl $2004252020, 115(%r11) # encoding: [0x41,0x81,0x7b,0x73,0x74,0x75,0x76,0x77] # imm = 0x77767574 nop # encoding: [0x90] $ echo -n -e "0x41, 0x81, 0x7c, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x90" | ./llvm/build/bin/llvm-mc --disassemble --show-encoding .text cmpl $2021095029, 116(%r11,%rsi,2) # encoding: [0x41,0x81,0x7c,0x73,0x74,0x75,0x76,0x77,0x78] # imm = 0x78777675 nop # encoding: [0x90] ```
1 parent d5fe633 commit 213c90d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

compiler-rt/lib/interception/interception_win.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,6 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
808808
case 0x798141: // 41 81 79 XX YY YY YY YY : cmp DWORD PTR [r9+YY], XX XX XX XX
809809
case 0x7a8141: // 41 81 7a XX YY YY YY YY : cmp DWORD PTR [r10+YY], XX XX XX XX
810810
case 0x7b8141: // 41 81 7b XX YY YY YY YY : cmp DWORD PTR [r11+YY], XX XX XX XX
811-
case 0x7c8141: // 41 81 7c XX YY YY YY YY : cmp DWORD PTR [r12+YY], XX XX XX XX
812811
case 0x7d8141: // 41 81 7d XX YY YY YY YY : cmp DWORD PTR [r13+YY], XX XX XX XX
813812
case 0x7e8141: // 41 81 7e XX YY YY YY YY : cmp DWORD PTR [r14+YY], XX XX XX XX
814813
case 0x7f8141: // 41 81 7f YY XX XX XX XX : cmp DWORD PTR [r15+YY], XX XX XX XX
@@ -835,6 +834,10 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
835834
case 0x2444c7: // C7 44 24 XX YY YY YY YY
836835
// mov dword ptr [rsp + XX], YYYYYYYY
837836
return 8;
837+
838+
case 0x7c8141: // 41 81 7c ZZ YY XX XX XX XX
839+
// cmp DWORD PTR [reg+reg*n+YY], XX XX XX XX
840+
return 9;
838841
}
839842

840843
switch (*(u32*)(address)) {

compiler-rt/lib/interception/tests/interception_win_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ const struct InstructionSizeData {
989989
{ 8, {0x41, 0x81, 0x7f, 0x73, 0x74, 0x75, 0x76, 0x77}, 0, "41 81 7f YY XX XX XX XX : cmp DWORD PTR [r15+YY], XX XX XX XX"},
990990
{ 8, {0x81, 0x7c, 0x24, 0x73, 0x74, 0x75, 0x76, 0x77}, 0, "81 7c 24 YY XX XX XX XX : cmp DWORD PTR [rsp+YY], XX XX XX XX"},
991991
{ 8, {0xc7, 0x44, 0x24, 0x73, 0x74, 0x75, 0x76, 0x77}, 0, "C7 44 24 XX YY YY YY YY : mov dword ptr [rsp + XX], YYYYYYYY"},
992+
{ 9, {0x41, 0x81, 0x7c, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78}, 0, "41 81 7c ZZ YY XX XX XX XX : cmp DWORD PTR [reg+reg*n+YY], XX XX XX XX"},
992993
{ 9, {0xA1, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78}, 0, "A1 XX XX XX XX XX XX XX XX : movabs eax, dword ptr ds:[XXXXXXXX]"},
993994
#else
994995
// sorted list

0 commit comments

Comments
 (0)