[llvm] [llvm-ml] Fix RIP-relative addressing for ptr operands (PR #107618)
Eric Astor via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 9 06:51:36 PDT 2024
================
@@ -53,4 +53,10 @@ mov eax, [t8]
; CHECK-LABEL: t8:
; CHECK: mov eax, dword ptr [t8]
-END
\ No newline at end of file
+t9:
+mov eax, dword ptr [bar]
----------------
ericastor wrote:
Unfortunately, this appears accurate to how MASM actually works! Having run the following code through ml64.exe, I do reproduce the behavior shown in this change.
In particular, with `bar` being a label in the `.data` section:
```
t1:
mov eax, [bar]
```
compiles to an OBJ file that disassembles as:
```
0000000000000000 <.text$mn>:
0: 8b 05 00 00 00 00 movl (%rip), %eax # 0x6 <.text$mn+0x6>
0000000000000002: IMAGE_REL_AMD64_REL32 bar
```
while
```
t2:
mov eax, dword ptr [bar]
```
compiles to an OBJ file that disassembles as:
```
0000000000000000 <.text$mn>:
0: b8 00 00 00 00 movl $0x0, %eax
0000000000000001: IMAGE_REL_AMD64_ADDR32 bar
```
It seems MASM resolves `[bar]` as a relative offset in one case and a full address in the other. I can't entirely explain this, but it may be relevant that in MASM, `<type> PTR` is actually a cast operator. (https://learn.microsoft.com/en-us/cpp/assembler/masm/operator-ptr?view=msvc-170)
https://github.com/llvm/llvm-project/pull/107618
More information about the llvm-commits
mailing list