]> git.ipfire.org Git - thirdparty/gcc.git/commit
i386: Generate 3-byte NOP for -mnop-mcount -m16
authorMathias Krause <minipli@grsecurity.net>
Mon, 1 Dec 2025 19:31:53 +0000 (20:31 +0100)
committerUros Bizjak <ubizjak@gmail.com>
Wed, 3 Dec 2025 13:53:26 +0000 (14:53 +0100)
commit114a19fae9bdf07158b3c239a15ec78cfe5e2faf
tree2dbc01b4e0c3854475a6f11c53db08175d0808e2
parent413a7f7d934b70b4ee3e27cded5a0677d1eb574c
i386: Generate 3-byte NOP for -mnop-mcount -m16

When generating 16-bit code via -m16, the NOP mcount code generation
emits a 5-byte NOP. However, that is neither a valid i8086 instruction
(long NOPs are PentiumPro+), nor would it get decoded as a 5-byte
instruction. It's a 4-byte 'nopw 0(%si)' followed by a zero byte. The
latter causes the following instruction to get misinterpreted as some
form of ADD.

Fix this by emiting a 3-byte no-op 'lea 0(%si)' instead which makes it
compatible with systems lacking long NOP support.

Add a test for this and change the existing one accordingly.

gcc/ChangeLog:

* config/i386/i386.cc (x86_print_call_or_nop): Fix 16-bit NOP
generation.

gcc/testsuite/ChangeLog:

* gcc.target/i386/nop-mcount-m16.c: New test.
* gcc.target/i386/nop-mcount.c: Adapt to test for 5-byte NOP.

Signed-off-by: Mathias Krause <minipli@grsecurity.net>
gcc/config/i386/i386.cc
gcc/testsuite/gcc.target/i386/nop-mcount-m16.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/nop-mcount.c