target/x86: ENTER interprets first operand as signed
Host environment
- Operating system: NixOS 26.05
- OS/kernel version: Linux 7.2.8
- Architecture: x64
- QEMU flavor: qemu-x64_64
- QEMU version: 11.1.1 down to 9.1.0
- QEMU command line: (binary: see below)
qemu-x86_64 a.out
Emulated/Virtualized environment
- Operating system: none
- OS/kernel version: none
- Architecture: x86
Description of problem
A regression regarding the ENTER instruction was introduced in QEMU 9.1.0: The first operand (size of dynamic storage) is interpreted as signed instead of unsigned.
Steps to reproduce
Minimal test case:
#include <stdio.h>
int main(void) {
long int rsp_before, rsp_after;
asm volatile(
"mov %%rsp, %0\n"
"enter $0x8000, $0\n"
"mov %%rsp, %1\n"
"leave\n"
: "=r"(rsp_before), "=r"(rsp_after)
);
printf("difference in rsp: %lx\n", rsp_after - rsp_before);
}Output on host, and with QEMU 9.0.2 and before (correct):
$ ./a.out
difference in rsp: ffffffffffff7ff8Output on QEMU 9.1.0 up to 11.1.1 (latest at the time of writing):
$ ./a.out
difference in rsp: 7ff8To reproduce:
- Compile test case with
gcc file.c - Run natively or with old version of QEMU to observe correct output (
ffffffffffff7ff8) - Run with a more recent version of QEMU to observe incorrect output (
7ff8)