Closed
Description
Hello, we've identified a bug during our research and would like to report it. It appears that the following assembly code is being incorrectly assembled by clang (32-bit). Could you please investigate this? Thank you.
Assembly code (bug.s)
.intel_syntax noprefix
cmpbxadd DWORD PTR [1], EDI, EBP
cmplexadd DWORD PTR [1], EDI, EBP
cmplxadd DWORD PTR [1], EDI, EBP
cmpnbexadd DWORD PTR [1], EDI, EBP
cmpnbxadd DWORD PTR [1], EDI, EBP
cmpbexadd DWORD PTR [1], EDI, EBP
cmpnlxadd DWORD PTR [1], EDI, EBP
cmpnoxadd DWORD PTR [1], EDI, EBP
cmpnpxadd DWORD PTR [1], EDI, EBP
cmpnsxadd DWORD PTR [1], EDI, EBP
cmpnzxadd DWORD PTR [1], EDI, EBP
cmpoxadd DWORD PTR [1], EDI, EBP
cmppxadd DWORD PTR [1], EDI, EBP
cmpbexadd DWORD PTR [1], EDI, EBP
cmpsxadd DWORD PTR [1], EDI, EBP
cmpzxadd DWORD PTR [1], EDI, EBP
When I compile above code with x86 option, then clang assembler (v16.0.0) generates weird binary code as follows.
$ bin/clang -m32 -c bug.s -o bug_x86.o
$ bin/objdump -d bug_x86.o
bug_x86.o: file format elf32-i386
Disassembly of section .text:
00000000 <.text>:
0: c4 e2 51 e2 (bad)
4: 3d 01 00 00 00 cmp eax,0x1
9: c4 e2 51 ee (bad)
d: 3d 01 00 00 00 cmp eax,0x1
12: c4 e2 51 ec (bad)
16: 3d 01 00 00 00 cmp eax,0x1
1b: c4 e2 51 e7 (bad)
1f: 3d 01 00 00 00 cmp eax,0x1
24: c4 e2 51 e3 (bad)
28: 3d 01 00 00 00 cmp eax,0x1
2d: c4 e2 51 e6 (bad)
31: 3d 01 00 00 00 cmp eax,0x1
36: c4 e2 51 ed (bad)
3a: 3d 01 00 00 00 cmp eax,0x1
3f: c4 e2 51 e1 (bad)
43: 3d 01 00 00 00 cmp eax,0x1
48: c4 e2 51 eb (bad)
4c: 3d 01 00 00 00 cmp eax,0x1
51: c4 e2 51 e9 (bad)
55: 3d 01 00 00 00 cmp eax,0x1
5a: c4 e2 51 e5 (bad)
5e: 3d 01 00 00 00 cmp eax,0x1
63: c4 e2 51 e0 (bad)
67: 3d 01 00 00 00 cmp eax,0x1
6c: c4 e2 51 ea (bad)
70: 3d 01 00 00 00 cmp eax,0x1
75: c4 e2 51 e6 (bad)
79: 3d 01 00 00 00 cmp eax,0x1
7e: c4 e2 51 e8 (bad)
82: 3d 01 00 00 00 cmp eax,0x1
87: c4 e2 51 e4 (bad)
8b: 3d 01 00 00 00 cmp eax,0x1
Fortunately, it seems to function correctly when compiled with the x64 option.
$ bin/clang -c bug.s -o bin_x64.o
$ bin/objdump -d bin_x64.o
bin_x64.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <.text>:
0: c4 e2 51 e2 3c 25 01 cmpbxadd DWORD PTR ds:0x1,edi,ebp
7: 00 00 00
a: c4 e2 51 ee 3c 25 01 cmplexadd DWORD PTR ds:0x1,edi,ebp
11: 00 00 00
14: c4 e2 51 ec 3c 25 01 cmplxadd DWORD PTR ds:0x1,edi,ebp
1b: 00 00 00
1e: c4 e2 51 e7 3c 25 01 cmpnbexadd DWORD PTR ds:0x1,edi,ebp
25: 00 00 00
28: c4 e2 51 e3 3c 25 01 cmpnbxadd DWORD PTR ds:0x1,edi,ebp
2f: 00 00 00
32: c4 e2 51 e6 3c 25 01 cmpbexadd DWORD PTR ds:0x1,edi,ebp
39: 00 00 00
3c: c4 e2 51 ed 3c 25 01 cmpnlxadd DWORD PTR ds:0x1,edi,ebp
43: 00 00 00
46: c4 e2 51 e1 3c 25 01 cmpnoxadd DWORD PTR ds:0x1,edi,ebp
4d: 00 00 00
50: c4 e2 51 eb 3c 25 01 cmpnpxadd DWORD PTR ds:0x1,edi,ebp
57: 00 00 00
5a: c4 e2 51 e9 3c 25 01 cmpnsxadd DWORD PTR ds:0x1,edi,ebp
61: 00 00 00
64: c4 e2 51 e5 3c 25 01 cmpnzxadd DWORD PTR ds:0x1,edi,ebp
6b: 00 00 00
6e: c4 e2 51 e0 3c 25 01 cmpoxadd DWORD PTR ds:0x1,edi,ebp
75: 00 00 00
78: c4 e2 51 ea 3c 25 01 cmppxadd DWORD PTR ds:0x1,edi,ebp
7f: 00 00 00
82: c4 e2 51 e6 3c 25 01 cmpbexadd DWORD PTR ds:0x1,edi,ebp
89: 00 00 00
8c: c4 e2 51 e8 3c 25 01 cmpsxadd DWORD PTR ds:0x1,edi,ebp
93: 00 00 00
96: c4 e2 51 e4 3c 25 01 cmpzxadd DWORD PTR ds:0x1,edi,ebp
9d: 00 00 00