mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 11:42:57 +01:00
Clang-format over X86AsmInstrumentation.*.
llvm-svn: 216536
This commit is contained in:
parent
a051690c52
commit
b7f5d6f168
@ -48,26 +48,28 @@ public:
|
||||
virtual ~X86AddressSanitizer() {}
|
||||
|
||||
// X86AsmInstrumentation implementation:
|
||||
virtual void InstrumentAndEmitInstruction(
|
||||
const MCInst &Inst, OperandVector &Operands, MCContext &Ctx,
|
||||
const MCInstrInfo &MII, MCStreamer &Out) override {
|
||||
virtual void InstrumentAndEmitInstruction(const MCInst &Inst,
|
||||
OperandVector &Operands,
|
||||
MCContext &Ctx,
|
||||
const MCInstrInfo &MII,
|
||||
MCStreamer &Out) override {
|
||||
InstrumentMOVS(Inst, Operands, Ctx, MII, Out);
|
||||
if (RepPrefix)
|
||||
EmitInstruction(Out, MCInstBuilder(X86::REP_PREFIX));
|
||||
if (RepPrefix) EmitInstruction(Out, MCInstBuilder(X86::REP_PREFIX));
|
||||
|
||||
InstrumentMOV(Inst, Operands, Ctx, MII, Out);
|
||||
|
||||
RepPrefix = (Inst.getOpcode() == X86::REP_PREFIX);
|
||||
if (!RepPrefix)
|
||||
EmitInstruction(Out, Inst);
|
||||
if (!RepPrefix) EmitInstruction(Out, Inst);
|
||||
}
|
||||
|
||||
// Should be implemented differently in x86_32 and x86_64 subclasses.
|
||||
virtual void InstrumentMemOperandSmallImpl(
|
||||
X86Operand &Op, unsigned AccessSize, bool IsWrite, MCContext &Ctx,
|
||||
virtual void InstrumentMemOperandSmallImpl(X86Operand &Op,
|
||||
unsigned AccessSize, bool IsWrite,
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Out) = 0;
|
||||
virtual void InstrumentMemOperandLargeImpl(
|
||||
X86Operand &Op, unsigned AccessSize, bool IsWrite, MCContext &Ctx,
|
||||
virtual void InstrumentMemOperandLargeImpl(X86Operand &Op,
|
||||
unsigned AccessSize, bool IsWrite,
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Out) = 0;
|
||||
virtual void InstrumentMOVSImpl(unsigned AccessSize, MCContext &Ctx,
|
||||
MCStreamer &Out) = 0;
|
||||
@ -88,8 +90,9 @@ protected:
|
||||
bool RepPrefix;
|
||||
};
|
||||
|
||||
void X86AddressSanitizer::InstrumentMemOperand(
|
||||
MCParsedAsmOperand &Op, unsigned AccessSize, bool IsWrite, MCContext &Ctx,
|
||||
void X86AddressSanitizer::InstrumentMemOperand(MCParsedAsmOperand &Op,
|
||||
unsigned AccessSize,
|
||||
bool IsWrite, MCContext &Ctx,
|
||||
MCStreamer &Out) {
|
||||
assert(Op.isMem() && "Op should be a memory operand.");
|
||||
assert((AccessSize & (AccessSize - 1)) == 0 && AccessSize <= 16 &&
|
||||
@ -107,8 +110,9 @@ void X86AddressSanitizer::InstrumentMemOperand(
|
||||
InstrumentMemOperandLargeImpl(MemOp, AccessSize, IsWrite, Ctx, Out);
|
||||
}
|
||||
|
||||
void X86AddressSanitizer::InstrumentMOVSBase(
|
||||
unsigned DstReg, unsigned SrcReg, unsigned CntReg, unsigned AccessSize,
|
||||
void X86AddressSanitizer::InstrumentMOVSBase(unsigned DstReg, unsigned SrcReg,
|
||||
unsigned CntReg,
|
||||
unsigned AccessSize,
|
||||
MCContext &Ctx, MCStreamer &Out) {
|
||||
// FIXME: check whole ranges [DstReg .. DstReg + AccessSize * (CntReg - 1)]
|
||||
// and [SrcReg .. SrcReg + AccessSize * (CntReg - 1)].
|
||||
@ -149,9 +153,10 @@ void X86AddressSanitizer::InstrumentMOVSBase(
|
||||
}
|
||||
}
|
||||
|
||||
void X86AddressSanitizer::InstrumentMOVS(
|
||||
const MCInst &Inst, OperandVector &Operands, MCContext &Ctx,
|
||||
const MCInstrInfo &MII, MCStreamer &Out) {
|
||||
void X86AddressSanitizer::InstrumentMOVS(const MCInst &Inst,
|
||||
OperandVector &Operands,
|
||||
MCContext &Ctx, const MCInstrInfo &MII,
|
||||
MCStreamer &Out) {
|
||||
// Access size in bytes.
|
||||
unsigned AccessSize = 0;
|
||||
|
||||
@ -175,9 +180,10 @@ void X86AddressSanitizer::InstrumentMOVS(
|
||||
InstrumentMOVSImpl(AccessSize, Ctx, Out);
|
||||
}
|
||||
|
||||
void X86AddressSanitizer::InstrumentMOV(
|
||||
const MCInst &Inst, OperandVector &Operands, MCContext &Ctx,
|
||||
const MCInstrInfo &MII, MCStreamer &Out) {
|
||||
void X86AddressSanitizer::InstrumentMOV(const MCInst &Inst,
|
||||
OperandVector &Operands, MCContext &Ctx,
|
||||
const MCInstrInfo &MII,
|
||||
MCStreamer &Out) {
|
||||
// Access size in bytes.
|
||||
unsigned AccessSize = 0;
|
||||
|
||||
@ -216,8 +222,7 @@ void X86AddressSanitizer::InstrumentMOV(
|
||||
for (unsigned Ix = 0; Ix < Operands.size(); ++Ix) {
|
||||
assert(Operands[Ix]);
|
||||
MCParsedAsmOperand &Op = *Operands[Ix];
|
||||
if (Op.isMem())
|
||||
InstrumentMemOperand(Op, AccessSize, IsWrite, Ctx, Out);
|
||||
if (Op.isMem()) InstrumentMemOperand(Op, AccessSize, IsWrite, Ctx, Out);
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,11 +234,13 @@ public:
|
||||
: X86AddressSanitizer(STI) {}
|
||||
virtual ~X86AddressSanitizer32() {}
|
||||
|
||||
virtual void InstrumentMemOperandSmallImpl(
|
||||
X86Operand &Op, unsigned AccessSize, bool IsWrite, MCContext &Ctx,
|
||||
virtual void InstrumentMemOperandSmallImpl(X86Operand &Op,
|
||||
unsigned AccessSize, bool IsWrite,
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Out) override;
|
||||
virtual void InstrumentMemOperandLargeImpl(
|
||||
X86Operand &Op, unsigned AccessSize, bool IsWrite, MCContext &Ctx,
|
||||
virtual void InstrumentMemOperandLargeImpl(X86Operand &Op,
|
||||
unsigned AccessSize, bool IsWrite,
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Out) override;
|
||||
virtual void InstrumentMOVSImpl(unsigned AccessSize, MCContext &Ctx,
|
||||
MCStreamer &Out) override;
|
||||
@ -244,8 +251,10 @@ public:
|
||||
EmitInstruction(Out, MCInstBuilder(X86::CLD));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::MMX_EMMS));
|
||||
|
||||
EmitInstruction(Out, MCInstBuilder(X86::AND64ri8).addReg(X86::ESP)
|
||||
.addReg(X86::ESP).addImm(-16));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::AND64ri8)
|
||||
.addReg(X86::ESP)
|
||||
.addReg(X86::ESP)
|
||||
.addImm(-16));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::PUSH32r).addReg(AddressReg));
|
||||
|
||||
const std::string &Fn = FuncName(AccessSize, IsWrite);
|
||||
@ -256,8 +265,10 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void X86AddressSanitizer32::InstrumentMemOperandSmallImpl(
|
||||
X86Operand &Op, unsigned AccessSize, bool IsWrite, MCContext &Ctx,
|
||||
void X86AddressSanitizer32::InstrumentMemOperandSmallImpl(X86Operand &Op,
|
||||
unsigned AccessSize,
|
||||
bool IsWrite,
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Out) {
|
||||
EmitInstruction(Out, MCInstBuilder(X86::PUSH32r).addReg(X86::EAX));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::PUSH32r).addReg(X86::ECX));
|
||||
@ -274,8 +285,9 @@ void X86AddressSanitizer32::InstrumentMemOperandSmallImpl(
|
||||
|
||||
EmitInstruction(
|
||||
Out, MCInstBuilder(X86::MOV32rr).addReg(X86::ECX).addReg(X86::EAX));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::SHR32ri).addReg(X86::ECX)
|
||||
.addReg(X86::ECX).addImm(3));
|
||||
EmitInstruction(
|
||||
Out,
|
||||
MCInstBuilder(X86::SHR32ri).addReg(X86::ECX).addReg(X86::ECX).addImm(3));
|
||||
|
||||
{
|
||||
MCInst Inst;
|
||||
@ -296,8 +308,9 @@ void X86AddressSanitizer32::InstrumentMemOperandSmallImpl(
|
||||
|
||||
EmitInstruction(
|
||||
Out, MCInstBuilder(X86::MOV32rr).addReg(X86::EDX).addReg(X86::EAX));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::AND32ri).addReg(X86::EDX)
|
||||
.addReg(X86::EDX).addImm(7));
|
||||
EmitInstruction(
|
||||
Out,
|
||||
MCInstBuilder(X86::AND32ri).addReg(X86::EDX).addReg(X86::EDX).addImm(7));
|
||||
|
||||
switch (AccessSize) {
|
||||
case 1:
|
||||
@ -315,8 +328,10 @@ void X86AddressSanitizer32::InstrumentMemOperandSmallImpl(
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
EmitInstruction(Out, MCInstBuilder(X86::ADD32ri8).addReg(X86::EDX)
|
||||
.addReg(X86::EDX).addImm(3));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::ADD32ri8)
|
||||
.addReg(X86::EDX)
|
||||
.addReg(X86::EDX)
|
||||
.addImm(3));
|
||||
break;
|
||||
default:
|
||||
assert(false && "Incorrect access size");
|
||||
@ -338,8 +353,10 @@ void X86AddressSanitizer32::InstrumentMemOperandSmallImpl(
|
||||
EmitInstruction(Out, MCInstBuilder(X86::POP32r).addReg(X86::EAX));
|
||||
}
|
||||
|
||||
void X86AddressSanitizer32::InstrumentMemOperandLargeImpl(
|
||||
X86Operand &Op, unsigned AccessSize, bool IsWrite, MCContext &Ctx,
|
||||
void X86AddressSanitizer32::InstrumentMemOperandLargeImpl(X86Operand &Op,
|
||||
unsigned AccessSize,
|
||||
bool IsWrite,
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Out) {
|
||||
EmitInstruction(Out, MCInstBuilder(X86::PUSH32r).addReg(X86::EAX));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::PUSH32r).addReg(X86::ECX));
|
||||
@ -354,8 +371,9 @@ void X86AddressSanitizer32::InstrumentMemOperandLargeImpl(
|
||||
}
|
||||
EmitInstruction(
|
||||
Out, MCInstBuilder(X86::MOV32rr).addReg(X86::ECX).addReg(X86::EAX));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::SHR32ri).addReg(X86::ECX)
|
||||
.addReg(X86::ECX).addImm(3));
|
||||
EmitInstruction(
|
||||
Out,
|
||||
MCInstBuilder(X86::SHR32ri).addReg(X86::ECX).addReg(X86::ECX).addImm(3));
|
||||
{
|
||||
MCInst Inst;
|
||||
switch (AccessSize) {
|
||||
@ -388,8 +406,9 @@ void X86AddressSanitizer32::InstrumentMemOperandLargeImpl(
|
||||
EmitInstruction(Out, MCInstBuilder(X86::POP32r).addReg(X86::EAX));
|
||||
}
|
||||
|
||||
void X86AddressSanitizer32::InstrumentMOVSImpl(
|
||||
unsigned AccessSize, MCContext &Ctx, MCStreamer &Out) {
|
||||
void X86AddressSanitizer32::InstrumentMOVSImpl(unsigned AccessSize,
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Out) {
|
||||
EmitInstruction(Out, MCInstBuilder(X86::PUSHF32));
|
||||
|
||||
// No need to test when ECX is equals to zero.
|
||||
@ -415,11 +434,13 @@ public:
|
||||
: X86AddressSanitizer(STI) {}
|
||||
virtual ~X86AddressSanitizer64() {}
|
||||
|
||||
virtual void InstrumentMemOperandSmallImpl(
|
||||
X86Operand &Op, unsigned AccessSize, bool IsWrite, MCContext &Ctx,
|
||||
virtual void InstrumentMemOperandSmallImpl(X86Operand &Op,
|
||||
unsigned AccessSize, bool IsWrite,
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Out) override;
|
||||
virtual void InstrumentMemOperandLargeImpl(
|
||||
X86Operand &Op, unsigned AccessSize, bool IsWrite, MCContext &Ctx,
|
||||
virtual void InstrumentMemOperandLargeImpl(X86Operand &Op,
|
||||
unsigned AccessSize, bool IsWrite,
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Out) override;
|
||||
virtual void InstrumentMOVSImpl(unsigned AccessSize, MCContext &Ctx,
|
||||
MCStreamer &Out) override;
|
||||
@ -442,8 +463,10 @@ private:
|
||||
EmitInstruction(Out, MCInstBuilder(X86::CLD));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::MMX_EMMS));
|
||||
|
||||
EmitInstruction(Out, MCInstBuilder(X86::AND64ri8).addReg(X86::RSP)
|
||||
.addReg(X86::RSP).addImm(-16));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::AND64ri8)
|
||||
.addReg(X86::RSP)
|
||||
.addReg(X86::RSP)
|
||||
.addImm(-16));
|
||||
|
||||
const std::string &Fn = FuncName(AccessSize, IsWrite);
|
||||
MCSymbol *FnSym = Ctx.GetOrCreateSymbol(StringRef(Fn));
|
||||
@ -453,8 +476,10 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
void X86AddressSanitizer64::InstrumentMemOperandSmallImpl(
|
||||
X86Operand &Op, unsigned AccessSize, bool IsWrite, MCContext &Ctx,
|
||||
void X86AddressSanitizer64::InstrumentMemOperandSmallImpl(X86Operand &Op,
|
||||
unsigned AccessSize,
|
||||
bool IsWrite,
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Out) {
|
||||
EmitAdjustRSP(Ctx, Out, -128);
|
||||
EmitInstruction(Out, MCInstBuilder(X86::PUSH64r).addReg(X86::RAX));
|
||||
@ -470,8 +495,9 @@ void X86AddressSanitizer64::InstrumentMemOperandSmallImpl(
|
||||
}
|
||||
EmitInstruction(
|
||||
Out, MCInstBuilder(X86::MOV64rr).addReg(X86::RAX).addReg(X86::RDI));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::SHR64ri).addReg(X86::RAX)
|
||||
.addReg(X86::RAX).addImm(3));
|
||||
EmitInstruction(
|
||||
Out,
|
||||
MCInstBuilder(X86::SHR64ri).addReg(X86::RAX).addReg(X86::RAX).addImm(3));
|
||||
{
|
||||
MCInst Inst;
|
||||
Inst.setOpcode(X86::MOV8rm);
|
||||
@ -491,8 +517,9 @@ void X86AddressSanitizer64::InstrumentMemOperandSmallImpl(
|
||||
|
||||
EmitInstruction(
|
||||
Out, MCInstBuilder(X86::MOV32rr).addReg(X86::ECX).addReg(X86::EDI));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::AND32ri).addReg(X86::ECX)
|
||||
.addReg(X86::ECX).addImm(7));
|
||||
EmitInstruction(
|
||||
Out,
|
||||
MCInstBuilder(X86::AND32ri).addReg(X86::ECX).addReg(X86::ECX).addImm(7));
|
||||
|
||||
switch (AccessSize) {
|
||||
case 1:
|
||||
@ -510,8 +537,10 @@ void X86AddressSanitizer64::InstrumentMemOperandSmallImpl(
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
EmitInstruction(Out, MCInstBuilder(X86::ADD32ri8).addReg(X86::ECX)
|
||||
.addReg(X86::ECX).addImm(3));
|
||||
EmitInstruction(Out, MCInstBuilder(X86::ADD32ri8)
|
||||
.addReg(X86::ECX)
|
||||
.addReg(X86::ECX)
|
||||
.addImm(3));
|
||||
break;
|
||||
default:
|
||||
assert(false && "Incorrect access size");
|
||||
@ -534,8 +563,10 @@ void X86AddressSanitizer64::InstrumentMemOperandSmallImpl(
|
||||
EmitAdjustRSP(Ctx, Out, 128);
|
||||
}
|
||||
|
||||
void X86AddressSanitizer64::InstrumentMemOperandLargeImpl(
|
||||
X86Operand &Op, unsigned AccessSize, bool IsWrite, MCContext &Ctx,
|
||||
void X86AddressSanitizer64::InstrumentMemOperandLargeImpl(X86Operand &Op,
|
||||
unsigned AccessSize,
|
||||
bool IsWrite,
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Out) {
|
||||
EmitAdjustRSP(Ctx, Out, -128);
|
||||
EmitInstruction(Out, MCInstBuilder(X86::PUSH64r).addReg(X86::RAX));
|
||||
@ -548,8 +579,9 @@ void X86AddressSanitizer64::InstrumentMemOperandLargeImpl(
|
||||
Op.addMemOperands(Inst, 5);
|
||||
EmitInstruction(Out, Inst);
|
||||
}
|
||||
EmitInstruction(Out, MCInstBuilder(X86::SHR64ri).addReg(X86::RAX)
|
||||
.addReg(X86::RAX).addImm(3));
|
||||
EmitInstruction(
|
||||
Out,
|
||||
MCInstBuilder(X86::SHR64ri).addReg(X86::RAX).addReg(X86::RAX).addImm(3));
|
||||
{
|
||||
MCInst Inst;
|
||||
switch (AccessSize) {
|
||||
@ -583,8 +615,9 @@ void X86AddressSanitizer64::InstrumentMemOperandLargeImpl(
|
||||
EmitAdjustRSP(Ctx, Out, 128);
|
||||
}
|
||||
|
||||
void X86AddressSanitizer64::InstrumentMOVSImpl(
|
||||
unsigned AccessSize, MCContext &Ctx, MCStreamer &Out) {
|
||||
void X86AddressSanitizer64::InstrumentMOVSImpl(unsigned AccessSize,
|
||||
MCContext &Ctx,
|
||||
MCStreamer &Out) {
|
||||
EmitInstruction(Out, MCInstBuilder(X86::PUSHF64));
|
||||
|
||||
// No need to test when RCX is equals to zero.
|
||||
@ -620,9 +653,9 @@ void X86AsmInstrumentation::EmitInstruction(MCStreamer &Out,
|
||||
Out.EmitInstruction(Inst, STI);
|
||||
}
|
||||
|
||||
X86AsmInstrumentation *
|
||||
CreateX86AsmInstrumentation(const MCTargetOptions &MCOptions,
|
||||
const MCContext &Ctx, const MCSubtargetInfo &STI) {
|
||||
X86AsmInstrumentation *CreateX86AsmInstrumentation(
|
||||
const MCTargetOptions &MCOptions, const MCContext &Ctx,
|
||||
const MCSubtargetInfo &STI) {
|
||||
Triple T(STI.getTargetTriple());
|
||||
const bool hasCompilerRTSupport = T.isOSLinux();
|
||||
if (ClAsanInstrumentAssembly && hasCompilerRTSupport &&
|
||||
|
@ -26,9 +26,9 @@ class MCTargetOptions;
|
||||
|
||||
class X86AsmInstrumentation;
|
||||
|
||||
X86AsmInstrumentation *
|
||||
CreateX86AsmInstrumentation(const MCTargetOptions &MCOptions,
|
||||
const MCContext &Ctx, const MCSubtargetInfo &STI);
|
||||
X86AsmInstrumentation *CreateX86AsmInstrumentation(
|
||||
const MCTargetOptions &MCOptions, const MCContext &Ctx,
|
||||
const MCSubtargetInfo &STI);
|
||||
|
||||
class X86AsmInstrumentation {
|
||||
public:
|
||||
@ -41,9 +41,9 @@ public:
|
||||
MCContext &Ctx, const MCInstrInfo &MII, MCStreamer &Out);
|
||||
|
||||
protected:
|
||||
friend X86AsmInstrumentation *
|
||||
CreateX86AsmInstrumentation(const MCTargetOptions &MCOptions,
|
||||
const MCContext &Ctx, const MCSubtargetInfo &STI);
|
||||
friend X86AsmInstrumentation *CreateX86AsmInstrumentation(
|
||||
const MCTargetOptions &MCOptions, const MCContext &Ctx,
|
||||
const MCSubtargetInfo &STI);
|
||||
|
||||
X86AsmInstrumentation(const MCSubtargetInfo &STI);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user