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