llvm.org GIT mirror llvm / 23a4885
[asan] Use MCInstrInfo in inline asm instrumentation. Patch by Yuri Gorshenin. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207115 91177308-0d34-0410-b5e6-96231b3b80d8 Evgeniy Stepanov 6 years ago
3 changed file(s) with 17 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
1414 #include "llvm/MC/MCContext.h"
1515 #include "llvm/MC/MCInst.h"
1616 #include "llvm/MC/MCInstBuilder.h"
17 #include "llvm/MC/MCInstrInfo.h"
1718 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
1819 #include "llvm/MC/MCStreamer.h"
1920 #include "llvm/MC/MCSubtargetInfo.h"
3940 // X86AsmInstrumentation implementation:
4041 virtual void InstrumentInstruction(
4142 const MCInst &Inst, SmallVectorImpl &Operands,
42 MCContext &Ctx, MCStreamer &Out) override {
43 InstrumentMOV(Inst, Operands, Ctx, Out);
43 MCContext &Ctx, const MCInstrInfo &MII, MCStreamer &Out) override {
44 InstrumentMOV(Inst, Operands, Ctx, MII, Out);
4445 }
4546
4647 // Should be implemented differently in x86_32 and x86_64 subclasses.
5253 bool IsWrite, MCContext &Ctx, MCStreamer &Out);
5354 void InstrumentMOV(const MCInst &Inst,
5455 SmallVectorImpl &Operands,
55 MCContext &Ctx, MCStreamer &Out);
56 MCContext &Ctx, const MCInstrInfo &MII, MCStreamer &Out);
5657 void EmitInstruction(MCStreamer &Out, const MCInst &Inst) {
5758 Out.EmitInstruction(Inst, STI);
5859 }
7879
7980 void X86AddressSanitizer::InstrumentMOV(
8081 const MCInst &Inst, SmallVectorImpl &Operands,
81 MCContext &Ctx, MCStreamer &Out) {
82 MCContext &Ctx, const MCInstrInfo &MII, MCStreamer &Out) {
8283 // Access size in bytes.
8384 unsigned AccessSize = 0;
8485
85 // FIXME: use MCInstrDesc to get proper value of IsWrite.
86 bool IsWrite = false;
8786 switch (Inst.getOpcode()) {
8887 case X86::MOV8mi:
8988 case X86::MOV8mr:
90 AccessSize = 1;
91 IsWrite = true;
92 break;
9389 case X86::MOV8rm:
9490 AccessSize = 1;
9591 break;
9692 case X86::MOV16mi:
9793 case X86::MOV16mr:
98 AccessSize = 2;
99 IsWrite = true;
100 break;
10194 case X86::MOV16rm:
10295 AccessSize = 2;
10396 break;
10497 case X86::MOV32mi:
10598 case X86::MOV32mr:
106 AccessSize = 4;
107 IsWrite = true;
108 break;
10999 case X86::MOV32rm:
110100 AccessSize = 4;
111101 break;
112102 case X86::MOV64mi32:
113103 case X86::MOV64mr:
114 AccessSize = 8;
115 IsWrite = true;
116 break;
117104 case X86::MOV64rm:
118105 AccessSize = 8;
119106 break;
120107 case X86::MOVAPDmr:
121108 case X86::MOVAPSmr:
122 AccessSize = 16;
123 IsWrite = true;
124 break;
125109 case X86::MOVAPDrm:
126110 case X86::MOVAPSrm:
127111 AccessSize = 16;
130114 return;
131115 }
132116
117 const bool IsWrite = MII.get(Inst.getOpcode()).mayStore();
133118 for (unsigned Ix = 0; Ix < Operands.size(); ++Ix) {
134119 MCParsedAsmOperand *Op = Operands[Ix];
135120 if (Op && Op->isMem())
218203
219204 void X86AsmInstrumentation::InstrumentInstruction(
220205 const MCInst &Inst, SmallVectorImpl &Operands,
221 MCContext &Ctx, MCStreamer &Out) {}
206 MCContext &Ctx, const MCInstrInfo &MII, MCStreamer &Out) {}
222207
223208 X86AsmInstrumentation *
224209 CreateX86AsmInstrumentation(const MCTargetOptions &MCOptions, const MCContext &Ctx,
1515
1616 class MCContext;
1717 class MCInst;
18 class MCInstrInfo;
1819 class MCParsedAsmOperand;
1920 class MCStreamer;
2021 class MCSubtargetInfo;
3435 // instruction is sent to Out.
3536 virtual void InstrumentInstruction(
3637 const MCInst &Inst, SmallVectorImpl &Operands,
37 MCContext &Ctx, MCStreamer &Out);
38 MCContext &Ctx,
39 const MCInstrInfo &MII,
40 MCStreamer &Out);
3841
3942 protected:
4043 friend X86AsmInstrumentation *
1919 #include "llvm/MC/MCContext.h"
2020 #include "llvm/MC/MCExpr.h"
2121 #include "llvm/MC/MCInst.h"
22 #include "llvm/MC/MCInstrInfo.h"
2223 #include "llvm/MC/MCParser/MCAsmLexer.h"
2324 #include "llvm/MC/MCParser/MCAsmParser.h"
2425 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
5455 class X86AsmParser : public MCTargetAsmParser {
5556 MCSubtargetInfo &STI;
5657 MCAsmParser &Parser;
58 const MCInstrInfo &MII;
5759 ParseInstructionInfo *InstInfo;
5860 std::unique_ptr Instrumentation;
5961 private:
709711
710712 public:
711713 X86AsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
712 const MCInstrInfo &MII,
714 const MCInstrInfo &mii,
713715 const MCTargetOptions &Options)
714 : MCTargetAsmParser(), STI(sti), Parser(parser), InstInfo(0) {
716 : MCTargetAsmParser(), STI(sti), Parser(parser), MII(mii), InstInfo(0) {
715717
716718 // Initialize the set of available features.
717719 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
22572259 void X86AsmParser::EmitInstruction(
22582260 MCInst &Inst, SmallVectorImpl &Operands,
22592261 MCStreamer &Out) {
2260 Instrumentation->InstrumentInstruction(Inst, Operands, getContext(), Out);
2262 Instrumentation->InstrumentInstruction(Inst, Operands, getContext(), MII,
2263 Out);
22612264 Out.EmitInstruction(Inst, STI);
22622265 }
22632266