Skip to content

[win/asan] GetInstructionSize: Add some more instructions. - #219038

Merged
zmodem merged 1 commit into
llvm:mainfrom
bernhardu:unhandled-instructions-2026-08-26
Aug 27, 2026
Merged

zmodem merged 1 commit into
llvm:mainfrom
bernhardu:unhandled-instructions-2026-08-26

Conversation

@bernhardu

Copy link
Copy Markdown
Contributor

These got reported in #96270.

  • Allow "0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]" for x86 and x86_64.
  • Add "0F B6 4C 24 XX : movzx ecx, byte ptr [esp + XX]"
  • Add "4F 8D 0C XX : lea r9, [...]"
  • Add "66 83 3A XX : cmp word ptr [rdx], XX"
  • Add "85 D2 : test edx, edx"
  • Add "8D 44 24 XX : lea eax, [esp + XX]"
  • Add "F3 0F 1E FA : endbr64"
  • Add "F3 0F 1E FB : endbr32"

These got reported in llvm#96270.

- Allow "0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]" for x86 and x86_64.
- Add "0F B6 4C 24 XX : movzx ecx, byte ptr [esp + XX]"
- Add "4F 8D 0C XX : lea r9, [...]"
- Add "66 83 3A XX : cmp word ptr [rdx], XX"
- Add "85 D2 : test edx, edx"
- Add "8D 44 24 XX : lea eax, [esp + XX]"
- Add "F3 0F 1E FA : endbr64"
- Add "F3 0F 1E FB : endbr32"
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Bernhard Übelacker (bernhardu)

Changes

These got reported in #96270.

  • Allow "0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]" for x86 and x86_64.
  • Add "0F B6 4C 24 XX : movzx ecx, byte ptr [esp + XX]"
  • Add "4F 8D 0C XX : lea r9, [...]"
  • Add "66 83 3A XX : cmp word ptr [rdx], XX"
  • Add "85 D2 : test edx, edx"
  • Add "8D 44 24 XX : lea eax, [esp + XX]"
  • Add "F3 0F 1E FA : endbr64"
  • Add "F3 0F 1E FB : endbr32"

Full diff: https://github.com/llvm/llvm-project/pull/219038.diff

2 Files Affected:

  • (modified) compiler-rt/lib/interception/interception_win.cpp (+9-5)
  • (modified) compiler-rt/lib/interception/tests/interception_win_test.cpp (+8-1)
diff --git a/compiler-rt/lib/interception/interception_win.cpp b/compiler-rt/lib/interception/interception_win.cpp
index 86a622ed48b50..b43776418f621 100644
--- a/compiler-rt/lib/interception/interception_win.cpp
+++ b/compiler-rt/lib/interception/interception_win.cpp
@@ -676,6 +676,7 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
     case 0xC084:  // 84 C0 : test al,al
     case 0xC984:  // 84 C9 : test cl,cl
     case 0xD284:  // 84 D2 : test dl,dl
+    case 0xD285:  // 85 D2 : test edx, edx
       return 2;
 
     case 0x3980:  // 80 39 XX : cmp BYTE PTR [rcx], XX
@@ -699,7 +700,9 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
   }
 
   switch (0x00FFFFFF & *(u32 *)address) {
+    case 0x24448D:  // 8D 44 24 XX : lea eax, [esp + XX]
     case 0x244C8D:  // 8D 4C 24 XX : lea ecx, [esp + XX]
+    case 0x3A8366:  // 66 83 3A XX : cmp word ptr [rdx], XX
     case 0x2474FF:  // FF 74 24 XX : push qword ptr [rsp + XX]
       return 4;
     case 0x24A48D:  // 8D A4 24 XX XX XX XX : lea esp, [esp + XX XX XX XX]
@@ -708,7 +711,12 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
 
   switch (*(u32*)(address)) {
     case 0xc0ef0f66:  // 66 0f ef c0 : pxor xmm0, xmm0
+    case 0xFA1E0FF3:  // F3 0F 1E FA : endbr64
+    case 0xFB1E0FF3:  // F3 0F 1E FB : endbr32
       return 4;
+    case 0x2444B60F:  // 0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]
+    case 0x244CB60F:  // 0F B6 4C 24 XX : movzx ecx, byte ptr [esp + XX]
+      return 5;
   }
 
   switch (0x000000FF & *(u32 *)address) {
@@ -885,6 +893,7 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
     case 0x488d49:    // 49 8d 48 XX : lea rcx, [...]
     case 0x048d4c:    // 4c 8d 04 XX : lea r8, [...]
     case 0x148d4e:    // 4e 8d 14 XX : lea r10, [...]
+    case 0x0C8D4F:    // 4F 8D 0C XX : lea r9, [...]
     case 0x398366:    // 66 83 39 XX : cmp WORD PTR [rcx], XX
       return 4;
 
@@ -1004,11 +1013,6 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
     case 0x247C8B:  // 8B 7C 24 XX : mov edi, dword ptr [esp + XX]
       return 4;
   }
-
-  switch (*(u32*)address) {
-    case 0x2444B60F:  // 0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]
-      return 5;
-  }
 #endif
 
   // Unknown instruction! This might happen when we add a new interceptor, use
diff --git a/compiler-rt/lib/interception/tests/interception_win_test.cpp b/compiler-rt/lib/interception/tests/interception_win_test.cpp
index 054d5405971dd..d3a52e9007b7a 100644
--- a/compiler-rt/lib/interception/tests/interception_win_test.cpp
+++ b/compiler-rt/lib/interception/tests/interception_win_test.cpp
@@ -852,6 +852,7 @@ const struct InstructionSizeData {
     { 2, {0x84, 0xC9}, 0, "84 C9 : test cl,cl"},
     { 2, {0x84, 0xD2}, 0, "84 D2 : test dl,dl"},
     { 2, {0x84, 0xDB}, 0, "84 DB : test bl,bl"},
+    { 2, {0x85, 0xD2}, 0, "85 D2 : test edx, edx"},
     { 2, {0x89, 0xc8}, 0, "89 C8 : mov eax, ecx"},
     { 2, {0x89, 0xD1}, 0, "89 D1 : mov ecx, edx"},
     { 2, {0x89, 0xE5}, 0, "89 E5 : mov ebp, esp"},
@@ -869,8 +870,14 @@ const struct InstructionSizeData {
     { 3, {0x8D, 0x45, 0x72}, 0, "8D 45 XX : lea eax, [ebp + XX]"},
     { 3, {0xc2, 0x71, 0x72}, 0, "C2 XX XX : ret XX (needed for registering weak functions)"},
     { 4, {0x66, 0x0f, 0xef, 0xc0}, 0, "66 0f ef c0 : pxor xmm0, xmm0"},
+    { 4, {0x66, 0x83, 0x3A, 0x73}, 0, "66 83 3A XX : cmp word ptr [rdx], XX"},
+    { 4, {0x8D, 0x44, 0x24, 0x73}, 0, "8D 44 24 XX : lea eax, [esp + XX]"},
     { 4, {0x8D, 0x4C, 0x24, 0x73}, 0, "8D 4C 24 XX : lea ecx, [esp + XX]"},
+    { 4, {0xF3, 0x0F, 0x1E, 0xFA}, 0, "F3 0F 1E FA : endbr64"},
+    { 4, {0xF3, 0x0F, 0x1E, 0xFB}, 0, "F3 0F 1E FB : endbr32"},
     { 4, {0xFF, 0x74, 0x24, 0x73}, 0, "FF 74 24 XX : push qword ptr [rsp + XX]"},
+    { 5, {0x0F, 0xB6, 0x44, 0x24, 0x74}, 0, "0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]"},
+    { 5, {0x0F, 0xB6, 0x4C, 0x24, 0x74}, 0, "0F B6 4C 24 XX : movzx ecx, byte ptr [esp + XX]"},
     { 5, {0x68, 0x71, 0x72, 0x73, 0x74}, 0, "68 XX XX XX XX : push imm32"},
     { 5, {0xb8, 0x71, 0x72, 0x73, 0x74}, 0, "b8 XX XX XX XX : mov eax, XX XX XX XX"},
     { 5, {0xB9, 0x71, 0x72, 0x73, 0x74}, 0, "b9 XX XX XX XX : mov ecx, XX XX XX XX"},
@@ -986,6 +993,7 @@ const struct InstructionSizeData {
     { 4, {0x49, 0x8d, 0x48, 0x73}, 0, "49 8d 48 XX : lea rcx, [...]"},
     { 4, {0x4c, 0x8d, 0x04, 0x73}, 0, "4c 8d 04 XX : lea r8, [...]"},
     { 4, {0x4e, 0x8d, 0x14, 0x73}, 0, "4e 8d 14 XX : lea r10, [...]"},
+    { 4, {0x4F, 0x8D, 0x0C, 0x73}, 0, "4F 8D 0C XX : lea r9, [...]"},
     { 4, {0x66, 0x83, 0x39, 0x73}, 0, "66 83 39 XX : cmp WORD PTR [rcx], XX"},
     { 4, {0x80, 0x78, 0x72, 0x73}, 0, "80 78 YY XX : cmp BYTE PTR [rax+YY], XX"},
     { 4, {0x80, 0x79, 0x72, 0x73}, 0, "80 79 YY XX : cmp BYTE ptr [rcx+YY], XX"},
@@ -1070,7 +1078,6 @@ const struct InstructionSizeData {
     { 4, {0x8B, 0x6C, 0x24, 0x73}, 0, "8B 6C 24 XX : mov ebp, dword ptr [esp + XX]"},
     { 4, {0x8B, 0x74, 0x24, 0x73}, 0, "8B 74 24 XX : mov esi, dword ptr [esp + XX]"},
     { 4, {0x8B, 0x7C, 0x24, 0x73}, 0, "8B 7C 24 XX : mov edi, dword ptr [esp + XX]"},
-    { 5, {0x0F, 0xB6, 0x44, 0x24, 0x74}, 0, "0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]"},
     { 5, {0xA1, 0x71, 0x72, 0x73, 0x74}, 0, "A1 XX XX XX XX : mov eax, dword ptr ds:[XXXXXXXX]"},
     { 6, {0xF7, 0xC1, 0x72, 0x73, 0x74, 0x75}, 0, "F7 C1 XX YY ZZ WW : test ecx, WWZZYYXX"},
     { 7, {0x83, 0x3D, 0x72, 0x73, 0x74, 0x75, 0x76}, 0, "83 3D XX YY ZZ WW TT : cmp TT, WWZZYYXX"},

@bernhardu

Copy link
Copy Markdown
Contributor Author

CC: @zmodem

Comment on lines +879 to +880
{ 5, {0x0F, 0xB6, 0x44, 0x24, 0x74}, 0, "0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]"},
{ 5, {0x0F, 0xB6, 0x4C, 0x24, 0x74}, 0, "0F B6 4C 24 XX : movzx ecx, byte ptr [esp + XX]"},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bernhardu the fifth element — 0x74 — does not seem right here, it would need to be 0x08 to match your comment #96270 (comment) and my findings in the same issue or be cut down to a four-byte sequence. I may be missing something. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @hartwork, thanks for taking a look. The last byte in this instruction is a variable value therefore the XX in 0F B6 44 24 XX. In the implementation only four bytes are matched, while the instruction has fife bytes.

See below examples, they give the same instruction, but the offset is different.

$ I="0F B6 44 24 08"
$ echo "$I" | sed 's/ /\n/g' | awk '{ printf "0x%s, ", $1 }' | llvm-mc-19 --disassemble --show-encoding --output-asm-variant=1 --arch=x86-64 | grep -v ".text"
        movzx   eax, byte ptr [rsp + 8]         # encoding: [0x0f,0xb6,0x44,0x24,0x08]
$ I="0F B6 44 24 74"
$ echo "$I" | sed 's/ /\n/g' | awk '{ printf "0x%s, ", $1 }' | llvm-mc-19 --disassemble --show-encoding --output-asm-variant=1 --arch=x86-64 | grep -v ".text"
        movzx   eax, byte ptr [rsp + 116]       # encoding: [0x0f,0xb6,0x44,0x24,0x74]

In the test I needed to use some value, therefore I used for such variable bytes a value of 0x70 plus the position, therefore 0x74.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bernhardu thanks for elaborating!

@zmodem zmodem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@zmodem
zmodem merged commit 7fd0dd8 into llvm:main Aug 27, 2026
15 checks passed
@bernhardu
bernhardu deleted the unhandled-instructions-2026-08-26 branch August 27, 2026 12:51
@bernhardu

Copy link
Copy Markdown
Contributor Author

Continuation from #214707.

If there are other PRs we should attempt to backport (or perhaps start with another one?) feel free to ping me there so we can get it done in the right sequence.

Hello @mstorsjo,
I think only this one would be also interesting to get backported after backporting #214707 is finished.

wlemkows pushed a commit to wlemkows/llvm-project that referenced this pull request Sep 4, 2026
These got reported in llvm#96270.

- Allow "0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]" for x86 and
x86_64.
- Add "0F B6 4C 24 XX : movzx ecx, byte ptr [esp + XX]"
- Add "4F 8D 0C XX : lea r9, [...]"
- Add "66 83 3A XX : cmp word ptr [rdx], XX"
- Add "85 D2 : test edx, edx"
- Add "8D 44 24 XX : lea eax, [esp + XX]"
- Add "F3 0F 1E FA : endbr64"
- Add "F3 0F 1E FB : endbr32"
asudarsa-qti pushed a commit to asudarsa-qti/llvm-project that referenced this pull request Sep 4, 2026
These got reported in llvm#96270.

- Allow "0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]" for x86 and
x86_64.
- Add "0F B6 4C 24 XX : movzx ecx, byte ptr [esp + XX]"
- Add "4F 8D 0C XX : lea r9, [...]"
- Add "66 83 3A XX : cmp word ptr [rdx], XX"
- Add "85 D2 : test edx, edx"
- Add "8D 44 24 XX : lea eax, [esp + XX]"
- Add "F3 0F 1E FA : endbr64"
- Add "F3 0F 1E FB : endbr32"
@mstorsjo mstorsjo added this to the LLVM 23.x Release milestone Sep 8, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in LLVM Release Status Sep 8, 2026
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in LLVM Release Status Sep 8, 2026
@mstorsjo

mstorsjo commented Sep 8, 2026

Copy link
Copy Markdown
Member

/cherry-pick 7fd0dd8

@llvmbot

llvmbot commented Sep 8, 2026

Copy link
Copy Markdown
Member

/pull-request #221969

dyung pushed a commit to llvmbot/llvm-project that referenced this pull request Sep 16, 2026
These got reported in llvm#96270.

- Allow "0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]" for x86 and
x86_64.
- Add "0F B6 4C 24 XX : movzx ecx, byte ptr [esp + XX]"
- Add "4F 8D 0C XX : lea r9, [...]"
- Add "66 83 3A XX : cmp word ptr [rdx], XX"
- Add "85 D2 : test edx, edx"
- Add "8D 44 24 XX : lea eax, [esp + XX]"
- Add "F3 0F 1E FA : endbr64"
- Add "F3 0F 1E FB : endbr32"

(cherry picked from commit 7fd0dd8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

5 participants