Author: hans Date: Mon Feb 12 02:14:34 2018 New Revision: 324875 URL: http://llvm.org/viewvc/llvm-project?rev=324875&view=rev Log: Merging r324772: ------------------------------------------------------------------------ r324772 | thegameg | 2018-02-09 22:47:07 +0100 (Fri, 09 Feb 2018) | 25 lines
[X86][MC] Fix assembling rip-relative addressing + immediate displacements In the rare case where the input contains rip-relative addressing with immediate displacements, *and* the instruction ends with an immediate, we encode the instruction in the wrong way: movl $12345678, 0x400(%rdi) // all good, no rip-relative addr movl %eax, 0x400(%rip) // all good, no immediate at the end of the instruction movl $12345678, 0x400(%rip) // fails, encodes address as 0x3fc(%rip) Offset is a label: movl $12345678, foo(%rip) we want to account for the size of the immediate (in this case, $12345678, 4 bytes). Offset is an immediate: movl $12345678, 0x400(%rip) we should not account for the size of the immediate, assuming the immediate offset is what the user wanted. Differential Revision: https://reviews.llvm.org/D43050 ------------------------------------------------------------------------ Modified: llvm/branches/release_60/ (props changed) llvm/branches/release_60/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp llvm/branches/release_60/test/MC/X86/x86-64.s Propchange: llvm/branches/release_60/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Mon Feb 12 02:14:34 2018 @@ -1,3 +1,3 @@ /llvm/branches/Apple/Pertwee:110850,110961 /llvm/branches/type-system-rewrite:133420-134817 -/llvm/trunk:155241,321751,321789,321791,321806,321862,321870,321872,321878,321911,321980,321991,321993-321994,322003,322016,322053,322056,322103,322106,322108,322123,322131,322223,322272,322313,322372,322473,322623,322644,322724,322767,322875,322878-322879,322900,322904-322905,322973,322993,323034,323155,323190,323307,323331,323355,323369,323371,323384,323469,323515,323536,323582,323643,323671-323672,323706,323710,323759,323781,323810-323811,323813,323857,323907-323909,323913,323915,324002,324039,324422 +/llvm/trunk:155241,321751,321789,321791,321806,321862,321870,321872,321878,321911,321980,321991,321993-321994,322003,322016,322053,322056,322103,322106,322108,322123,322131,322223,322272,322313,322372,322473,322623,322644,322724,322767,322875,322878-322879,322900,322904-322905,322973,322993,323034,323155,323190,323307,323331,323355,323369,323371,323384,323469,323515,323536,323582,323643,323671-323672,323706,323710,323759,323781,323810-323811,323813,323857,323907-323909,323913,323915,324002,324039,324422,324772 Modified: llvm/branches/release_60/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp?rev=324875&r1=324874&r2=324875&view=diff ============================================================================== --- llvm/branches/release_60/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp (original) +++ llvm/branches/release_60/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp Mon Feb 12 02:14:34 2018 @@ -396,10 +396,14 @@ void X86MCCodeEmitter::emitMemModRMByte( // 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); Modified: llvm/branches/release_60/test/MC/X86/x86-64.s URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/test/MC/X86/x86-64.s?rev=324875&r1=324874&r2=324875&view=diff ============================================================================== --- llvm/branches/release_60/test/MC/X86/x86-64.s (original) +++ llvm/branches/release_60/test/MC/X86/x86-64.s Mon Feb 12 02:14:34 2018 @@ -622,6 +622,11 @@ movl $12, foo(%rip) // 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] _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits