Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceFixups.cpp - Implementation of Assembler Fixups -----===// | 1 //===- subzero/src/IceFixups.cpp - Implementation of Assembler Fixups -----===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 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 /// \file | 10 /// \file |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 const Assembler *Asm) const { | 33 const Assembler *Asm) const { |
| 34 std::string Buffer; | 34 std::string Buffer; |
| 35 llvm::raw_string_ostream Str(Buffer); | 35 llvm::raw_string_ostream Str(Buffer); |
| 36 const Constant *C = value_; | 36 const Constant *C = value_; |
| 37 assert(!isNullSymbol()); | 37 assert(!isNullSymbol()); |
| 38 if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(C)) { | 38 if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(C)) { |
| 39 if (CR->getSuppressMangling()) | 39 if (CR->getSuppressMangling()) |
| 40 Str << CR->getName(); | 40 Str << CR->getName(); |
| 41 else | 41 else |
| 42 Str << Ctx->mangleName(CR->getName()); | 42 Str << Ctx->mangleName(CR->getName()); |
| 43 if (Asm && !Asm->fixupIsPCRel(kind()) && Ctx->getFlags().getUseNonsfi()) { | 43 if (Asm && !Asm->fixupIsPCRel(kind()) && Ctx->getFlags().getUseNonsfi() && |
| 44 CR->getName() != GlobalOffsetTable) { | |
| 45 // TODO(jpp): remove the special GOT test. | |
| 44 Str << "@GOTOFF"; | 46 Str << "@GOTOFF"; |
| 45 } | 47 } |
| 46 } else { | 48 } else { |
| 47 // NOTE: currently only float/doubles are put into constant pools. In the | 49 // NOTE: currently only float/doubles are put into constant pools. In the |
| 48 // future we may put integers as well. | 50 // future we may put integers as well. |
| 49 assert(llvm::isa<ConstantFloat>(C) || llvm::isa<ConstantDouble>(C)); | 51 assert(llvm::isa<ConstantFloat>(C) || llvm::isa<ConstantDouble>(C)); |
| 50 C->emitPoolLabel(Str, Ctx); | 52 C->emitPoolLabel(Str, Ctx); |
| 51 } | 53 } |
| 52 return Str.str(); | 54 return Str.str(); |
| 53 } | 55 } |
| 54 | 56 |
| 55 size_t AssemblerFixup::emit(GlobalContext *Ctx, const Assembler &Asm) const { | 57 size_t AssemblerFixup::emit(GlobalContext *Ctx, const Assembler &Asm) const { |
| 56 static constexpr const size_t FixupSize = 4; | 58 static constexpr const size_t FixupSize = 4; |
| 57 if (!BuildDefs::dump()) | 59 if (!BuildDefs::dump()) |
| 58 return FixupSize; | 60 return FixupSize; |
| 59 Ostream &Str = Ctx->getStrEmit(); | 61 Ostream &Str = Ctx->getStrEmit(); |
| 60 Str << "\t.long "; | 62 Str << "\t.long "; |
| 61 if (isNullSymbol()) | 63 IceString Symbol; |
| 64 if (isNullSymbol()) { | |
| 62 Str << "__Sz_AbsoluteZero"; | 65 Str << "__Sz_AbsoluteZero"; |
| 63 else | 66 } else { |
| 64 Str << symbol(Ctx, &Asm); | 67 Symbol = symbol(Ctx, &Asm); |
| 65 RelocOffsetT Offset = Asm.load<RelocOffsetT>(position()); | 68 Str << Symbol; |
| 66 if (Offset) | 69 } |
| 67 Str << " + " << Offset; | 70 // The old behavior was x86 specific: emit expected a relocatable addend to |
| 68 // For PCRel fixups, we write the pc-offset from a symbol into the Buffer | 71 // "live" in the 4 bytes starting at position(). This is not portable (e.g., |
| 69 // (e.g., -4), but we don't represent that in the fixup's offset. Otherwise | 72 // ARM32 relocations are hardly ever 32-bits.) |
| 70 // the fixup holds the true offset, and so does the Buffer. Just load the | 73 // |
| 71 // offset from the buffer. | 74 // The new behavior: offset() contains the offset that used to be stored in |
| 72 if (Asm.fixupIsPCRel(kind())) | 75 // the instruction stream, so we use it instead of the value at |
| 76 // Asm.Buffer[position()]. | |
| 77 // | |
| 78 // We leave an assert behind to detect any uses that still write anything but | |
| 79 // a zero in the instruction stream. | |
| 80 // | |
| 81 // TODO(jpp): this behavior is also not portable. Ideally, X86 should define | |
| 82 // its own sets of relocatables, and define emit as it pleases. | |
| 83 assert(Asm.load<RelocOffsetT>(position()) == 0); | |
| 84 | |
| 85 RelocOffsetT Offset = offset(); | |
| 86 if (Offset != 0) { | |
| 87 if (Offset > 0) { | |
| 88 Str << " + "; | |
| 89 } | |
| 90 Str << Offset; | |
|
Karl
2016/02/03 21:03:05
This works, but is not obvious.
John
2016/02/03 21:25:20
Agreed, done.
| |
| 91 } | |
| 92 | |
| 93 // We need to emit the '- .' for PCRel fixups. Even if the relocation kind() | |
| 94 // is not PCRel, we emit the '- .' for the _GLOBAL_OFFSET_TABLE_. | |
| 95 // TODO(jpp): create fixups wrt the GOT with the right fixup kind. | |
| 96 if (Asm.fixupIsPCRel(kind()) || Symbol == GlobalOffsetTable) | |
| 73 Str << " - ."; | 97 Str << " - ."; |
| 74 Str << "\n"; | 98 Str << "\n"; |
| 75 return FixupSize; | 99 return FixupSize; |
| 76 } | 100 } |
| 77 | 101 |
| 102 void AssemblerFixup::emitOffset(Assembler *Asm) const { | |
| 103 Asm->store(position(), offset()); | |
| 104 } | |
| 105 | |
| 78 size_t AssemblerTextFixup::emit(GlobalContext *Ctx, const Assembler &) const { | 106 size_t AssemblerTextFixup::emit(GlobalContext *Ctx, const Assembler &) const { |
| 79 Ctx->getStrEmit() << Message << "\n"; | 107 Ctx->getStrEmit() << Message << "\n"; |
| 80 return NumBytes; | 108 return NumBytes; |
| 81 } | 109 } |
| 82 | 110 |
| 83 } // end of namespace Ice | 111 } // end of namespace Ice |
| OLD | NEW |