[PATCH] D43050: [X86][MC] Fix assembling rip-relative addressing + immediate displacements

Francis Visoiu Mistrih via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 9 13:49:30 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL324772: [X86][MC] Fix assembling rip-relative addressing + immediate displacements (authored by thegameg, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43050?vs=133329&id=133680#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43050

Files:
  llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
  llvm/trunk/test/MC/X86/x86-64.s


Index: llvm/trunk/test/MC/X86/x86-64.s
===================================================================
--- llvm/trunk/test/MC/X86/x86-64.s
+++ llvm/trunk/test/MC/X86/x86-64.s
@@ -622,6 +622,11 @@
 // CHECK: encoding: [0xc7,0x05,A,A,A,A,0x0c,0x00,0x00,0x00]
 // CHECK:    fixup A - offset: 2, value: foo-8, kind: reloc_riprel_4byte
 
+// rdar://37247000
+movl	$12, 1024(%rip)
+// CHECK: movl	$12, 1024(%rip)
+// CHECK: encoding: [0xc7,0x05,0x00,0x04,0x00,0x00,0x0c,0x00,0x00,0x00]
+
 movq	$12, foo(%rip)
 // CHECK:  movq	$12, foo(%rip)
 // CHECK: encoding: [0x48,0xc7,0x05,A,A,A,A,0x0c,0x00,0x00,0x00]
Index: llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
===================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
@@ -396,10 +396,14 @@
 
     // rip-relative addressing is actually relative to the *next* instruction.
     // Since an immediate can follow the mod/rm byte for an instruction, this
-    // means that we need to bias the immediate field of the instruction with
-    // the size of the immediate field.  If we have this case, add it into the
+    // means that we need to bias the displacement field of the instruction with
+    // the size of the immediate field. If we have this case, add it into the
     // expression to emit.
-    int ImmSize = X86II::hasImm(TSFlags) ? X86II::getSizeOfImm(TSFlags) : 0;
+    // Note: rip-relative addressing using immediate displacement values should
+    // not be adjusted, assuming it was the user's intent.
+    int ImmSize = !Disp.isImm() && X86II::hasImm(TSFlags)
+                      ? X86II::getSizeOfImm(TSFlags)
+                      : 0;
 
     EmitImmediate(Disp, MI.getLoc(), 4, MCFixupKind(FixupKind),
                   CurByte, OS, Fixups, -ImmSize);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43050.133680.patch
Type: text/x-patch
Size: 1877 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180209/1b273c3b/attachment.bin>


More information about the llvm-commits mailing list