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

Side by Side Diff: src/IceFixups.cpp

Issue 1669443002: Subzero. Uses fixups to calculate addend to relocations. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Addresses comments. Created 4 years, 10 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 //===- 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
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
Jim Stichnoth 2016/02/03 23:18:27 I don't think it makes sense to document old behav
John 2016/02/04 18:28:50 Comment removed. assert left behind with an error
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 << " + " << Offset;
89 } else {
90 assert(Offset != std::numeric_limits<RelocOffsetT>::lowest());
91 Str << " - " << -Offset;
92 }
93 }
94
95 // We need to emit the '- .' for PCRel fixups. Even if the relocation kind()
96 // is not PCRel, we emit the '- .' for the _GLOBAL_OFFSET_TABLE_.
97 // TODO(jpp): create fixups wrt the GOT with the right fixup kind.
98 if (Asm.fixupIsPCRel(kind()) || Symbol == GlobalOffsetTable)
73 Str << " - ."; 99 Str << " - .";
74 Str << "\n"; 100 Str << "\n";
75 return FixupSize; 101 return FixupSize;
76 } 102 }
77 103
104 void AssemblerFixup::emitOffset(Assembler *Asm) const {
105 Asm->store(position(), offset());
106 }
107
78 size_t AssemblerTextFixup::emit(GlobalContext *Ctx, const Assembler &) const { 108 size_t AssemblerTextFixup::emit(GlobalContext *Ctx, const Assembler &) const {
79 Ctx->getStrEmit() << Message << "\n"; 109 Ctx->getStrEmit() << Message << "\n";
80 return NumBytes; 110 return NumBytes;
81 } 111 }
82 112
83 } // end of namespace Ice 113 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698