Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: lib/Target/X86/MCTargetDesc/X86MCNaCl.cpp

Issue 1151093004: Changes from 3.7 merge to files not in upstream (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //=== X86MCNaCl.cpp - Expansion of NaCl pseudo-instructions --*- C++ -*-=// 1 //=== X86MCNaCl.cpp - Expansion of NaCl pseudo-instructions --*- C++ -*-=//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 //===----------------------------------------------------------------------===// 10 //===----------------------------------------------------------------------===//
(...skipping 30 matching lines...) Expand all
41 cl::init(true)); 41 cl::init(true));
42 42
43 const int kNaClX86InstructionBundleSize = 32; 43 const int kNaClX86InstructionBundleSize = 32;
44 44
45 // See the notes below where these functions are defined. 45 // See the notes below where these functions are defined.
46 namespace { 46 namespace {
47 unsigned getX86SubSuperRegister_(unsigned Reg, EVT VT, bool High=false); 47 unsigned getX86SubSuperRegister_(unsigned Reg, EVT VT, bool High=false);
48 unsigned DemoteRegTo32_(unsigned RegIn); 48 unsigned DemoteRegTo32_(unsigned RegIn);
49 } // namespace 49 } // namespace
50 50
51 static MCSymbol *CreateTempLabel(MCContext &Context, const char *Prefix) {
52 SmallString<128> NameSV;
53 raw_svector_ostream(NameSV)
54 << Context.getAsmInfo()->getPrivateGlobalPrefix() // get internal label
55 << Prefix << Context.getUniqueSymbolID();
56 return Context.GetOrCreateSymbol(NameSV);
57 }
58
59 static void PushReturnAddress(const llvm::MCSubtargetInfo &STI, 51 static void PushReturnAddress(const llvm::MCSubtargetInfo &STI,
60 MCContext &Context, MCStreamer &Out, 52 MCContext &Context, MCStreamer &Out,
61 MCSymbol *RetTarget) { 53 MCSymbol *RetTarget) {
62 const MCExpr *RetTargetExpr = MCSymbolRefExpr::Create(RetTarget, Context); 54 const MCExpr *RetTargetExpr = MCSymbolRefExpr::Create(RetTarget, Context);
63 if (Context.getObjectFileInfo()->getRelocM() == Reloc::PIC_) { 55 if (Context.getObjectFileInfo()->getRelocM() == Reloc::PIC_) {
64 // Calculate return_addr 56 // Calculate return_addr
65 // The return address should not be calculated into R11 because if the push 57 // The return address should not be calculated into R11 because if the push
66 // instruction ends up at the start of a bundle, an attacker could arrange 58 // instruction ends up at the start of a bundle, an attacker could arrange
67 // an indirect jump to it, which would push the full jump target 59 // an indirect jump to it, which would push the full jump target
68 // (which itself was calculated into r11) onto the stack. 60 // (which itself was calculated into r11) onto the stack.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // When generating PIC code, calculate the return address manually: 100 // When generating PIC code, calculate the return address manually:
109 // leal return_addr(%rip), %r10d 101 // leal return_addr(%rip), %r10d
110 // push %r10 102 // push %r10
111 // jmp target 103 // jmp target
112 // .align 32 104 // .align 32
113 // return_addr: 105 // return_addr:
114 106
115 MCContext &Context = Out.getContext(); 107 MCContext &Context = Out.getContext();
116 108
117 // Generate a label for the return address. 109 // Generate a label for the return address.
118 MCSymbol *RetTarget = CreateTempLabel(Context, "DirectCallRetAddr"); 110 MCSymbol *RetTarget = Context.createTempSymbol("DirectCallRetAddr", true);
119 111
120 PushReturnAddress(STI, Context, Out, RetTarget); 112 PushReturnAddress(STI, Context, Out, RetTarget);
121 113
122 // jmp target 114 // jmp target
123 MCInst JMPInst; 115 MCInst JMPInst;
124 JMPInst.setOpcode(X86::JMP_4); 116 JMPInst.setOpcode(X86::JMP_4);
125 JMPInst.addOperand(Op); 117 JMPInst.addOperand(Op);
126 Out.EmitInstruction(JMPInst, STI); 118 Out.EmitInstruction(JMPInst, STI);
127 119
128 Out.EmitCodeAlignment(kNaClX86InstructionBundleSize); 120 Out.EmitCodeAlignment(kNaClX86InstructionBundleSize);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 MCInst MOVInst; 190 MCInst MOVInst;
199 MOVInst.setOpcode(X86::MOV32rr); 191 MOVInst.setOpcode(X86::MOV32rr);
200 MOVInst.addOperand(MCOperand::CreateReg(SafeReg32)); 192 MOVInst.addOperand(MCOperand::CreateReg(SafeReg32));
201 MOVInst.addOperand(MCOperand::CreateReg(Reg32)); 193 MOVInst.addOperand(MCOperand::CreateReg(Reg32));
202 Out.EmitInstruction(MOVInst, STI); 194 Out.EmitInstruction(MOVInst, STI);
203 Reg32 = SafeReg32; 195 Reg32 = SafeReg32;
204 } 196 }
205 if (IsCall) { 197 if (IsCall) {
206 MCContext &Context = Out.getContext(); 198 MCContext &Context = Out.getContext();
207 // Generate a label for the return address. 199 // Generate a label for the return address.
208 RetTarget = CreateTempLabel(Context, "IndirectCallRetAddr"); 200 RetTarget = Context.createTempSymbol("IndirectCallRetAddr", true);
209 // Explicitly push the (32-bit) return address for a NaCl64 call 201 // Explicitly push the (32-bit) return address for a NaCl64 call
210 // instruction. 202 // instruction.
211 PushReturnAddress(STI, Context, Out, RetTarget); 203 PushReturnAddress(STI, Context, Out, RetTarget);
212 } 204 }
213 } 205 }
214 const unsigned Reg64 = getX86SubSuperRegister_(Reg32, MVT::i64); 206 const unsigned Reg64 = getX86SubSuperRegister_(Reg32, MVT::i64);
215 207
216 const bool WillEmitCallInst = IsCall && !HideSandboxBase; 208 const bool WillEmitCallInst = IsCall && !HideSandboxBase;
217 Out.EmitBundleLock(WillEmitCallInst); 209 Out.EmitBundleLock(WillEmitCallInst);
218 210
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 825
834 unsigned DemoteRegTo32_(unsigned RegIn) { 826 unsigned DemoteRegTo32_(unsigned RegIn) {
835 if (RegIn == 0) 827 if (RegIn == 0)
836 return 0; 828 return 0;
837 unsigned RegOut = getX86SubSuperRegister_(RegIn, MVT::i32, false); 829 unsigned RegOut = getX86SubSuperRegister_(RegIn, MVT::i32, false);
838 assert(RegOut != 0); 830 assert(RegOut != 0);
839 return RegOut; 831 return RegOut;
840 } 832 }
841 } //namespace 833 } //namespace
842 // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 834 // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698