]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
x86: Disallow instructions with length > 15 bytes
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 1 Feb 2024 22:42:08 +0000 (14:42 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 2 Feb 2024 12:36:27 +0000 (04:36 -0800)
commit46bd909328c3c8f3d6fc7a505b2fad1eea72d872
tree8afec2c4466447f2093cf08066b79ceeb66c5631
parent6a6744198309c2122fed4374b97ee170a3b2d3e2
x86: Disallow instructions with length > 15 bytes

It is a hard error when an instruction length exceeds the limit of 15
bytes:

[hjl@gnu-cfl-3 tmp]$ cat x.s
.text
xacquire lock addq $0x11223344, %fs:(,%eax)
[hjl@gnu-cfl-3 tmp]$ gcc -c x.s
x.s: Assembler messages:
x.s:2: Warning: instruction length of 16 bytes exceeds the limit of 15
[hjl@gnu-cfl-3 tmp]$ objdump -dw x.o

x.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <.text>:
   0: 64 67 f2 f0 48 81 04 05 00 00 00 00 44 33 22  xacquire lock (bad)
   f: 11                    .byte 0x11
[hjl@gnu-cfl-3 tmp]$

and

[hjl@gnu-cfl-3 tmp]$ cat z.s
addq $0xe0, %fs:0, %rdx
[hjl@gnu-cfl-3 tmp]$ as -o z.o z.s
z.s: Assembler messages:
z.s:1: Warning: instruction length of 16 bytes exceeds the limit of 15
[hjl@gnu-cfl-3 tmp]$ objdump -dw z.o

z.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <.text>:
   0: 64 62 f4 ec 18 81 04 25 00 00 00 00 e0 00 00  (bad)
...
[hjl@gnu-cfl-3 pr31323]$

Instructions with length > 15 bytes are always invalid.  It is quite easy
to generate invalid instructions with AVX now.  We should issue an error
when instruction length exceeds the limit of 15 bytes.

PR gas/31323
* config/tc-i386.c (output_insn): Issue an error when instruction
length exceeds the limit of 15 bytes.
* testsuite/gas/i386/oversized16.l: Updated.
* testsuite/gas/i386/oversized64.l: Likewise.
* testsuite/gas/i386/x86-64-apx-inval.l: New file.
* testsuite/gas/i386/x86-64-apx-inval.s: Likewise.
gas/config/tc-i386.c
gas/testsuite/gas/i386/oversized16.l
gas/testsuite/gas/i386/oversized64.l
gas/testsuite/gas/i386/x86-64-apx-inval.l [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64-apx-inval.s [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64.exp