[X86AsmBackend] Provide diagnostic when immediate value too large for fixup
When .set follows the use, the compiler emits a fixup slot and then never fills it. If the order is reversed, the code compiles properly with a movabs. This was intentionally allowed previously to for compatibility with other assemblers (see: https://bugs.llvm.org/show_bug.cgi?id=10583), however GAS now emits a diagnostic for this case. MASM still does not. Given that the emitted code doesn't match the assembly, and given that the fixup is never resolved, emitting an error here would make sense. There's currently an assertion to catch this behavior, but most users won't see it.
$ clang --version | head -n1
clang version 20.0.0git ([email protected]:llvm/llvm-project.git def22f4e718daa74c2d0c03a32e32d4913a46278)
$ cat test.s
.intel_syntax noprefix
.code64
test_case:
mov rcx, EXAMPLE
.set EXAMPLE, (1ULL<<63ULL)
$ clang -c -o test.o test.s
$ llvm-objdump -d test.o
test.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <test_case>:
0: 48 8b 0c 25 00 00 00 00 movq 0x0, %rcx
$
@llvm/issue-subscribers-backend-x86
Author: Matthew Voss (ormris)
test.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <test_case>: 0: 48 8b 0c 25 00 00 00 00 movq 0x0, %rcx $
</details>
This is an issue within llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp applyFixup. The other most used targets have a range check.
In X86AsmBackend::applyFixup, the assert in the else branch is reachable for out-of-range fixup values and should be fixed. FK_Data_[1248] may have true of false PCRel, while other fixup kinds have a known PCRel value.
When IsResolved, we should add the reportError check for more fixup kinds, but should ensure every new case has test coverage.
Thanks! This is now fixed.