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