[all-commits] [llvm/llvm-project] 83680f: [X86AsmParser] Check displacement overflow (#75747)
Fangrui Song via All-commits
all-commits at lists.llvm.org
Mon Dec 18 13:49:59 PST 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 83680f8c5388d76c3f5b15cc9ad565b28c86af35
https://github.com/llvm/llvm-project/commit/83680f8c5388d76c3f5b15cc9ad565b28c86af35
Author: Fangrui Song <i at maskray.me>
Date: 2023-12-18 (Mon, 18 Dec 2023)
Changed paths:
M llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
A llvm/test/MC/X86/displacement-overflow.s
M llvm/test/MC/X86/x86-64.s
M llvm/test/MC/X86/x86_64-asm-match.s
M llvm/test/MC/X86/x86_64-encoding.s
Log Message:
-----------
[X86AsmParser] Check displacement overflow (#75747)
A displacement is an 8-, 16-, or 32-bit value.
LLVM integrated assembler silently encodes an out-of-range displacement.
GNU assembler checks the displacement and may report a warning or error
(error is for 64-bit addressing, done as part of
https://sourceware.org/PR10636).
```
movq 0x80000000(%rip), %rax
Error: 0x80000000 out of range of signed 32bit displacement
movq -0x080000001(%rax), %rax
Error: 0xffffffff7fffffff out of range of signed 32bit displacement
movl 0x100000001(%eax), %eax
Warning: 0x100000001 shortened to 0x1
```
For 32-bit addressing, GNU assembler gives no diagnostic when the
displacement is within `[-2**32,2**32)`. 16-bit addressing is similar.
```
movl 0xffffffff(%eax), %eax # no diagnostic
movl -0xffffffff(%eax), %eax # no diagnostic
```
Supporting a larger range is probably because wraparound using a large
constant is more reasonable. E.g. Linux kernel arch/x86/kernel/head_32.S
has `leal -__PAGE_OFFSET(%ecx),%esp` where `__PAGE_OFFSET` is
0xc0000000.
This patch implements a similar behavior.
More information about the All-commits
mailing list