Daniel Dunbar | 9faf273 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCStreamer.cpp - Streaming Machine Code Output --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 10 | #include "llvm/MC/MCStreamer.h" |
| 11 | #include "llvm/ADT/SmallString.h" |
| 12 | #include "llvm/ADT/Twine.h" |
Bill Wendling | 58e2d3d | 2013-09-09 02:37:14 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCAsmBackend.h" |
Rafael Espindola | 44bbe36 | 2010-12-06 17:27:56 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCAsmInfo.h" |
Rafael Espindola | c653a89 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCContext.h" |
Chris Lattner | 0c65fd4 | 2010-01-19 18:45:47 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCExpr.h" |
Pete Cooper | 81902a3 | 2015-05-15 22:19:42 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCInst.h" |
Colin LeMahieu | 48a9b71 | 2015-06-18 20:43:22 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCInstPrinter.h" |
Rafael Espindola | 61adb27 | 2014-01-24 02:42:26 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCObjectFileInfo.h" |
Kevin Enderby | e46564a | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCObjectWriter.h" |
Rafael Espindola | f1a13f5 | 2015-03-11 00:51:37 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCSection.h" |
Reid Kleckner | 97837b7 | 2016-05-02 23:22:18 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCSectionCOFF.h" |
Rafael Espindola | 27c0c9b | 2011-04-27 15:21:19 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCSymbol.h" |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCWin64EH.h" |
Reid Kleckner | 97837b7 | 2016-05-02 23:22:18 +0000 | [diff] [blame] | 25 | #include "llvm/Support/COFF.h" |
Rafael Espindola | 1614597 | 2010-11-01 14:28:48 +0000 | [diff] [blame] | 26 | #include "llvm/Support/ErrorHandling.h" |
Jim Grosbach | bf387df | 2012-08-08 23:56:06 +0000 | [diff] [blame] | 27 | #include "llvm/Support/LEB128.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 28 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 6ec72d2 | 2010-04-03 21:48:59 +0000 | [diff] [blame] | 29 | #include <cstdlib> |
Daniel Dunbar | 9faf273 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 32 | // Pin the vtables to this file. |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 33 | MCTargetStreamer::~MCTargetStreamer() {} |
Rafael Espindola | 24ea09e | 2014-01-26 06:06:37 +0000 | [diff] [blame] | 34 | |
| 35 | MCTargetStreamer::MCTargetStreamer(MCStreamer &S) : Streamer(S) { |
| 36 | S.setTargetStreamer(this); |
| 37 | } |
| 38 | |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 39 | void MCTargetStreamer::emitLabel(MCSymbol *Symbol) {} |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 40 | |
Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 41 | void MCTargetStreamer::finish() {} |
| 42 | |
Zoran Jovanovic | 28221d8 | 2014-03-20 09:44:49 +0000 | [diff] [blame] | 43 | void MCTargetStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {} |
| 44 | |
Rafael Espindola | 24ea09e | 2014-01-26 06:06:37 +0000 | [diff] [blame] | 45 | MCStreamer::MCStreamer(MCContext &Ctx) |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 46 | : Context(Ctx), CurrentWinFrameInfo(nullptr) { |
Peter Collingbourne | 2f495b9 | 2013-04-17 21:18:16 +0000 | [diff] [blame] | 47 | SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>()); |
Daniel Dunbar | 9faf273 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | MCStreamer::~MCStreamer() { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 51 | for (unsigned i = 0; i < getNumWinFrameInfos(); ++i) |
| 52 | delete WinFrameInfos[i]; |
Daniel Dunbar | 9faf273 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 53 | } |
Chris Lattner | 0c65fd4 | 2010-01-19 18:45:47 +0000 | [diff] [blame] | 54 | |
Pedro Artigas | 7212ee4 | 2012-12-12 22:59:46 +0000 | [diff] [blame] | 55 | void MCStreamer::reset() { |
Yaron Keren | 559b47d | 2014-09-17 09:25:36 +0000 | [diff] [blame] | 56 | DwarfFrameInfos.clear(); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 57 | for (unsigned i = 0; i < getNumWinFrameInfos(); ++i) |
| 58 | delete WinFrameInfos[i]; |
| 59 | WinFrameInfos.clear(); |
| 60 | CurrentWinFrameInfo = nullptr; |
Yaron Keren | d122211 | 2014-09-17 17:50:34 +0000 | [diff] [blame] | 61 | SymbolOrdering.clear(); |
Pedro Artigas | 7212ee4 | 2012-12-12 22:59:46 +0000 | [diff] [blame] | 62 | SectionStack.clear(); |
Peter Collingbourne | 2f495b9 | 2013-04-17 21:18:16 +0000 | [diff] [blame] | 63 | SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>()); |
Pedro Artigas | 7212ee4 | 2012-12-12 22:59:46 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Chris Lattner | 8fa0e35 | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 66 | raw_ostream &MCStreamer::GetCommentOS() { |
| 67 | // By default, discard comments. |
| 68 | return nulls(); |
| 69 | } |
| 70 | |
Rafael Espindola | 0b69481 | 2014-01-16 16:28:37 +0000 | [diff] [blame] | 71 | void MCStreamer::emitRawComment(const Twine &T, bool TabPrefix) {} |
| 72 | |
Nirav Dave | 53a72f4 | 2016-07-11 12:42:14 +0000 | [diff] [blame] | 73 | void MCStreamer::addExplicitComment(const Twine &T) {} |
| 74 | void MCStreamer::emitExplicitComments() {} |
| 75 | |
Bill Wendling | 550c76d | 2013-09-09 19:48:37 +0000 | [diff] [blame] | 76 | void MCStreamer::generateCompactUnwindEncodings(MCAsmBackend *MAB) { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 77 | for (auto &FI : DwarfFrameInfos) |
| 78 | FI.CompactUnwindEncoding = |
| 79 | (MAB ? MAB->generateCompactUnwindEncoding(FI.Instructions) : 0); |
Bill Wendling | 58e2d3d | 2013-09-09 02:37:14 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Chris Lattner | dc50e5d | 2010-01-19 22:03:38 +0000 | [diff] [blame] | 82 | /// EmitIntValue - Special case of EmitValue that avoids the client having to |
| 83 | /// pass in a MCExpr for constant integers. |
Rafael Espindola | 64e1af8 | 2013-07-02 15:49:13 +0000 | [diff] [blame] | 84 | void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size) { |
Alexey Samsonov | e5864c6 | 2014-08-20 22:46:38 +0000 | [diff] [blame] | 85 | assert(1 <= Size && Size <= 8 && "Invalid size"); |
Matt Beaumont-Gay | f991d4f | 2010-12-15 23:14:45 +0000 | [diff] [blame] | 86 | assert((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) && |
| 87 | "Invalid size"); |
Rafael Espindola | 4c70eea | 2010-12-03 02:54:21 +0000 | [diff] [blame] | 88 | char buf[8]; |
Bill Wendling | bc07a89 | 2013-06-18 07:20:20 +0000 | [diff] [blame] | 89 | const bool isLittleEndian = Context.getAsmInfo()->isLittleEndian(); |
Roman Divacky | 384ffa9 | 2011-06-07 17:31:02 +0000 | [diff] [blame] | 90 | for (unsigned i = 0; i != Size; ++i) { |
| 91 | unsigned index = isLittleEndian ? i : (Size - i - 1); |
| 92 | buf[i] = uint8_t(Value >> (index * 8)); |
| 93 | } |
Rafael Espindola | 64e1af8 | 2013-07-02 15:49:13 +0000 | [diff] [blame] | 94 | EmitBytes(StringRef(buf, Size)); |
Chris Lattner | dc50e5d | 2010-01-19 22:03:38 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Rafael Espindola | 5e87498 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 97 | /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the |
| 98 | /// client having to pass in a MCExpr for constant integers. |
Rafael Espindola | 64e1af8 | 2013-07-02 15:49:13 +0000 | [diff] [blame] | 99 | void MCStreamer::EmitULEB128IntValue(uint64_t Value, unsigned Padding) { |
Benjamin Kramer | 00b679c | 2012-02-23 21:15:21 +0000 | [diff] [blame] | 100 | SmallString<128> Tmp; |
Rafael Espindola | 675fbb2 | 2010-12-03 01:19:49 +0000 | [diff] [blame] | 101 | raw_svector_ostream OSE(Tmp); |
Jim Grosbach | bf387df | 2012-08-08 23:56:06 +0000 | [diff] [blame] | 102 | encodeULEB128(Value, OSE, Padding); |
Rafael Espindola | 64e1af8 | 2013-07-02 15:49:13 +0000 | [diff] [blame] | 103 | EmitBytes(OSE.str()); |
Kevin Enderby | e46564a | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Rafael Espindola | 5e87498 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 106 | /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the |
| 107 | /// client having to pass in a MCExpr for constant integers. |
Rafael Espindola | 64e1af8 | 2013-07-02 15:49:13 +0000 | [diff] [blame] | 108 | void MCStreamer::EmitSLEB128IntValue(int64_t Value) { |
Benjamin Kramer | 00b679c | 2012-02-23 21:15:21 +0000 | [diff] [blame] | 109 | SmallString<128> Tmp; |
Rafael Espindola | 675fbb2 | 2010-12-03 01:19:49 +0000 | [diff] [blame] | 110 | raw_svector_ostream OSE(Tmp); |
Jim Grosbach | bf387df | 2012-08-08 23:56:06 +0000 | [diff] [blame] | 111 | encodeSLEB128(Value, OSE); |
Rafael Espindola | 64e1af8 | 2013-07-02 15:49:13 +0000 | [diff] [blame] | 112 | EmitBytes(OSE.str()); |
Kevin Enderby | e46564a | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Craig Topper | 3c76c52 | 2015-09-20 23:35:59 +0000 | [diff] [blame] | 115 | void MCStreamer::EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc) { |
Kevin Enderby | 96918bc | 2014-04-22 17:27:29 +0000 | [diff] [blame] | 116 | EmitValueImpl(Value, Size, Loc); |
Rafael Espindola | 0a017a6 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Saleem Abdulrasool | 00426d9 | 2014-07-19 21:01:58 +0000 | [diff] [blame] | 119 | void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size, |
| 120 | bool IsSectionRelative) { |
| 121 | assert((!IsSectionRelative || Size == 4) && |
| 122 | "SectionRelative value requires 4-bytes"); |
| 123 | |
| 124 | if (!IsSectionRelative) |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 125 | EmitValueImpl(MCSymbolRefExpr::create(Sym, getContext()), Size); |
Saleem Abdulrasool | 00426d9 | 2014-07-19 21:01:58 +0000 | [diff] [blame] | 126 | else |
| 127 | EmitCOFFSecRel32(Sym); |
Rafael Espindola | 0a017a6 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Akira Hatanaka | f0b0844 | 2012-02-03 04:33:00 +0000 | [diff] [blame] | 130 | void MCStreamer::EmitGPRel64Value(const MCExpr *Value) { |
| 131 | report_fatal_error("unsupported directive in streamer"); |
| 132 | } |
| 133 | |
Rafael Espindola | b746531 | 2010-11-28 15:09:24 +0000 | [diff] [blame] | 134 | void MCStreamer::EmitGPRel32Value(const MCExpr *Value) { |
| 135 | report_fatal_error("unsupported directive in streamer"); |
| 136 | } |
| 137 | |
Petr Hosek | faef320 | 2016-06-01 01:59:58 +0000 | [diff] [blame] | 138 | /// Emit NumBytes bytes worth of the value specified by FillValue. |
| 139 | /// This implements directives such as '.space'. |
| 140 | void MCStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) { |
Chris Lattner | 0c65fd4 | 2010-01-19 18:45:47 +0000 | [diff] [blame] | 141 | for (uint64_t i = 0, e = NumBytes; i != e; ++i) |
Petr Hosek | 67a94a7 | 2016-05-28 05:57:48 +0000 | [diff] [blame] | 142 | EmitIntValue(FillValue, 1); |
| 143 | } |
| 144 | |
| 145 | void MCStreamer::emitFill(uint64_t NumValues, int64_t Size, int64_t Expr) { |
| 146 | int64_t NonZeroSize = Size > 4 ? 4 : Size; |
| 147 | Expr &= ~0ULL >> (64 - NonZeroSize * 8); |
| 148 | for (uint64_t i = 0, e = NumValues; i != e; ++i) { |
| 149 | EmitIntValue(Expr, NonZeroSize); |
| 150 | if (NonZeroSize < Size) |
| 151 | EmitIntValue(0, Size - NonZeroSize); |
| 152 | } |
Chris Lattner | 0c65fd4 | 2010-01-19 18:45:47 +0000 | [diff] [blame] | 153 | } |
Chris Lattner | 8a87fb7 | 2010-04-03 21:35:55 +0000 | [diff] [blame] | 154 | |
Petr Hosek | faef320 | 2016-06-01 01:59:58 +0000 | [diff] [blame] | 155 | /// The implementation in this class just redirects to emitFill. |
Rafael Espindola | 64e1af8 | 2013-07-02 15:49:13 +0000 | [diff] [blame] | 156 | void MCStreamer::EmitZeros(uint64_t NumBytes) { |
Petr Hosek | faef320 | 2016-06-01 01:59:58 +0000 | [diff] [blame] | 157 | emitFill(NumBytes, 0); |
Serge Pavlov | 24a3ebb | 2013-06-27 14:35:03 +0000 | [diff] [blame] | 158 | } |
| 159 | |
David Blaikie | c714ef4 | 2014-03-17 01:52:11 +0000 | [diff] [blame] | 160 | unsigned MCStreamer::EmitDwarfFileDirective(unsigned FileNo, |
| 161 | StringRef Directory, |
| 162 | StringRef Filename, unsigned CUID) { |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 163 | return getContext().getDwarfFile(Directory, Filename, FileNo, CUID); |
Rafael Espindola | c653a89 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line, |
| 167 | unsigned Column, unsigned Flags, |
| 168 | unsigned Isa, |
Devang Patel | 17740e7 | 2011-04-18 20:26:49 +0000 | [diff] [blame] | 169 | unsigned Discriminator, |
| 170 | StringRef FileName) { |
Rafael Espindola | c653a89 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 171 | getContext().setCurrentDwarfLoc(FileNo, Line, Column, Flags, Isa, |
| 172 | Discriminator); |
| 173 | } |
| 174 | |
David Blaikie | 3464161 | 2014-04-01 08:07:52 +0000 | [diff] [blame] | 175 | MCSymbol *MCStreamer::getDwarfLineTableSymbol(unsigned CUID) { |
| 176 | MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID); |
| 177 | if (!Table.getLabel()) { |
| 178 | StringRef Prefix = Context.getAsmInfo()->getPrivateGlobalPrefix(); |
| 179 | Table.setLabel( |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 180 | Context.getOrCreateSymbol(Prefix + "line_table_start" + Twine(CUID))); |
David Blaikie | 3464161 | 2014-04-01 08:07:52 +0000 | [diff] [blame] | 181 | } |
| 182 | return Table.getLabel(); |
| 183 | } |
| 184 | |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 185 | MCDwarfFrameInfo *MCStreamer::getCurrentDwarfFrameInfo() { |
| 186 | if (DwarfFrameInfos.empty()) |
Craig Topper | bb694de | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 187 | return nullptr; |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 188 | return &DwarfFrameInfos.back(); |
Rafael Espindola | 0a017a6 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Amaury Sechet | 6194276 | 2016-02-24 22:25:18 +0000 | [diff] [blame] | 191 | bool MCStreamer::hasUnfinishedDwarfFrameInfo() { |
| 192 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
| 193 | return CurFrame && !CurFrame->End; |
| 194 | } |
| 195 | |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 196 | void MCStreamer::EnsureValidDwarfFrame() { |
| 197 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 0a017a6 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 198 | if (!CurFrame || CurFrame->End) |
| 199 | report_fatal_error("No open frame"); |
| 200 | } |
| 201 | |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 202 | unsigned MCStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename) { |
| 203 | return getContext().getCVFile(Filename, FileNo); |
| 204 | } |
| 205 | |
| 206 | void MCStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, |
| 207 | unsigned Line, unsigned Column, |
| 208 | bool PrologueEnd, bool IsStmt, |
| 209 | StringRef FileName) { |
| 210 | getContext().setCurrentCVLoc(FunctionId, FileNo, Line, Column, PrologueEnd, |
| 211 | IsStmt); |
| 212 | } |
| 213 | |
| 214 | void MCStreamer::EmitCVLinetableDirective(unsigned FunctionId, |
| 215 | const MCSymbol *Begin, |
| 216 | const MCSymbol *End) {} |
| 217 | |
David Majnemer | 6fcbd7e | 2016-01-29 19:24:12 +0000 | [diff] [blame] | 218 | void MCStreamer::EmitCVInlineLinetableDirective( |
| 219 | unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, |
David Majnemer | c9911f2 | 2016-02-02 19:22:34 +0000 | [diff] [blame] | 220 | const MCSymbol *FnStartSym, const MCSymbol *FnEndSym, |
| 221 | ArrayRef<unsigned> SecondaryFunctionIds) {} |
David Majnemer | 6fcbd7e | 2016-01-29 19:24:12 +0000 | [diff] [blame] | 222 | |
David Majnemer | 408b5e6 | 2016-02-05 01:55:49 +0000 | [diff] [blame] | 223 | void MCStreamer::EmitCVDefRangeDirective( |
| 224 | ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges, |
| 225 | StringRef FixedSizePortion) {} |
| 226 | |
Rafael Espindola | 349c329 | 2011-04-28 12:50:37 +0000 | [diff] [blame] | 227 | void MCStreamer::EmitEHSymAttributes(const MCSymbol *Symbol, |
| 228 | MCSymbol *EHSymbol) { |
| 229 | } |
| 230 | |
Rafael Espindola | 7b61ddf | 2014-10-15 16:12:52 +0000 | [diff] [blame] | 231 | void MCStreamer::InitSections(bool NoExecStack) { |
Rafael Espindola | 61adb27 | 2014-01-24 02:42:26 +0000 | [diff] [blame] | 232 | SwitchSection(getContext().getObjectFileInfo()->getTextSection()); |
| 233 | } |
| 234 | |
Rafael Espindola | e3a20f5 | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 235 | void MCStreamer::AssignFragment(MCSymbol *Symbol, MCFragment *Fragment) { |
| 236 | assert(Fragment); |
| 237 | Symbol->setFragment(Fragment); |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 238 | |
| 239 | // As we emit symbols into a section, track the order so that they can |
| 240 | // be sorted upon later. Zero is reserved to mean 'unemitted'. |
| 241 | SymbolOrdering[Symbol] = 1 + SymbolOrdering.size(); |
| 242 | } |
| 243 | |
Rafael Espindola | 27c0c9b | 2011-04-27 15:21:19 +0000 | [diff] [blame] | 244 | void MCStreamer::EmitLabel(MCSymbol *Symbol) { |
| 245 | assert(!Symbol->isVariable() && "Cannot emit a variable symbol!"); |
Peter Collingbourne | 2f495b9 | 2013-04-17 21:18:16 +0000 | [diff] [blame] | 246 | assert(getCurrentSection().first && "Cannot emit before setting section!"); |
Rafael Espindola | e3a20f5 | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 247 | assert(!Symbol->getFragment() && "Unexpected fragment on symbol data!"); |
| 248 | Symbol->setFragment(&getCurrentSectionOnly()->getDummyFragment()); |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 249 | |
| 250 | MCTargetStreamer *TS = getTargetStreamer(); |
| 251 | if (TS) |
| 252 | TS->emitLabel(Symbol); |
Rafael Espindola | 27c0c9b | 2011-04-27 15:21:19 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Rafael Espindola | 74b101f | 2011-05-10 01:10:18 +0000 | [diff] [blame] | 255 | void MCStreamer::EmitCFISections(bool EH, bool Debug) { |
Rafael Espindola | ec53aa9 | 2011-05-10 13:39:48 +0000 | [diff] [blame] | 256 | assert(EH || Debug); |
Rafael Espindola | 74b101f | 2011-05-10 01:10:18 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Oliver Stannard | cf6bfb1 | 2014-11-03 12:19:03 +0000 | [diff] [blame] | 259 | void MCStreamer::EmitCFIStartProc(bool IsSimple) { |
Amaury Sechet | 6194276 | 2016-02-24 22:25:18 +0000 | [diff] [blame] | 260 | if (hasUnfinishedDwarfFrameInfo()) |
Rafael Espindola | 0a017a6 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 261 | report_fatal_error("Starting a frame before finishing the previous one!"); |
Rafael Espindola | c48e10c | 2011-08-02 20:24:22 +0000 | [diff] [blame] | 262 | |
Evan Cheng | eee8645 | 2011-08-24 22:31:37 +0000 | [diff] [blame] | 263 | MCDwarfFrameInfo Frame; |
David Majnemer | e035cf9 | 2014-01-27 17:20:25 +0000 | [diff] [blame] | 264 | Frame.IsSimple = IsSimple; |
Oliver Stannard | cf6bfb1 | 2014-11-03 12:19:03 +0000 | [diff] [blame] | 265 | EmitCFIStartProcImpl(Frame); |
Rafael Espindola | c48e10c | 2011-08-02 20:24:22 +0000 | [diff] [blame] | 266 | |
Yuri Gorshenin | e8c81fd | 2014-10-07 11:03:09 +0000 | [diff] [blame] | 267 | const MCAsmInfo* MAI = Context.getAsmInfo(); |
| 268 | if (MAI) { |
| 269 | for (const MCCFIInstruction& Inst : MAI->getInitialFrameState()) { |
| 270 | if (Inst.getOperation() == MCCFIInstruction::OpDefCfa || |
| 271 | Inst.getOperation() == MCCFIInstruction::OpDefCfaRegister) { |
| 272 | Frame.CurrentCfaRegister = Inst.getRegister(); |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 277 | DwarfFrameInfos.push_back(Frame); |
Rafael Espindola | 3824120 | 2012-01-07 22:42:19 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Oliver Stannard | cf6bfb1 | 2014-11-03 12:19:03 +0000 | [diff] [blame] | 280 | void MCStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) { |
| 281 | } |
Rafael Espindola | 3824120 | 2012-01-07 22:42:19 +0000 | [diff] [blame] | 282 | |
Rafael Espindola | 539d96f | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 283 | void MCStreamer::EmitCFIEndProc() { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 284 | EnsureValidDwarfFrame(); |
| 285 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | f28213c | 2012-01-09 00:17:29 +0000 | [diff] [blame] | 286 | EmitCFIEndProcImpl(*CurFrame); |
| 287 | } |
| 288 | |
| 289 | void MCStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) { |
Rafael Espindola | 49bbfd0 | 2014-06-25 00:13:59 +0000 | [diff] [blame] | 290 | // Put a dummy non-null value in Frame.End to mark that this frame has been |
| 291 | // closed. |
| 292 | Frame.End = (MCSymbol *) 1; |
Rafael Espindola | 3c227b0 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 295 | MCSymbol *MCStreamer::EmitCFICommon() { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 296 | EnsureValidDwarfFrame(); |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 297 | MCSymbol *Label = getContext().createTempSymbol(); |
Rafael Espindola | 290d716 | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 298 | EmitLabel(Label); |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 299 | return Label; |
| 300 | } |
| 301 | |
| 302 | void MCStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) { |
| 303 | MCSymbol *Label = EmitCFICommon(); |
Rafael Espindola | 1c3086c | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 304 | MCCFIInstruction Instruction = |
| 305 | MCCFIInstruction::createDefCfa(Label, Register, Offset); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 306 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 290d716 | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 307 | CurFrame->Instructions.push_back(Instruction); |
Yuri Gorshenin | e8c81fd | 2014-10-07 11:03:09 +0000 | [diff] [blame] | 308 | CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register); |
Rafael Espindola | 290d716 | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Rafael Espindola | 539d96f | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 311 | void MCStreamer::EmitCFIDefCfaOffset(int64_t Offset) { |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 312 | MCSymbol *Label = EmitCFICommon(); |
Rafael Espindola | 1c3086c | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 313 | MCCFIInstruction Instruction = |
| 314 | MCCFIInstruction::createDefCfaOffset(Label, Offset); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 315 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 85d9198 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 316 | CurFrame->Instructions.push_back(Instruction); |
Rafael Espindola | 3c227b0 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Rafael Espindola | fd794af | 2011-04-12 18:53:30 +0000 | [diff] [blame] | 319 | void MCStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) { |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 320 | MCSymbol *Label = EmitCFICommon(); |
Rafael Espindola | 1c3086c | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 321 | MCCFIInstruction Instruction = |
| 322 | MCCFIInstruction::createAdjustCfaOffset(Label, Adjustment); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 323 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | fd794af | 2011-04-12 18:53:30 +0000 | [diff] [blame] | 324 | CurFrame->Instructions.push_back(Instruction); |
| 325 | } |
| 326 | |
Rafael Espindola | 539d96f | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 327 | void MCStreamer::EmitCFIDefCfaRegister(int64_t Register) { |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 328 | MCSymbol *Label = EmitCFICommon(); |
Rafael Espindola | 1c3086c | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 329 | MCCFIInstruction Instruction = |
| 330 | MCCFIInstruction::createDefCfaRegister(Label, Register); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 331 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 426e68f | 2010-12-29 00:26:06 +0000 | [diff] [blame] | 332 | CurFrame->Instructions.push_back(Instruction); |
Yuri Gorshenin | e8c81fd | 2014-10-07 11:03:09 +0000 | [diff] [blame] | 333 | CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register); |
Rafael Espindola | 3c227b0 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Rafael Espindola | 539d96f | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 336 | void MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) { |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 337 | MCSymbol *Label = EmitCFICommon(); |
Rafael Espindola | 1c3086c | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 338 | MCCFIInstruction Instruction = |
Rafael Espindola | 5dce65b | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 339 | MCCFIInstruction::createOffset(Label, Register, Offset); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 340 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 86d347d | 2010-12-29 00:09:59 +0000 | [diff] [blame] | 341 | CurFrame->Instructions.push_back(Instruction); |
Rafael Espindola | 3c227b0 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Rafael Espindola | 1ec0f46 | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 344 | void MCStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) { |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 345 | MCSymbol *Label = EmitCFICommon(); |
Rafael Espindola | 1c3086c | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 346 | MCCFIInstruction Instruction = |
| 347 | MCCFIInstruction::createRelOffset(Label, Register, Offset); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 348 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 1ec0f46 | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 349 | CurFrame->Instructions.push_back(Instruction); |
| 350 | } |
| 351 | |
Rafael Espindola | 539d96f | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 352 | void MCStreamer::EmitCFIPersonality(const MCSymbol *Sym, |
Rafael Espindola | 2ac8355 | 2010-12-27 00:36:05 +0000 | [diff] [blame] | 353 | unsigned Encoding) { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 354 | EnsureValidDwarfFrame(); |
| 355 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 0a017a6 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 356 | CurFrame->Personality = Sym; |
Rafael Espindola | 2ac8355 | 2010-12-27 00:36:05 +0000 | [diff] [blame] | 357 | CurFrame->PersonalityEncoding = Encoding; |
Rafael Espindola | 3c227b0 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Rafael Espindola | 539d96f | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 360 | void MCStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 361 | EnsureValidDwarfFrame(); |
| 362 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 0a017a6 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 363 | CurFrame->Lsda = Sym; |
Rafael Espindola | 1de2dd0 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 364 | CurFrame->LsdaEncoding = Encoding; |
Rafael Espindola | 3c227b0 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Rafael Espindola | 539d96f | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 367 | void MCStreamer::EmitCFIRememberState() { |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 368 | MCSymbol *Label = EmitCFICommon(); |
Rafael Espindola | 1c3086c | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 369 | MCCFIInstruction Instruction = MCCFIInstruction::createRememberState(Label); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 370 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 85d9198 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 371 | CurFrame->Instructions.push_back(Instruction); |
Rafael Espindola | 85d9198 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 372 | } |
| 373 | |
Rafael Espindola | 539d96f | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 374 | void MCStreamer::EmitCFIRestoreState() { |
Rafael Espindola | 85d9198 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 375 | // FIXME: Error if there is no matching cfi_remember_state. |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 376 | MCSymbol *Label = EmitCFICommon(); |
Rafael Espindola | 1c3086c | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 377 | MCCFIInstruction Instruction = MCCFIInstruction::createRestoreState(Label); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 378 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 85d9198 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 379 | CurFrame->Instructions.push_back(Instruction); |
Rafael Espindola | 85d9198 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Rafael Espindola | 2e1c9d2 | 2011-04-12 15:31:05 +0000 | [diff] [blame] | 382 | void MCStreamer::EmitCFISameValue(int64_t Register) { |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 383 | MCSymbol *Label = EmitCFICommon(); |
Rafael Espindola | 1c3086c | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 384 | MCCFIInstruction Instruction = |
| 385 | MCCFIInstruction::createSameValue(Label, Register); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 386 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 2e1c9d2 | 2011-04-12 15:31:05 +0000 | [diff] [blame] | 387 | CurFrame->Instructions.push_back(Instruction); |
| 388 | } |
| 389 | |
Rafael Espindola | 4ea9981 | 2011-12-29 21:43:03 +0000 | [diff] [blame] | 390 | void MCStreamer::EmitCFIRestore(int64_t Register) { |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 391 | MCSymbol *Label = EmitCFICommon(); |
Rafael Espindola | 1c3086c | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 392 | MCCFIInstruction Instruction = |
| 393 | MCCFIInstruction::createRestore(Label, Register); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 394 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 4ea9981 | 2011-12-29 21:43:03 +0000 | [diff] [blame] | 395 | CurFrame->Instructions.push_back(Instruction); |
| 396 | } |
| 397 | |
Rafael Espindola | ef4aa35 | 2011-12-29 20:24:47 +0000 | [diff] [blame] | 398 | void MCStreamer::EmitCFIEscape(StringRef Values) { |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 399 | MCSymbol *Label = EmitCFICommon(); |
Rafael Espindola | 1c3086c | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 400 | MCCFIInstruction Instruction = MCCFIInstruction::createEscape(Label, Values); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 401 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | ef4aa35 | 2011-12-29 20:24:47 +0000 | [diff] [blame] | 402 | CurFrame->Instructions.push_back(Instruction); |
| 403 | } |
| 404 | |
Michael Kuperstein | 259f150 | 2015-10-07 07:01:31 +0000 | [diff] [blame] | 405 | void MCStreamer::EmitCFIGnuArgsSize(int64_t Size) { |
| 406 | MCSymbol *Label = EmitCFICommon(); |
| 407 | MCCFIInstruction Instruction = |
| 408 | MCCFIInstruction::createGnuArgsSize(Label, Size); |
| 409 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
| 410 | CurFrame->Instructions.push_back(Instruction); |
| 411 | } |
| 412 | |
Rafael Espindola | 3c47e37 | 2012-01-23 21:51:52 +0000 | [diff] [blame] | 413 | void MCStreamer::EmitCFISignalFrame() { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 414 | EnsureValidDwarfFrame(); |
| 415 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 3c47e37 | 2012-01-23 21:51:52 +0000 | [diff] [blame] | 416 | CurFrame->IsSignalFrame = true; |
| 417 | } |
| 418 | |
Rafael Espindola | 9bb2478 | 2012-11-23 16:59:41 +0000 | [diff] [blame] | 419 | void MCStreamer::EmitCFIUndefined(int64_t Register) { |
Rafael Espindola | 7a6e441 | 2012-11-24 02:18:49 +0000 | [diff] [blame] | 420 | MCSymbol *Label = EmitCFICommon(); |
Rafael Espindola | 1c3086c | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 421 | MCCFIInstruction Instruction = |
| 422 | MCCFIInstruction::createUndefined(Label, Register); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 423 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | 9bb2478 | 2012-11-23 16:59:41 +0000 | [diff] [blame] | 424 | CurFrame->Instructions.push_back(Instruction); |
| 425 | } |
| 426 | |
Rafael Espindola | cdb9a53 | 2012-11-25 15:14:49 +0000 | [diff] [blame] | 427 | void MCStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) { |
| 428 | MCSymbol *Label = EmitCFICommon(); |
| 429 | MCCFIInstruction Instruction = |
| 430 | MCCFIInstruction::createRegister(Label, Register1, Register2); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 431 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Rafael Espindola | cdb9a53 | 2012-11-25 15:14:49 +0000 | [diff] [blame] | 432 | CurFrame->Instructions.push_back(Instruction); |
| 433 | } |
| 434 | |
Venkatraman Govindaraju | 3816d43 | 2013-09-26 14:49:40 +0000 | [diff] [blame] | 435 | void MCStreamer::EmitCFIWindowSave() { |
| 436 | MCSymbol *Label = EmitCFICommon(); |
| 437 | MCCFIInstruction Instruction = |
| 438 | MCCFIInstruction::createWindowSave(Label); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 439 | MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); |
Venkatraman Govindaraju | 3816d43 | 2013-09-26 14:49:40 +0000 | [diff] [blame] | 440 | CurFrame->Instructions.push_back(Instruction); |
| 441 | } |
| 442 | |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 443 | void MCStreamer::EnsureValidWinFrameInfo() { |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 444 | const MCAsmInfo *MAI = Context.getAsmInfo(); |
| 445 | if (!MAI->usesWindowsCFI()) |
| 446 | report_fatal_error(".seh_* directives are not supported on this target"); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 447 | if (!CurrentWinFrameInfo || CurrentWinFrameInfo->End) |
Charles Davis | d991ec4 | 2011-05-19 02:49:00 +0000 | [diff] [blame] | 448 | report_fatal_error("No open Win64 EH frame function!"); |
| 449 | } |
| 450 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 451 | void MCStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol) { |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 452 | const MCAsmInfo *MAI = Context.getAsmInfo(); |
| 453 | if (!MAI->usesWindowsCFI()) |
| 454 | report_fatal_error(".seh_* directives are not supported on this target"); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 455 | if (CurrentWinFrameInfo && !CurrentWinFrameInfo->End) |
Charles Davis | d991ec4 | 2011-05-19 02:49:00 +0000 | [diff] [blame] | 456 | report_fatal_error("Starting a function before ending the previous one!"); |
Saleem Abdulrasool | b3be737 | 2014-08-03 18:51:17 +0000 | [diff] [blame] | 457 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 458 | MCSymbol *StartProc = getContext().createTempSymbol(); |
Saleem Abdulrasool | b3be737 | 2014-08-03 18:51:17 +0000 | [diff] [blame] | 459 | EmitLabel(StartProc); |
| 460 | |
| 461 | WinFrameInfos.push_back(new WinEH::FrameInfo(Symbol, StartProc)); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 462 | CurrentWinFrameInfo = WinFrameInfos.back(); |
Reid Kleckner | 97837b7 | 2016-05-02 23:22:18 +0000 | [diff] [blame] | 463 | CurrentWinFrameInfo->TextSection = getCurrentSectionOnly(); |
Charles Davis | d991ec4 | 2011-05-19 02:49:00 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 466 | void MCStreamer::EmitWinCFIEndProc() { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 467 | EnsureValidWinFrameInfo(); |
| 468 | if (CurrentWinFrameInfo->ChainedParent) |
Charles Davis | d991ec4 | 2011-05-19 02:49:00 +0000 | [diff] [blame] | 469 | report_fatal_error("Not all chained regions terminated!"); |
Saleem Abdulrasool | b3be737 | 2014-08-03 18:51:17 +0000 | [diff] [blame] | 470 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 471 | MCSymbol *Label = getContext().createTempSymbol(); |
Saleem Abdulrasool | b3be737 | 2014-08-03 18:51:17 +0000 | [diff] [blame] | 472 | EmitLabel(Label); |
| 473 | CurrentWinFrameInfo->End = Label; |
Charles Davis | af18d07 | 2011-05-15 17:20:01 +0000 | [diff] [blame] | 474 | } |
| 475 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 476 | void MCStreamer::EmitWinCFIStartChained() { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 477 | EnsureValidWinFrameInfo(); |
Saleem Abdulrasool | b3be737 | 2014-08-03 18:51:17 +0000 | [diff] [blame] | 478 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 479 | MCSymbol *StartProc = getContext().createTempSymbol(); |
Saleem Abdulrasool | b3be737 | 2014-08-03 18:51:17 +0000 | [diff] [blame] | 480 | EmitLabel(StartProc); |
| 481 | |
| 482 | WinFrameInfos.push_back(new WinEH::FrameInfo(CurrentWinFrameInfo->Function, |
| 483 | StartProc, CurrentWinFrameInfo)); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 484 | CurrentWinFrameInfo = WinFrameInfos.back(); |
Reid Kleckner | 97837b7 | 2016-05-02 23:22:18 +0000 | [diff] [blame] | 485 | CurrentWinFrameInfo->TextSection = getCurrentSectionOnly(); |
Charles Davis | 77e0610 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 488 | void MCStreamer::EmitWinCFIEndChained() { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 489 | EnsureValidWinFrameInfo(); |
| 490 | if (!CurrentWinFrameInfo->ChainedParent) |
Charles Davis | b422258 | 2011-05-19 04:04:13 +0000 | [diff] [blame] | 491 | report_fatal_error("End of a chained region outside a chained region!"); |
Saleem Abdulrasool | b3be737 | 2014-08-03 18:51:17 +0000 | [diff] [blame] | 492 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 493 | MCSymbol *Label = getContext().createTempSymbol(); |
Saleem Abdulrasool | b3be737 | 2014-08-03 18:51:17 +0000 | [diff] [blame] | 494 | EmitLabel(Label); |
| 495 | |
| 496 | CurrentWinFrameInfo->End = Label; |
| 497 | CurrentWinFrameInfo = |
| 498 | const_cast<WinEH::FrameInfo *>(CurrentWinFrameInfo->ChainedParent); |
Charles Davis | 77e0610 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 499 | } |
| 500 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 501 | void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, |
| 502 | bool Except) { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 503 | EnsureValidWinFrameInfo(); |
| 504 | if (CurrentWinFrameInfo->ChainedParent) |
Charles Davis | 6879634 | 2011-05-21 17:36:25 +0000 | [diff] [blame] | 505 | report_fatal_error("Chained unwind areas can't have handlers!"); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 506 | CurrentWinFrameInfo->ExceptionHandler = Sym; |
Charles Davis | 8e8f59b | 2011-05-21 15:57:49 +0000 | [diff] [blame] | 507 | if (!Except && !Unwind) |
Charles Davis | 4cd8856 | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 508 | report_fatal_error("Don't know what kind of handler this is!"); |
Charles Davis | 8e8f59b | 2011-05-21 15:57:49 +0000 | [diff] [blame] | 509 | if (Unwind) |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 510 | CurrentWinFrameInfo->HandlesUnwind = true; |
Charles Davis | 8e8f59b | 2011-05-21 15:57:49 +0000 | [diff] [blame] | 511 | if (Except) |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 512 | CurrentWinFrameInfo->HandlesExceptions = true; |
Charles Davis | 4cd8856 | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 515 | void MCStreamer::EmitWinEHHandlerData() { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 516 | EnsureValidWinFrameInfo(); |
| 517 | if (CurrentWinFrameInfo->ChainedParent) |
Charles Davis | 6879634 | 2011-05-21 17:36:25 +0000 | [diff] [blame] | 518 | report_fatal_error("Chained unwind areas can't have handlers!"); |
Charles Davis | 77e0610 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Reid Kleckner | 97837b7 | 2016-05-02 23:22:18 +0000 | [diff] [blame] | 521 | static MCSection *getWinCFISection(MCContext &Context, unsigned *NextWinCFIID, |
| 522 | MCSection *MainCFISec, |
| 523 | const MCSection *TextSec) { |
| 524 | // If this is the main .text section, use the main unwind info section. |
| 525 | if (TextSec == Context.getObjectFileInfo()->getTextSection()) |
| 526 | return MainCFISec; |
| 527 | |
| 528 | const auto *TextSecCOFF = cast<MCSectionCOFF>(TextSec); |
| 529 | unsigned UniqueID = TextSecCOFF->getOrAssignWinCFISectionID(NextWinCFIID); |
| 530 | |
| 531 | // If this section is COMDAT, this unwind section should be COMDAT associative |
| 532 | // with its group. |
| 533 | const MCSymbol *KeySym = nullptr; |
| 534 | if (TextSecCOFF->getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) |
| 535 | KeySym = TextSecCOFF->getCOMDATSymbol(); |
| 536 | |
| 537 | return Context.getAssociativeCOFFSection(cast<MCSectionCOFF>(MainCFISec), |
| 538 | KeySym, UniqueID); |
| 539 | } |
| 540 | |
| 541 | MCSection *MCStreamer::getAssociatedPDataSection(const MCSection *TextSec) { |
| 542 | return getWinCFISection(getContext(), &NextWinCFIID, |
| 543 | getContext().getObjectFileInfo()->getPDataSection(), |
| 544 | TextSec); |
| 545 | } |
| 546 | |
| 547 | MCSection *MCStreamer::getAssociatedXDataSection(const MCSection *TextSec) { |
| 548 | return getWinCFISection(getContext(), &NextWinCFIID, |
| 549 | getContext().getObjectFileInfo()->getXDataSection(), |
| 550 | TextSec); |
| 551 | } |
| 552 | |
Michael Kuperstein | 23d952b | 2015-07-22 10:49:44 +0000 | [diff] [blame] | 553 | void MCStreamer::EmitSyntaxDirective() {} |
| 554 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 555 | void MCStreamer::EmitWinCFIPushReg(unsigned Register) { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 556 | EnsureValidWinFrameInfo(); |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 557 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 558 | MCSymbol *Label = getContext().createTempSymbol(); |
Charles Davis | 6d1c4c7 | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 559 | EmitLabel(Label); |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 560 | |
| 561 | WinEH::Instruction Inst = Win64EH::Instruction::PushNonVol(Label, Register); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 562 | CurrentWinFrameInfo->Instructions.push_back(Inst); |
Charles Davis | 77e0610 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 563 | } |
| 564 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 565 | void MCStreamer::EmitWinCFISetFrame(unsigned Register, unsigned Offset) { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 566 | EnsureValidWinFrameInfo(); |
| 567 | if (CurrentWinFrameInfo->LastFrameInst >= 0) |
Charles Davis | 9dcee31 | 2011-05-27 01:42:17 +0000 | [diff] [blame] | 568 | report_fatal_error("Frame register and offset already specified!"); |
Charles Davis | e636022 | 2011-05-22 00:56:20 +0000 | [diff] [blame] | 569 | if (Offset & 0x0F) |
| 570 | report_fatal_error("Misaligned frame pointer offset!"); |
NAKAMURA Takumi | 1db5995 | 2014-06-25 12:41:52 +0000 | [diff] [blame] | 571 | if (Offset > 240) |
| 572 | report_fatal_error("Frame offset must be less than or equal to 240!"); |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 573 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 574 | MCSymbol *Label = getContext().createTempSymbol(); |
Kai Nacke | 1b7e486 | 2013-08-27 04:16:16 +0000 | [diff] [blame] | 575 | EmitLabel(Label); |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 576 | |
| 577 | WinEH::Instruction Inst = |
| 578 | Win64EH::Instruction::SetFPReg(Label, Register, Offset); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 579 | CurrentWinFrameInfo->LastFrameInst = CurrentWinFrameInfo->Instructions.size(); |
| 580 | CurrentWinFrameInfo->Instructions.push_back(Inst); |
Charles Davis | af18d07 | 2011-05-15 17:20:01 +0000 | [diff] [blame] | 581 | } |
| 582 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 583 | void MCStreamer::EmitWinCFIAllocStack(unsigned Size) { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 584 | EnsureValidWinFrameInfo(); |
Reid Kleckner | b5dd945 | 2014-07-01 00:42:47 +0000 | [diff] [blame] | 585 | if (Size == 0) |
| 586 | report_fatal_error("Allocation size must be non-zero!"); |
Charles Davis | e636022 | 2011-05-22 00:56:20 +0000 | [diff] [blame] | 587 | if (Size & 7) |
| 588 | report_fatal_error("Misaligned stack allocation!"); |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 589 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 590 | MCSymbol *Label = getContext().createTempSymbol(); |
Charles Davis | 6d1c4c7 | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 591 | EmitLabel(Label); |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 592 | |
| 593 | WinEH::Instruction Inst = Win64EH::Instruction::Alloc(Label, Size); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 594 | CurrentWinFrameInfo->Instructions.push_back(Inst); |
Charles Davis | af18d07 | 2011-05-15 17:20:01 +0000 | [diff] [blame] | 595 | } |
| 596 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 597 | void MCStreamer::EmitWinCFISaveReg(unsigned Register, unsigned Offset) { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 598 | EnsureValidWinFrameInfo(); |
Charles Davis | e636022 | 2011-05-22 00:56:20 +0000 | [diff] [blame] | 599 | if (Offset & 7) |
| 600 | report_fatal_error("Misaligned saved register offset!"); |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 601 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 602 | MCSymbol *Label = getContext().createTempSymbol(); |
Charles Davis | 6d1c4c7 | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 603 | EmitLabel(Label); |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 604 | |
| 605 | WinEH::Instruction Inst = |
| 606 | Win64EH::Instruction::SaveNonVol(Label, Register, Offset); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 607 | CurrentWinFrameInfo->Instructions.push_back(Inst); |
Charles Davis | af18d07 | 2011-05-15 17:20:01 +0000 | [diff] [blame] | 608 | } |
| 609 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 610 | void MCStreamer::EmitWinCFISaveXMM(unsigned Register, unsigned Offset) { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 611 | EnsureValidWinFrameInfo(); |
Charles Davis | e636022 | 2011-05-22 00:56:20 +0000 | [diff] [blame] | 612 | if (Offset & 0x0F) |
| 613 | report_fatal_error("Misaligned saved vector register offset!"); |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 614 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 615 | MCSymbol *Label = getContext().createTempSymbol(); |
Charles Davis | 6d1c4c7 | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 616 | EmitLabel(Label); |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 617 | |
| 618 | WinEH::Instruction Inst = |
| 619 | Win64EH::Instruction::SaveXMM(Label, Register, Offset); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 620 | CurrentWinFrameInfo->Instructions.push_back(Inst); |
Charles Davis | af18d07 | 2011-05-15 17:20:01 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 623 | void MCStreamer::EmitWinCFIPushFrame(bool Code) { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 624 | EnsureValidWinFrameInfo(); |
| 625 | if (CurrentWinFrameInfo->Instructions.size() > 0) |
Charles Davis | 9dcee31 | 2011-05-27 01:42:17 +0000 | [diff] [blame] | 626 | report_fatal_error("If present, PushMachFrame must be the first UOP"); |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 627 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 628 | MCSymbol *Label = getContext().createTempSymbol(); |
Charles Davis | 6d1c4c7 | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 629 | EmitLabel(Label); |
Saleem Abdulrasool | ab82086 | 2014-07-17 03:08:50 +0000 | [diff] [blame] | 630 | |
| 631 | WinEH::Instruction Inst = Win64EH::Instruction::PushMachFrame(Label, Code); |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 632 | CurrentWinFrameInfo->Instructions.push_back(Inst); |
Charles Davis | af18d07 | 2011-05-15 17:20:01 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Saleem Abdulrasool | 7206a52 | 2014-06-29 01:52:01 +0000 | [diff] [blame] | 635 | void MCStreamer::EmitWinCFIEndProlog() { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 636 | EnsureValidWinFrameInfo(); |
Saleem Abdulrasool | b3be737 | 2014-08-03 18:51:17 +0000 | [diff] [blame] | 637 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 638 | MCSymbol *Label = getContext().createTempSymbol(); |
Saleem Abdulrasool | b3be737 | 2014-08-03 18:51:17 +0000 | [diff] [blame] | 639 | EmitLabel(Label); |
| 640 | |
| 641 | CurrentWinFrameInfo->PrologEnd = Label; |
Charles Davis | 2701815 | 2011-05-16 21:13:58 +0000 | [diff] [blame] | 642 | } |
| 643 | |
David Majnemer | 4eecd30 | 2015-05-30 04:56:02 +0000 | [diff] [blame] | 644 | void MCStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) { |
| 645 | } |
| 646 | |
Timur Iskhodzhanov | c1fb2d6 | 2013-12-20 18:15:00 +0000 | [diff] [blame] | 647 | void MCStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) { |
Timur Iskhodzhanov | c1fb2d6 | 2013-12-20 18:15:00 +0000 | [diff] [blame] | 648 | } |
| 649 | |
Rafael Espindola | d3df3d3 | 2011-12-17 01:14:52 +0000 | [diff] [blame] | 650 | void MCStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) { |
Rafael Espindola | d3df3d3 | 2011-12-17 01:14:52 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Matt Fleming | 141791c | 2010-05-20 19:45:09 +0000 | [diff] [blame] | 653 | /// EmitRawText - If this file is backed by an assembly streamer, this dumps |
Chris Lattner | 8a87fb7 | 2010-04-03 21:35:55 +0000 | [diff] [blame] | 654 | /// the specified string in the output .s file. This capability is |
| 655 | /// indicated by the hasRawTextSupport() predicate. |
David Blaikie | d8c5b4e | 2013-10-24 22:43:10 +0000 | [diff] [blame] | 656 | void MCStreamer::EmitRawTextImpl(StringRef String) { |
Chris Lattner | 8a87fb7 | 2010-04-03 21:35:55 +0000 | [diff] [blame] | 657 | errs() << "EmitRawText called on an MCStreamer that doesn't support it, " |
| 658 | " something must not be fully mc'ized\n"; |
| 659 | abort(); |
| 660 | } |
Chris Lattner | 1716721 | 2010-04-03 22:12:35 +0000 | [diff] [blame] | 661 | |
| 662 | void MCStreamer::EmitRawText(const Twine &T) { |
| 663 | SmallString<128> Str; |
David Blaikie | d8c5b4e | 2013-10-24 22:43:10 +0000 | [diff] [blame] | 664 | EmitRawTextImpl(T.toStringRef(Str)); |
Chris Lattner | 1716721 | 2010-04-03 22:12:35 +0000 | [diff] [blame] | 665 | } |
Rafael Espindola | b6089d6 | 2011-05-10 03:14:15 +0000 | [diff] [blame] | 666 | |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 667 | void MCStreamer::EmitWindowsUnwindTables() { |
Charles Davis | bc2daa0 | 2011-05-22 04:15:07 +0000 | [diff] [blame] | 668 | } |
Rafael Espindola | 0708209 | 2012-01-07 03:13:18 +0000 | [diff] [blame] | 669 | |
| 670 | void MCStreamer::Finish() { |
Saleem Abdulrasool | 3f3cefd | 2014-07-13 19:03:36 +0000 | [diff] [blame] | 671 | if (!DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End) |
Rafael Espindola | 0708209 | 2012-01-07 03:13:18 +0000 | [diff] [blame] | 672 | report_fatal_error("Unfinished frame!"); |
| 673 | |
Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 674 | MCTargetStreamer *TS = getTargetStreamer(); |
| 675 | if (TS) |
| 676 | TS->finish(); |
| 677 | |
Rafael Espindola | 0708209 | 2012-01-07 03:13:18 +0000 | [diff] [blame] | 678 | FinishImpl(); |
| 679 | } |
Jack Carter | 2f8d9d9 | 2013-02-19 21:57:35 +0000 | [diff] [blame] | 680 | |
Zoran Jovanovic | 28221d8 | 2014-03-20 09:44:49 +0000 | [diff] [blame] | 681 | void MCStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { |
Rafael Espindola | 591c641 | 2014-06-25 18:37:33 +0000 | [diff] [blame] | 682 | visitUsedExpr(*Value); |
Zoran Jovanovic | 28221d8 | 2014-03-20 09:44:49 +0000 | [diff] [blame] | 683 | Symbol->setVariableValue(Value); |
| 684 | |
| 685 | MCTargetStreamer *TS = getTargetStreamer(); |
| 686 | if (TS) |
| 687 | TS->emitAssignment(Symbol, Value); |
| 688 | } |
Rafael Espindola | 624ac24 | 2014-06-25 00:27:53 +0000 | [diff] [blame] | 689 | |
Colin LeMahieu | 48a9b71 | 2015-06-18 20:43:22 +0000 | [diff] [blame] | 690 | void MCTargetStreamer::prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS, |
| 691 | const MCInst &Inst, const MCSubtargetInfo &STI) { |
| 692 | InstPrinter.printInst(&Inst, OS, "", STI); |
| 693 | } |
| 694 | |
Rafael Espindola | e2c6624 | 2014-06-25 15:45:33 +0000 | [diff] [blame] | 695 | void MCStreamer::visitUsedSymbol(const MCSymbol &Sym) { |
| 696 | } |
| 697 | |
| 698 | void MCStreamer::visitUsedExpr(const MCExpr &Expr) { |
| 699 | switch (Expr.getKind()) { |
| 700 | case MCExpr::Target: |
| 701 | cast<MCTargetExpr>(Expr).visitUsedExpr(*this); |
| 702 | break; |
| 703 | |
| 704 | case MCExpr::Constant: |
| 705 | break; |
| 706 | |
| 707 | case MCExpr::Binary: { |
| 708 | const MCBinaryExpr &BE = cast<MCBinaryExpr>(Expr); |
| 709 | visitUsedExpr(*BE.getLHS()); |
| 710 | visitUsedExpr(*BE.getRHS()); |
| 711 | break; |
| 712 | } |
| 713 | |
| 714 | case MCExpr::SymbolRef: |
| 715 | visitUsedSymbol(cast<MCSymbolRefExpr>(Expr).getSymbol()); |
| 716 | break; |
| 717 | |
| 718 | case MCExpr::Unary: |
| 719 | visitUsedExpr(*cast<MCUnaryExpr>(Expr).getSubExpr()); |
| 720 | break; |
| 721 | } |
| 722 | } |
| 723 | |
Rafael Espindola | 591c641 | 2014-06-25 18:37:33 +0000 | [diff] [blame] | 724 | void MCStreamer::EmitInstruction(const MCInst &Inst, |
| 725 | const MCSubtargetInfo &STI) { |
| 726 | // Scan for values. |
| 727 | for (unsigned i = Inst.getNumOperands(); i--;) |
| 728 | if (Inst.getOperand(i).isExpr()) |
| 729 | visitUsedExpr(*Inst.getOperand(i).getExpr()); |
| 730 | } |
| 731 | |
Rafael Espindola | 7c6e6e4 | 2015-06-11 18:58:08 +0000 | [diff] [blame] | 732 | void MCStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, |
| 733 | unsigned Size) { |
| 734 | // Get the Hi-Lo expression. |
| 735 | const MCExpr *Diff = |
| 736 | MCBinaryExpr::createSub(MCSymbolRefExpr::create(Hi, Context), |
| 737 | MCSymbolRefExpr::create(Lo, Context), Context); |
| 738 | |
| 739 | const MCAsmInfo *MAI = Context.getAsmInfo(); |
Joerg Sonnenberger | 2298203 | 2016-06-18 23:25:37 +0000 | [diff] [blame] | 740 | if (!MAI->doesSetDirectiveSuppressReloc()) { |
Rafael Espindola | 7c6e6e4 | 2015-06-11 18:58:08 +0000 | [diff] [blame] | 741 | EmitValue(Diff, Size); |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | // Otherwise, emit with .set (aka assignment). |
| 746 | MCSymbol *SetLabel = Context.createTempSymbol("set", true); |
| 747 | EmitAssignment(SetLabel, Diff); |
| 748 | EmitSymbolValue(SetLabel, Size); |
| 749 | } |
| 750 | |
Rafael Espindola | 624ac24 | 2014-06-25 00:27:53 +0000 | [diff] [blame] | 751 | void MCStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {} |
| 752 | void MCStreamer::EmitThumbFunc(MCSymbol *Func) {} |
| 753 | void MCStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {} |
| 754 | void MCStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {} |
| 755 | void MCStreamer::EndCOFFSymbolDef() {} |
| 756 | void MCStreamer::EmitFileDirective(StringRef Filename) {} |
| 757 | void MCStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {} |
| 758 | void MCStreamer::EmitCOFFSymbolType(int Type) {} |
Rafael Espindola | a869576 | 2015-06-02 00:25:12 +0000 | [diff] [blame] | 759 | void MCStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {} |
Rafael Espindola | 624ac24 | 2014-06-25 00:27:53 +0000 | [diff] [blame] | 760 | void MCStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
| 761 | unsigned ByteAlignment) {} |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 762 | void MCStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, |
Rafael Espindola | 624ac24 | 2014-06-25 00:27:53 +0000 | [diff] [blame] | 763 | uint64_t Size, unsigned ByteAlignment) {} |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 764 | void MCStreamer::ChangeSection(MCSection *, const MCExpr *) {} |
Rafael Espindola | 624ac24 | 2014-06-25 00:27:53 +0000 | [diff] [blame] | 765 | void MCStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {} |
| 766 | void MCStreamer::EmitBytes(StringRef Data) {} |
Reid Kleckner | fbdbe9e | 2016-05-31 18:45:36 +0000 | [diff] [blame] | 767 | void MCStreamer::EmitBinaryData(StringRef Data) { EmitBytes(Data); } |
Craig Topper | 3c76c52 | 2015-09-20 23:35:59 +0000 | [diff] [blame] | 768 | void MCStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) { |
Rafael Espindola | 591c641 | 2014-06-25 18:37:33 +0000 | [diff] [blame] | 769 | visitUsedExpr(*Value); |
| 770 | } |
Rafael Espindola | 624ac24 | 2014-06-25 00:27:53 +0000 | [diff] [blame] | 771 | void MCStreamer::EmitULEB128Value(const MCExpr *Value) {} |
| 772 | void MCStreamer::EmitSLEB128Value(const MCExpr *Value) {} |
Petr Hosek | 67a94a7 | 2016-05-28 05:57:48 +0000 | [diff] [blame] | 773 | void MCStreamer::emitFill(const MCExpr &NumBytes, uint64_t Value, SMLoc Loc) {} |
| 774 | void MCStreamer::emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr, |
| 775 | SMLoc Loc) {} |
Rafael Espindola | 624ac24 | 2014-06-25 00:27:53 +0000 | [diff] [blame] | 776 | void MCStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value, |
| 777 | unsigned ValueSize, |
| 778 | unsigned MaxBytesToEmit) {} |
| 779 | void MCStreamer::EmitCodeAlignment(unsigned ByteAlignment, |
| 780 | unsigned MaxBytesToEmit) {} |
Rafael Espindola | 7ae65d8 | 2015-11-04 23:59:18 +0000 | [diff] [blame] | 781 | void MCStreamer::emitValueToOffset(const MCExpr *Offset, unsigned char Value) {} |
Rafael Espindola | 624ac24 | 2014-06-25 00:27:53 +0000 | [diff] [blame] | 782 | void MCStreamer::EmitBundleAlignMode(unsigned AlignPow2) {} |
| 783 | void MCStreamer::EmitBundleLock(bool AlignToEnd) {} |
| 784 | void MCStreamer::FinishImpl() {} |
| 785 | void MCStreamer::EmitBundleUnlock() {} |
Rafael Espindola | ceb96a4 | 2015-03-10 21:35:16 +0000 | [diff] [blame] | 786 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 787 | void MCStreamer::SwitchSection(MCSection *Section, const MCExpr *Subsection) { |
Rafael Espindola | ceb96a4 | 2015-03-10 21:35:16 +0000 | [diff] [blame] | 788 | assert(Section && "Cannot switch to a null section!"); |
| 789 | MCSectionSubPair curSection = SectionStack.back().first; |
| 790 | SectionStack.back().second = curSection; |
| 791 | if (MCSectionSubPair(Section, Subsection) != curSection) { |
Rafael Espindola | 2f9bdd8 | 2015-05-27 20:52:32 +0000 | [diff] [blame] | 792 | ChangeSection(Section, Subsection); |
Rafael Espindola | ceb96a4 | 2015-03-10 21:35:16 +0000 | [diff] [blame] | 793 | SectionStack.back().first = MCSectionSubPair(Section, Subsection); |
Rafael Espindola | f2b408c | 2015-03-23 21:22:04 +0000 | [diff] [blame] | 794 | assert(!Section->hasEnded() && "Section already ended"); |
Rafael Espindola | f1a13f5 | 2015-03-11 00:51:37 +0000 | [diff] [blame] | 795 | MCSymbol *Sym = Section->getBeginSymbol(); |
| 796 | if (Sym && !Sym->isInSection()) |
| 797 | EmitLabel(Sym); |
Rafael Espindola | ceb96a4 | 2015-03-10 21:35:16 +0000 | [diff] [blame] | 798 | } |
| 799 | } |
Rafael Espindola | f2b408c | 2015-03-23 21:22:04 +0000 | [diff] [blame] | 800 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 801 | MCSymbol *MCStreamer::endSection(MCSection *Section) { |
Rafael Espindola | f2b408c | 2015-03-23 21:22:04 +0000 | [diff] [blame] | 802 | // TODO: keep track of the last subsection so that this symbol appears in the |
| 803 | // correct place. |
| 804 | MCSymbol *Sym = Section->getEndSymbol(Context); |
| 805 | if (Sym->isInSection()) |
| 806 | return Sym; |
| 807 | |
| 808 | SwitchSection(Section); |
| 809 | EmitLabel(Sym); |
| 810 | return Sym; |
| 811 | } |