forked from OSchip/llvm-project
implement the rest of correct x86-64 encoder support for
rip-relative addresses, and add a testcase. llvm-svn: 96040
This commit is contained in:
parent
626b79d6a6
commit
1e827fd8ca
|
@ -15,6 +15,7 @@
|
||||||
#include "X86.h"
|
#include "X86.h"
|
||||||
#include "X86InstrInfo.h"
|
#include "X86InstrInfo.h"
|
||||||
#include "llvm/MC/MCCodeEmitter.h"
|
#include "llvm/MC/MCCodeEmitter.h"
|
||||||
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/MC/MCInst.h"
|
#include "llvm/MC/MCInst.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
@ -36,10 +37,11 @@ class X86MCCodeEmitter : public MCCodeEmitter {
|
||||||
void operator=(const X86MCCodeEmitter &); // DO NOT IMPLEMENT
|
void operator=(const X86MCCodeEmitter &); // DO NOT IMPLEMENT
|
||||||
const TargetMachine &TM;
|
const TargetMachine &TM;
|
||||||
const TargetInstrInfo &TII;
|
const TargetInstrInfo &TII;
|
||||||
|
MCContext &Ctx;
|
||||||
bool Is64BitMode;
|
bool Is64BitMode;
|
||||||
public:
|
public:
|
||||||
X86MCCodeEmitter(TargetMachine &tm, bool is64Bit)
|
X86MCCodeEmitter(TargetMachine &tm, MCContext &ctx, bool is64Bit)
|
||||||
: TM(tm), TII(*TM.getInstrInfo()) {
|
: TM(tm), TII(*TM.getInstrInfo()), Ctx(ctx) {
|
||||||
Is64BitMode = is64Bit;
|
Is64BitMode = is64Bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,13 +124,13 @@ public:
|
||||||
MCCodeEmitter *llvm::createX86_32MCCodeEmitter(const Target &,
|
MCCodeEmitter *llvm::createX86_32MCCodeEmitter(const Target &,
|
||||||
TargetMachine &TM,
|
TargetMachine &TM,
|
||||||
MCContext &Ctx) {
|
MCContext &Ctx) {
|
||||||
return new X86MCCodeEmitter(TM, false);
|
return new X86MCCodeEmitter(TM, Ctx, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
MCCodeEmitter *llvm::createX86_64MCCodeEmitter(const Target &,
|
MCCodeEmitter *llvm::createX86_64MCCodeEmitter(const Target &,
|
||||||
TargetMachine &TM,
|
TargetMachine &TM,
|
||||||
MCContext &Ctx) {
|
MCContext &Ctx) {
|
||||||
return new X86MCCodeEmitter(TM, true);
|
return new X86MCCodeEmitter(TM, Ctx, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,7 +169,9 @@ EmitImmediate(const MCOperand &DispOp, unsigned Size, MCFixupKind FixupKind,
|
||||||
|
|
||||||
// If we have an immoffset, add it to the expression.
|
// If we have an immoffset, add it to the expression.
|
||||||
const MCExpr *Expr = DispOp.getExpr();
|
const MCExpr *Expr = DispOp.getExpr();
|
||||||
// FIXME: NO CONTEXT.
|
if (ImmOffset)
|
||||||
|
Expr = MCBinaryExpr::CreateAdd(Expr,MCConstantExpr::Create(ImmOffset, Ctx),
|
||||||
|
Ctx);
|
||||||
|
|
||||||
// Emit a symbolic constant as a fixup and 4 zeros.
|
// Emit a symbolic constant as a fixup and 4 zeros.
|
||||||
Fixups.push_back(MCFixup::Create(CurByte, Expr, FixupKind));
|
Fixups.push_back(MCFixup::Create(CurByte, Expr, FixupKind));
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
// RUN: llvm-mc -triple x86_64-unknown-unknown --show-encoding --enable-new-x86-encoder %s | FileCheck %s
|
||||||
|
|
||||||
|
movl foo(%rip), %eax
|
||||||
|
// CHECK: movl foo(%rip), %eax
|
||||||
|
// CHECK: encoding: [0x8b,0x05,A,A,A,A]
|
||||||
|
// CHECK: fixup A - offset: 2, value: foo, kind: reloc_riprel_4byte
|
||||||
|
|
||||||
|
movb $12, foo(%rip)
|
||||||
|
// CHECK: movb $12, foo(%rip)
|
||||||
|
// CHECK: encoding: [0xc6,0x05,A,A,A,A,B]
|
||||||
|
// CHECK: fixup A - offset: 2, value: foo-1, kind: reloc_riprel_4byte
|
||||||
|
// CHECK: fixup B - offset: 6, value: 12, kind: FK_Data_1
|
||||||
|
|
||||||
|
movw $12, foo(%rip)
|
||||||
|
// CHECK: movw $12, foo(%rip)
|
||||||
|
// CHECK: encoding: [0x66,0xc7,0x05,A,A,A,A,B,B]
|
||||||
|
// CHECK: fixup A - offset: 3, value: foo-2, kind: reloc_riprel_4byte
|
||||||
|
// CHECK: fixup B - offset: 7, value: 12, kind: FK_Data_2
|
||||||
|
|
||||||
|
movl $12, foo(%rip)
|
||||||
|
// CHECK: movl $12, foo(%rip)
|
||||||
|
// CHECK: encoding: [0xc7,0x05,A,A,A,A,B,B,B,B]
|
||||||
|
// CHECK: fixup A - offset: 2, value: foo-4, kind: reloc_riprel_4byte
|
||||||
|
// CHECK: fixup B - offset: 6, value: 12, kind: FK_Data_4
|
||||||
|
|
||||||
|
movq $12, foo(%rip)
|
||||||
|
// CHECK: movq $12, foo(%rip)
|
||||||
|
// CHECK: encoding: [0x48,0xc7,0x05,A,A,A,A,B,B,B,B]
|
||||||
|
// CHECK: fixup A - offset: 3, value: foo-4, kind: reloc_riprel_4byte
|
||||||
|
// CHECK: fixup B - offset: 7, value: 12, kind: FK_Data_4
|
Loading…
Reference in New Issue