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