blob: a7551a3283a32fe875b0a191df5a42c1c7595506 [file] [log] [blame]
Kevin Enderbye5930f12010-07-28 20:55:35 +00001//===- lib/MC/MCDwarf.cpp - MCDwarf implementation ------------------------===//
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
10#include "llvm/MC/MCDwarf.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000011#include "llvm/ADT/Hashing.h"
Benjamin Kramer502b9e12014-04-12 16:15:53 +000012#include "llvm/ADT/STLExtras.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000013#include "llvm/ADT/SmallString.h"
14#include "llvm/ADT/Twine.h"
15#include "llvm/Config/config.h"
Evan Cheng76792992011-07-20 05:58:47 +000016#include "llvm/MC/MCAsmInfo.h"
17#include "llvm/MC/MCContext.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000018#include "llvm/MC/MCExpr.h"
Evan Cheng76792992011-07-20 05:58:47 +000019#include "llvm/MC/MCObjectFileInfo.h"
Rafael Espindola4066e8d2014-05-12 14:28:48 +000020#include "llvm/MC/MCObjectStreamer.h"
Evan Cheng76792992011-07-20 05:58:47 +000021#include "llvm/MC/MCRegisterInfo.h"
Oliver Stannard8b273082014-06-19 15:52:37 +000022#include "llvm/MC/MCSection.h"
Kevin Enderbye46564a2010-09-30 16:52:03 +000023#include "llvm/MC/MCSymbol.h"
Kevin Enderbye5930f12010-07-28 20:55:35 +000024#include "llvm/Support/Debug.h"
Reid Kleckner858239d2016-06-22 23:23:08 +000025#include "llvm/Support/EndianStream.h"
Rafael Espindola85d91982010-12-28 18:36:23 +000026#include "llvm/Support/ErrorHandling.h"
Jim Grosbachbf387df2012-08-08 23:56:06 +000027#include "llvm/Support/LEB128.h"
Kevin Enderbye7739d42011-12-09 18:09:40 +000028#include "llvm/Support/Path.h"
29#include "llvm/Support/SourceMgr.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000030#include "llvm/Support/raw_ostream.h"
Hans Wennborg083ca9b2015-10-06 23:24:35 +000031
Kevin Enderbye5930f12010-07-28 20:55:35 +000032using namespace llvm;
33
Ulrich Weigand32d725b2013-06-12 14:46:54 +000034static inline uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta) {
Bill Wendlingbc07a892013-06-18 07:20:20 +000035 unsigned MinInsnLength = Context.getAsmInfo()->getMinInstAlignment();
Ulrich Weigand32d725b2013-06-12 14:46:54 +000036 if (MinInsnLength == 1)
Kevin Enderbye46564a2010-09-30 16:52:03 +000037 return AddrDelta;
Ulrich Weigand32d725b2013-06-12 14:46:54 +000038 if (AddrDelta % MinInsnLength != 0) {
Kevin Enderbye46564a2010-09-30 16:52:03 +000039 // TODO: report this error, but really only once.
40 ;
41 }
Ulrich Weigand32d725b2013-06-12 14:46:54 +000042 return AddrDelta / MinInsnLength;
Kevin Enderbye46564a2010-09-30 16:52:03 +000043}
44
45//
46// This is called when an instruction is assembled into the specified section
47// and if there is information from the last .loc directive that has yet to have
48// a line entry made for it is made.
49//
David Majnemer8cc30782016-01-21 01:59:03 +000050void MCDwarfLineEntry::Make(MCObjectStreamer *MCOS, MCSection *Section) {
Kevin Enderbye46564a2010-09-30 16:52:03 +000051 if (!MCOS->getContext().getDwarfLocSeen())
52 return;
53
54 // Create a symbol at in the current section for use in the line entry.
Jim Grosbach6f482002015-05-18 18:43:14 +000055 MCSymbol *LineSym = MCOS->getContext().createTempSymbol();
David Majnemer8cc30782016-01-21 01:59:03 +000056 // Set the value of the symbol to use for the MCDwarfLineEntry.
Kevin Enderbye46564a2010-09-30 16:52:03 +000057 MCOS->EmitLabel(LineSym);
58
59 // Get the current .loc info saved in the context.
60 const MCDwarfLoc &DwarfLoc = MCOS->getContext().getCurrentDwarfLoc();
61
62 // Create a (local) line entry with the symbol and the current .loc info.
David Majnemer8cc30782016-01-21 01:59:03 +000063 MCDwarfLineEntry LineEntry(LineSym, DwarfLoc);
Kevin Enderbye46564a2010-09-30 16:52:03 +000064
65 // clear DwarfLocSeen saying the current .loc info is now used.
Jim Grosbach6f482002015-05-18 18:43:14 +000066 MCOS->getContext().clearDwarfLocSeen();
Kevin Enderbye46564a2010-09-30 16:52:03 +000067
Kevin Enderbye46564a2010-09-30 16:52:03 +000068 // Add the line entry to this section's entries.
David Blaikiea55e64f2014-03-12 22:28:56 +000069 MCOS->getContext()
David Blaikied9012ba2014-03-13 21:59:51 +000070 .getMCDwarfLineTable(MCOS->getContext().getDwarfCompileUnitID())
David Blaikie11765bc2014-03-13 17:55:28 +000071 .getMCLineSections()
David Blaikiea55e64f2014-03-12 22:28:56 +000072 .addLineEntry(LineEntry, Section);
Kevin Enderbye46564a2010-09-30 16:52:03 +000073}
74
75//
76// This helper routine returns an expression of End - Start + IntVal .
Jim Grosbachdc1e36e2012-05-11 01:41:30 +000077//
Rafael Espindolad66e65d2010-12-09 23:08:35 +000078static inline const MCExpr *MakeStartMinusEndExpr(const MCStreamer &MCOS,
79 const MCSymbol &Start,
80 const MCSymbol &End,
81 int IntVal) {
Kevin Enderbye46564a2010-09-30 16:52:03 +000082 MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
83 const MCExpr *Res =
Jim Grosbach13760bd2015-05-30 01:25:56 +000084 MCSymbolRefExpr::create(&End, Variant, MCOS.getContext());
Kevin Enderbye46564a2010-09-30 16:52:03 +000085 const MCExpr *RHS =
Jim Grosbach13760bd2015-05-30 01:25:56 +000086 MCSymbolRefExpr::create(&Start, Variant, MCOS.getContext());
Kevin Enderbye46564a2010-09-30 16:52:03 +000087 const MCExpr *Res1 =
Jim Grosbach13760bd2015-05-30 01:25:56 +000088 MCBinaryExpr::create(MCBinaryExpr::Sub, Res, RHS, MCOS.getContext());
Kevin Enderbye46564a2010-09-30 16:52:03 +000089 const MCExpr *Res2 =
Jim Grosbach13760bd2015-05-30 01:25:56 +000090 MCConstantExpr::create(IntVal, MCOS.getContext());
Kevin Enderbye46564a2010-09-30 16:52:03 +000091 const MCExpr *Res3 =
Jim Grosbach13760bd2015-05-30 01:25:56 +000092 MCBinaryExpr::create(MCBinaryExpr::Sub, Res1, Res2, MCOS.getContext());
Kevin Enderbye46564a2010-09-30 16:52:03 +000093 return Res3;
94}
95
Kevin Enderbye46564a2010-09-30 16:52:03 +000096//
97// This emits the Dwarf line table for the specified section from the entries
98// in the LineSection.
99//
David Blaikief4ad6982014-03-12 22:35:23 +0000100static inline void
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000101EmitDwarfLineTable(MCObjectStreamer *MCOS, MCSection *Section,
David Majnemer8cc30782016-01-21 01:59:03 +0000102 const MCLineSection::MCDwarfLineEntryCollection &LineEntries) {
Kevin Enderbye46564a2010-09-30 16:52:03 +0000103 unsigned FileNum = 1;
104 unsigned LastLine = 1;
105 unsigned Column = 0;
106 unsigned Flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0;
107 unsigned Isa = 0;
Diego Novillo5b5cf502014-02-14 19:27:53 +0000108 unsigned Discriminator = 0;
Craig Topperbb694de2014-04-13 04:57:38 +0000109 MCSymbol *LastLabel = nullptr;
Kevin Enderbye46564a2010-09-30 16:52:03 +0000110
David Majnemer8cc30782016-01-21 01:59:03 +0000111 // Loop through each MCDwarfLineEntry and encode the dwarf line number table.
Benjamin Kramer7b4658f2016-06-26 14:49:00 +0000112 for (const MCDwarfLineEntry &LineEntry : LineEntries) {
113 int64_t LineDelta = static_cast<int64_t>(LineEntry.getLine()) - LastLine;
Kevin Enderbye46564a2010-09-30 16:52:03 +0000114
Benjamin Kramer7b4658f2016-06-26 14:49:00 +0000115 if (FileNum != LineEntry.getFileNum()) {
116 FileNum = LineEntry.getFileNum();
Kevin Enderbye46564a2010-09-30 16:52:03 +0000117 MCOS->EmitIntValue(dwarf::DW_LNS_set_file, 1);
Rafael Espindola5e874982010-11-02 17:22:24 +0000118 MCOS->EmitULEB128IntValue(FileNum);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000119 }
Benjamin Kramer7b4658f2016-06-26 14:49:00 +0000120 if (Column != LineEntry.getColumn()) {
121 Column = LineEntry.getColumn();
Kevin Enderbye46564a2010-09-30 16:52:03 +0000122 MCOS->EmitIntValue(dwarf::DW_LNS_set_column, 1);
Rafael Espindola5e874982010-11-02 17:22:24 +0000123 MCOS->EmitULEB128IntValue(Column);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000124 }
Dehao Chen6e0c8442016-10-07 15:21:31 +0000125 if (Discriminator != LineEntry.getDiscriminator() &&
126 MCOS->getContext().getDwarfVersion() >= 4) {
Benjamin Kramer7b4658f2016-06-26 14:49:00 +0000127 Discriminator = LineEntry.getDiscriminator();
Logan Chien5b776b72014-02-22 14:00:39 +0000128 unsigned Size = getULEB128Size(Discriminator);
Diego Novillo5b5cf502014-02-14 19:27:53 +0000129 MCOS->EmitIntValue(dwarf::DW_LNS_extended_op, 1);
130 MCOS->EmitULEB128IntValue(Size + 1);
131 MCOS->EmitIntValue(dwarf::DW_LNE_set_discriminator, 1);
132 MCOS->EmitULEB128IntValue(Discriminator);
133 }
Benjamin Kramer7b4658f2016-06-26 14:49:00 +0000134 if (Isa != LineEntry.getIsa()) {
135 Isa = LineEntry.getIsa();
Kevin Enderbye46564a2010-09-30 16:52:03 +0000136 MCOS->EmitIntValue(dwarf::DW_LNS_set_isa, 1);
Rafael Espindola5e874982010-11-02 17:22:24 +0000137 MCOS->EmitULEB128IntValue(Isa);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000138 }
Benjamin Kramer7b4658f2016-06-26 14:49:00 +0000139 if ((LineEntry.getFlags() ^ Flags) & DWARF2_FLAG_IS_STMT) {
140 Flags = LineEntry.getFlags();
Kevin Enderbye46564a2010-09-30 16:52:03 +0000141 MCOS->EmitIntValue(dwarf::DW_LNS_negate_stmt, 1);
142 }
Benjamin Kramer7b4658f2016-06-26 14:49:00 +0000143 if (LineEntry.getFlags() & DWARF2_FLAG_BASIC_BLOCK)
Kevin Enderbye46564a2010-09-30 16:52:03 +0000144 MCOS->EmitIntValue(dwarf::DW_LNS_set_basic_block, 1);
Benjamin Kramer7b4658f2016-06-26 14:49:00 +0000145 if (LineEntry.getFlags() & DWARF2_FLAG_PROLOGUE_END)
Kevin Enderbye46564a2010-09-30 16:52:03 +0000146 MCOS->EmitIntValue(dwarf::DW_LNS_set_prologue_end, 1);
Benjamin Kramer7b4658f2016-06-26 14:49:00 +0000147 if (LineEntry.getFlags() & DWARF2_FLAG_EPILOGUE_BEGIN)
Kevin Enderbye46564a2010-09-30 16:52:03 +0000148 MCOS->EmitIntValue(dwarf::DW_LNS_set_epilogue_begin, 1);
149
Benjamin Kramer7b4658f2016-06-26 14:49:00 +0000150 MCSymbol *Label = LineEntry.getLabel();
Kevin Enderbye46564a2010-09-30 16:52:03 +0000151
152 // At this point we want to emit/create the sequence to encode the delta in
153 // line numbers and the increment of the address from the previous Label
154 // and the current Label.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000155 const MCAsmInfo *asmInfo = MCOS->getContext().getAsmInfo();
Evan Chengc7ac6902011-07-14 05:43:07 +0000156 MCOS->EmitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label,
Bill Wendlingbc07a892013-06-18 07:20:20 +0000157 asmInfo->getPointerSize());
Kevin Enderbye46564a2010-09-30 16:52:03 +0000158
Dehao Chen1b54fce2016-04-28 22:09:37 +0000159 Discriminator = 0;
Benjamin Kramer7b4658f2016-06-26 14:49:00 +0000160 LastLine = LineEntry.getLine();
Kevin Enderbye46564a2010-09-30 16:52:03 +0000161 LastLabel = Label;
Kevin Enderbye46564a2010-09-30 16:52:03 +0000162 }
163
164 // Emit a DW_LNE_end_sequence for the end of the section.
Rafael Espindolaf2b408c2015-03-23 21:22:04 +0000165 // Use the section end label to compute the address delta and use INT64_MAX
166 // as the line delta which is the signal that this is actually a
167 // DW_LNE_end_sequence.
168 MCSymbol *SectionEnd = MCOS->endSection(Section);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000169
Rafael Espindolaf2b408c2015-03-23 21:22:04 +0000170 // Switch back the dwarf line section, in case endSection had to switch the
171 // section.
Rafael Espindolaae3d78a2015-03-23 20:25:31 +0000172 MCContext &Ctx = MCOS->getContext();
Rafael Espindolaae3d78a2015-03-23 20:25:31 +0000173 MCOS->SwitchSection(Ctx.getObjectFileInfo()->getDwarfLineSection());
Rafael Espindolab58867c2010-11-19 02:26:16 +0000174
Rafael Espindolaae3d78a2015-03-23 20:25:31 +0000175 const MCAsmInfo *AsmInfo = Ctx.getAsmInfo();
Evan Chengc7ac6902011-07-14 05:43:07 +0000176 MCOS->EmitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd,
Rafael Espindolaae3d78a2015-03-23 20:25:31 +0000177 AsmInfo->getPointerSize());
Kevin Enderbye46564a2010-09-30 16:52:03 +0000178}
179
180//
181// This emits the Dwarf file and the line tables.
182//
Frederic Rissa5ab8442015-08-07 15:14:08 +0000183void MCDwarfLineTable::Emit(MCObjectStreamer *MCOS,
184 MCDwarfLineTableParams Params) {
Rafael Espindola0a017a62010-12-10 07:39:47 +0000185 MCContext &context = MCOS->getContext();
Kevin Enderbye46564a2010-09-30 16:52:03 +0000186
David Blaikie8bf66c42014-04-01 07:35:52 +0000187 auto &LineTables = context.getMCDwarfLineTables();
188
189 // Bail out early so we don't switch to the debug_line section needlessly and
190 // in doing so create an unnecessary (if empty) section.
191 if (LineTables.empty())
192 return;
David Blaikie11765bc2014-03-13 17:55:28 +0000193
194 // Switch to the section where the table will be emitted into.
195 MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfLineSection());
196
Manman Ren4e042a62013-02-05 21:52:47 +0000197 // Handle the rest of the Compile Units.
David Blaikie8bf66c42014-04-01 07:35:52 +0000198 for (const auto &CUIDTablePair : LineTables)
Frederic Rissa5ab8442015-08-07 15:14:08 +0000199 CUIDTablePair.second.EmitCU(MCOS, Params);
Manman Ren4e042a62013-02-05 21:52:47 +0000200}
201
Frederic Rissa5ab8442015-08-07 15:14:08 +0000202void MCDwarfDwoLineTable::Emit(MCStreamer &MCOS,
203 MCDwarfLineTableParams Params) const {
204 MCOS.EmitLabel(Header.Emit(&MCOS, Params, None).second);
David Blaikie8287aff2014-03-18 02:13:23 +0000205}
206
Frederic Rissa5ab8442015-08-07 15:14:08 +0000207std::pair<MCSymbol *, MCSymbol *>
208MCDwarfLineTableHeader::Emit(MCStreamer *MCOS,
209 MCDwarfLineTableParams Params) const {
David Blaikie8287aff2014-03-18 02:13:23 +0000210 static const char StandardOpcodeLengths[] = {
211 0, // length of DW_LNS_copy
212 1, // length of DW_LNS_advance_pc
213 1, // length of DW_LNS_advance_line
214 1, // length of DW_LNS_set_file
215 1, // length of DW_LNS_set_column
216 0, // length of DW_LNS_negate_stmt
217 0, // length of DW_LNS_set_basic_block
218 0, // length of DW_LNS_const_add_pc
219 1, // length of DW_LNS_fixed_advance_pc
220 0, // length of DW_LNS_set_prologue_end
221 0, // length of DW_LNS_set_epilogue_begin
222 1 // DW_LNS_set_isa
223 };
Frederic Rissa5ab8442015-08-07 15:14:08 +0000224 assert(array_lengthof(StandardOpcodeLengths) >=
Aaron Ballmand8ac7de2015-08-10 15:22:39 +0000225 (Params.DWARF2LineOpcodeBase - 1U));
Craig Topper0013be12015-09-21 05:32:41 +0000226 return Emit(MCOS, Params, makeArrayRef(StandardOpcodeLengths,
227 Params.DWARF2LineOpcodeBase - 1));
David Blaikie8287aff2014-03-18 02:13:23 +0000228}
229
Rafael Espindolac23174b2014-08-15 15:12:13 +0000230static const MCExpr *forceExpAbs(MCStreamer &OS, const MCExpr* Expr) {
231 MCContext &Context = OS.getContext();
232 assert(!isa<MCSymbolRefExpr>(Expr));
233 if (Context.getAsmInfo()->hasAggressiveSymbolFolding())
234 return Expr;
235
Jim Grosbach6f482002015-05-18 18:43:14 +0000236 MCSymbol *ABS = Context.createTempSymbol();
Rafael Espindolac23174b2014-08-15 15:12:13 +0000237 OS.EmitAssignment(ABS, Expr);
Jim Grosbach13760bd2015-05-30 01:25:56 +0000238 return MCSymbolRefExpr::create(ABS, Context);
Rafael Espindolac23174b2014-08-15 15:12:13 +0000239}
240
241static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size) {
242 const MCExpr *ABS = forceExpAbs(OS, Value);
243 OS.EmitValue(ABS, Size);
244}
245
David Blaikie8287aff2014-03-18 02:13:23 +0000246std::pair<MCSymbol *, MCSymbol *>
Frederic Rissa5ab8442015-08-07 15:14:08 +0000247MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
David Blaikie8287aff2014-03-18 02:13:23 +0000248 ArrayRef<char> StandardOpcodeLengths) const {
Manman Ren4e042a62013-02-05 21:52:47 +0000249 MCContext &context = MCOS->getContext();
250
251 // Create a symbol at the beginning of the line table.
David Blaikie11765bc2014-03-13 17:55:28 +0000252 MCSymbol *LineStartSym = Label;
Manman Ren4e042a62013-02-05 21:52:47 +0000253 if (!LineStartSym)
Jim Grosbach6f482002015-05-18 18:43:14 +0000254 LineStartSym = context.createTempSymbol();
Manman Ren4e042a62013-02-05 21:52:47 +0000255 // Set the value of the symbol, as we are at the start of the line table.
Kevin Enderbye46564a2010-09-30 16:52:03 +0000256 MCOS->EmitLabel(LineStartSym);
257
258 // Create a symbol for the end of the section (to be set when we get there).
Jim Grosbach6f482002015-05-18 18:43:14 +0000259 MCSymbol *LineEndSym = context.createTempSymbol();
Kevin Enderbye46564a2010-09-30 16:52:03 +0000260
261 // The first 4 bytes is the total length of the information for this
262 // compilation unit (not including these 4 bytes for the length).
Rafael Espindolac23174b2014-08-15 15:12:13 +0000263 emitAbsValue(*MCOS,
264 MakeStartMinusEndExpr(*MCOS, *LineStartSym, *LineEndSym, 4), 4);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000265
266 // Next 2 bytes is the Version, which is Dwarf 2.
267 MCOS->EmitIntValue(2, 2);
268
269 // Create a symbol for the end of the prologue (to be set when we get there).
Jim Grosbach6f482002015-05-18 18:43:14 +0000270 MCSymbol *ProEndSym = context.createTempSymbol(); // Lprologue_end
Kevin Enderbye46564a2010-09-30 16:52:03 +0000271
272 // Length of the prologue, is the next 4 bytes. Which is the start of the
273 // section to the end of the prologue. Not including the 4 bytes for the
274 // total length, the 2 bytes for the version, and these 4 bytes for the
275 // length of the prologue.
Rafael Espindolac23174b2014-08-15 15:12:13 +0000276 emitAbsValue(
277 *MCOS,
278 MakeStartMinusEndExpr(*MCOS, *LineStartSym, *ProEndSym, (4 + 2 + 4)), 4);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000279
280 // Parameters of the state machine, are next.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000281 MCOS->EmitIntValue(context.getAsmInfo()->getMinInstAlignment(), 1);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000282 MCOS->EmitIntValue(DWARF2_LINE_DEFAULT_IS_STMT, 1);
Frederic Rissa5ab8442015-08-07 15:14:08 +0000283 MCOS->EmitIntValue(Params.DWARF2LineBase, 1);
284 MCOS->EmitIntValue(Params.DWARF2LineRange, 1);
David Blaikie8287aff2014-03-18 02:13:23 +0000285 MCOS->EmitIntValue(StandardOpcodeLengths.size() + 1, 1);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000286
287 // Standard opcode lengths
David Blaikie8287aff2014-03-18 02:13:23 +0000288 for (char Length : StandardOpcodeLengths)
289 MCOS->EmitIntValue(Length, 1);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000290
291 // Put out the directory and file tables.
292
293 // First the directory table.
Kevin Enderbye46564a2010-09-30 16:52:03 +0000294 for (unsigned i = 0; i < MCDwarfDirs.size(); i++) {
Eric Christophere3ab3d02013-01-09 01:57:54 +0000295 MCOS->EmitBytes(MCDwarfDirs[i]); // the DirectoryName
296 MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string
Kevin Enderbye46564a2010-09-30 16:52:03 +0000297 }
298 MCOS->EmitIntValue(0, 1); // Terminate the directory list
299
300 // Second the file table.
Kevin Enderbye46564a2010-09-30 16:52:03 +0000301 for (unsigned i = 1; i < MCDwarfFiles.size(); i++) {
David Blaikiec2df16b2014-03-17 18:13:58 +0000302 assert(!MCDwarfFiles[i].Name.empty());
David Blaikiea55ddad2014-03-13 18:55:04 +0000303 MCOS->EmitBytes(MCDwarfFiles[i].Name); // FileName
Eric Christophere3ab3d02013-01-09 01:57:54 +0000304 MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string
Rafael Espindola5e874982010-11-02 17:22:24 +0000305 // the Directory num
David Blaikiea55ddad2014-03-13 18:55:04 +0000306 MCOS->EmitULEB128IntValue(MCDwarfFiles[i].DirIndex);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000307 MCOS->EmitIntValue(0, 1); // last modification timestamp (always 0)
308 MCOS->EmitIntValue(0, 1); // filesize (always 0)
309 }
310 MCOS->EmitIntValue(0, 1); // Terminate the file list
311
312 // This is the end of the prologue, so set the value of the symbol at the
313 // end of the prologue (that was used in a previous expression).
314 MCOS->EmitLabel(ProEndSym);
315
David Blaikie5cff0e62014-03-13 21:47:12 +0000316 return std::make_pair(LineStartSym, LineEndSym);
317}
318
Frederic Rissa5ab8442015-08-07 15:14:08 +0000319void MCDwarfLineTable::EmitCU(MCObjectStreamer *MCOS,
320 MCDwarfLineTableParams Params) const {
321 MCSymbol *LineEndSym = Header.Emit(MCOS, Params).second;
David Blaikie5cff0e62014-03-13 21:47:12 +0000322
Kevin Enderbye46564a2010-09-30 16:52:03 +0000323 // Put out the line tables.
David Blaikie11765bc2014-03-13 17:55:28 +0000324 for (const auto &LineSec : MCLineSections.getMCLineEntries())
325 EmitDwarfLineTable(MCOS, LineSec.first, LineSec.second);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000326
Kevin Enderbye46564a2010-09-30 16:52:03 +0000327 // This is the end of the section, so set the value of the symbol at the end
328 // of this section (that was used in a previous expression).
329 MCOS->EmitLabel(LineEndSym);
330}
331
David Blaikiec2df16b2014-03-17 18:13:58 +0000332unsigned MCDwarfLineTable::getFile(StringRef &Directory, StringRef &FileName,
David Blaikied9012ba2014-03-13 21:59:51 +0000333 unsigned FileNumber) {
David Blaikie5cff0e62014-03-13 21:47:12 +0000334 return Header.getFile(Directory, FileName, FileNumber);
335}
336
David Blaikiec2df16b2014-03-17 18:13:58 +0000337unsigned MCDwarfLineTableHeader::getFile(StringRef &Directory,
338 StringRef &FileName,
David Blaikiec714ef42014-03-17 01:52:11 +0000339 unsigned FileNumber) {
David Blaikiec7f29dc2014-03-17 23:29:40 +0000340 if (Directory == CompilationDir)
341 Directory = "";
David Blaikiec2df16b2014-03-17 18:13:58 +0000342 if (FileName.empty()) {
343 FileName = "<stdin>";
344 Directory = "";
345 }
346 assert(!FileName.empty());
David Blaikiec714ef42014-03-17 01:52:11 +0000347 if (FileNumber == 0) {
Adrian Prantld6cc53f2016-03-09 17:32:56 +0000348 // File numbers start with 1 and/or after any file numbers
349 // allocated by inline-assembler .file directives.
350 FileNumber = MCDwarfFiles.empty() ? 1 : MCDwarfFiles.size();
Pete Cooperb7800812015-05-20 19:12:14 +0000351 SmallString<256> Buffer;
David Blaikie5106ce72014-11-19 05:49:42 +0000352 auto IterBool = SourceIdMap.insert(
Pete Cooperb7800812015-05-20 19:12:14 +0000353 std::make_pair((Directory + Twine('\0') + FileName).toStringRef(Buffer),
354 FileNumber));
David Blaikie5106ce72014-11-19 05:49:42 +0000355 if (!IterBool.second)
356 return IterBool.first->second;
David Blaikiec714ef42014-03-17 01:52:11 +0000357 }
David Blaikie498589c2014-03-13 19:15:04 +0000358 // Make space for this FileNumber in the MCDwarfFiles vector if needed.
359 MCDwarfFiles.resize(FileNumber + 1);
360
361 // Get the new MCDwarfFile slot for this FileNumber.
362 MCDwarfFile &File = MCDwarfFiles[FileNumber];
363
364 // It is an error to use see the same number more than once.
365 if (!File.Name.empty())
366 return 0;
367
368 if (Directory.empty()) {
369 // Separate the directory part from the basename of the FileName.
370 StringRef tFileName = sys::path::filename(FileName);
371 if (!tFileName.empty()) {
372 Directory = sys::path::parent_path(FileName);
373 if (!Directory.empty())
374 FileName = tFileName;
375 }
376 }
377
378 // Find or make an entry in the MCDwarfDirs vector for this Directory.
379 // Capture directory name.
380 unsigned DirIndex;
381 if (Directory.empty()) {
382 // For FileNames with no directories a DirIndex of 0 is used.
383 DirIndex = 0;
384 } else {
385 DirIndex = 0;
386 for (unsigned End = MCDwarfDirs.size(); DirIndex < End; DirIndex++) {
387 if (Directory == MCDwarfDirs[DirIndex])
388 break;
389 }
390 if (DirIndex >= MCDwarfDirs.size())
391 MCDwarfDirs.push_back(Directory);
392 // The DirIndex is one based, as DirIndex of 0 is used for FileNames with
393 // no directories. MCDwarfDirs[] is unlike MCDwarfFiles[] in that the
394 // directory names are stored at MCDwarfDirs[DirIndex-1] where FileNames
395 // are stored at MCDwarfFiles[FileNumber].Name .
396 DirIndex++;
397 }
398
399 File.Name = FileName;
400 File.DirIndex = DirIndex;
401
402 // return the allocated FileNumber.
403 return FileNumber;
404}
405
Kevin Enderbye46564a2010-09-30 16:52:03 +0000406/// Utility function to emit the encoding to a streamer.
Frederic Rissa5ab8442015-08-07 15:14:08 +0000407void MCDwarfLineAddr::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
408 int64_t LineDelta, uint64_t AddrDelta) {
Ulrich Weigand32d725b2013-06-12 14:46:54 +0000409 MCContext &Context = MCOS->getContext();
Alp Tokere69170a2014-06-26 22:52:05 +0000410 SmallString<256> Tmp;
411 raw_svector_ostream OS(Tmp);
Frederic Rissa5ab8442015-08-07 15:14:08 +0000412 MCDwarfLineAddr::Encode(Context, Params, LineDelta, AddrDelta, OS);
Eric Christophere3ab3d02013-01-09 01:57:54 +0000413 MCOS->EmitBytes(OS.str());
Kevin Enderbye46564a2010-09-30 16:52:03 +0000414}
415
Frederic Rissa5ab8442015-08-07 15:14:08 +0000416/// Given a special op, return the address skip amount (in units of
417/// DWARF2_LINE_MIN_INSN_LENGTH).
418static uint64_t SpecialAddr(MCDwarfLineTableParams Params, uint64_t op) {
419 return (op - Params.DWARF2LineOpcodeBase) / Params.DWARF2LineRange;
420}
421
Kevin Enderbye46564a2010-09-30 16:52:03 +0000422/// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
Frederic Rissa5ab8442015-08-07 15:14:08 +0000423void MCDwarfLineAddr::Encode(MCContext &Context, MCDwarfLineTableParams Params,
424 int64_t LineDelta, uint64_t AddrDelta,
425 raw_ostream &OS) {
Kevin Enderbye46564a2010-09-30 16:52:03 +0000426 uint64_t Temp, Opcode;
427 bool NeedCopy = false;
428
Frederic Rissa5ab8442015-08-07 15:14:08 +0000429 // The maximum address skip amount that can be encoded with a special op.
430 uint64_t MaxSpecialAddrDelta = SpecialAddr(Params, 255);
431
Kevin Enderbye46564a2010-09-30 16:52:03 +0000432 // Scale the address delta by the minimum instruction length.
Ulrich Weigand32d725b2013-06-12 14:46:54 +0000433 AddrDelta = ScaleAddrDelta(Context, AddrDelta);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000434
435 // A LineDelta of INT64_MAX is a signal that this is actually a
Jim Grosbachdc1e36e2012-05-11 01:41:30 +0000436 // DW_LNE_end_sequence. We cannot use special opcodes here, since we want the
Kevin Enderbye46564a2010-09-30 16:52:03 +0000437 // end_sequence to emit the matrix entry.
438 if (LineDelta == INT64_MAX) {
Frederic Rissa5ab8442015-08-07 15:14:08 +0000439 if (AddrDelta == MaxSpecialAddrDelta)
Kevin Enderbye46564a2010-09-30 16:52:03 +0000440 OS << char(dwarf::DW_LNS_const_add_pc);
Frederic Rissceb18362015-03-15 20:45:39 +0000441 else if (AddrDelta) {
Kevin Enderbye46564a2010-09-30 16:52:03 +0000442 OS << char(dwarf::DW_LNS_advance_pc);
Jim Grosbachbf387df2012-08-08 23:56:06 +0000443 encodeULEB128(AddrDelta, OS);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000444 }
445 OS << char(dwarf::DW_LNS_extended_op);
446 OS << char(1);
447 OS << char(dwarf::DW_LNE_end_sequence);
448 return;
449 }
450
451 // Bias the line delta by the base.
Frederic Rissa5ab8442015-08-07 15:14:08 +0000452 Temp = LineDelta - Params.DWARF2LineBase;
Kevin Enderbye46564a2010-09-30 16:52:03 +0000453
454 // If the line increment is out of range of a special opcode, we must encode
455 // it with DW_LNS_advance_line.
Frederic Risse5b78d82016-01-31 22:06:35 +0000456 if (Temp >= Params.DWARF2LineRange ||
457 Temp + Params.DWARF2LineOpcodeBase > 255) {
Kevin Enderbye46564a2010-09-30 16:52:03 +0000458 OS << char(dwarf::DW_LNS_advance_line);
Jim Grosbachbf387df2012-08-08 23:56:06 +0000459 encodeSLEB128(LineDelta, OS);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000460
461 LineDelta = 0;
Frederic Rissa5ab8442015-08-07 15:14:08 +0000462 Temp = 0 - Params.DWARF2LineBase;
Kevin Enderbye46564a2010-09-30 16:52:03 +0000463 NeedCopy = true;
464 }
465
466 // Use DW_LNS_copy instead of a "line +0, addr +0" special opcode.
467 if (LineDelta == 0 && AddrDelta == 0) {
468 OS << char(dwarf::DW_LNS_copy);
469 return;
470 }
471
472 // Bias the opcode by the special opcode base.
Frederic Rissa5ab8442015-08-07 15:14:08 +0000473 Temp += Params.DWARF2LineOpcodeBase;
Kevin Enderbye46564a2010-09-30 16:52:03 +0000474
475 // Avoid overflow when addr_delta is large.
Frederic Rissa5ab8442015-08-07 15:14:08 +0000476 if (AddrDelta < 256 + MaxSpecialAddrDelta) {
Kevin Enderbye46564a2010-09-30 16:52:03 +0000477 // Try using a special opcode.
Frederic Rissa5ab8442015-08-07 15:14:08 +0000478 Opcode = Temp + AddrDelta * Params.DWARF2LineRange;
Kevin Enderbye46564a2010-09-30 16:52:03 +0000479 if (Opcode <= 255) {
480 OS << char(Opcode);
481 return;
482 }
483
484 // Try using DW_LNS_const_add_pc followed by special op.
Frederic Rissa5ab8442015-08-07 15:14:08 +0000485 Opcode = Temp + (AddrDelta - MaxSpecialAddrDelta) * Params.DWARF2LineRange;
Kevin Enderbye46564a2010-09-30 16:52:03 +0000486 if (Opcode <= 255) {
487 OS << char(dwarf::DW_LNS_const_add_pc);
488 OS << char(Opcode);
489 return;
490 }
491 }
492
493 // Otherwise use DW_LNS_advance_pc.
494 OS << char(dwarf::DW_LNS_advance_pc);
Jim Grosbachbf387df2012-08-08 23:56:06 +0000495 encodeULEB128(AddrDelta, OS);
Kevin Enderbye46564a2010-09-30 16:52:03 +0000496
497 if (NeedCopy)
498 OS << char(dwarf::DW_LNS_copy);
Frederic Risse5b78d82016-01-31 22:06:35 +0000499 else {
500 assert(Temp <= 255 && "Buggy special opcode encoding.");
Kevin Enderbye46564a2010-09-30 16:52:03 +0000501 OS << char(Temp);
Frederic Risse5b78d82016-01-31 22:06:35 +0000502 }
Kevin Enderbye46564a2010-09-30 16:52:03 +0000503}
504
Kevin Enderbye7739d42011-12-09 18:09:40 +0000505// Utility function to write a tuple for .debug_abbrev.
506static void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form) {
507 MCOS->EmitULEB128IntValue(Name);
508 MCOS->EmitULEB128IntValue(Form);
509}
510
511// When generating dwarf for assembly source files this emits
512// the data for .debug_abbrev section which contains three DIEs.
513static void EmitGenDwarfAbbrev(MCStreamer *MCOS) {
514 MCContext &context = MCOS->getContext();
515 MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection());
516
517 // DW_TAG_compile_unit DIE abbrev (1).
518 MCOS->EmitULEB128IntValue(1);
519 MCOS->EmitULEB128IntValue(dwarf::DW_TAG_compile_unit);
520 MCOS->EmitIntValue(dwarf::DW_CHILDREN_yes, 1);
Paul Robinsone95fa422016-01-04 18:49:15 +0000521 EmitAbbrev(MCOS, dwarf::DW_AT_stmt_list, context.getDwarfVersion() >= 4
522 ? dwarf::DW_FORM_sec_offset
523 : dwarf::DW_FORM_data4);
Paul Robinson22d0d312015-12-23 01:57:31 +0000524 if (context.getGenDwarfSectionSyms().size() > 1 &&
525 context.getDwarfVersion() >= 3) {
Paul Robinsone95fa422016-01-04 18:49:15 +0000526 EmitAbbrev(MCOS, dwarf::DW_AT_ranges, context.getDwarfVersion() >= 4
527 ? dwarf::DW_FORM_sec_offset
Paul Robinson22d0d312015-12-23 01:57:31 +0000528 : dwarf::DW_FORM_data4);
Oliver Stannard8b273082014-06-19 15:52:37 +0000529 } else {
530 EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
531 EmitAbbrev(MCOS, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr);
532 }
Kevin Enderbye7739d42011-12-09 18:09:40 +0000533 EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
Andrew Trick32591d32013-12-10 04:39:09 +0000534 if (!context.getCompilationDir().empty())
535 EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000536 StringRef DwarfDebugFlags = context.getDwarfDebugFlags();
537 if (!DwarfDebugFlags.empty())
538 EmitAbbrev(MCOS, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string);
539 EmitAbbrev(MCOS, dwarf::DW_AT_producer, dwarf::DW_FORM_string);
540 EmitAbbrev(MCOS, dwarf::DW_AT_language, dwarf::DW_FORM_data2);
541 EmitAbbrev(MCOS, 0, 0);
542
Kevin Enderby8d4a2202012-01-10 17:52:29 +0000543 // DW_TAG_label DIE abbrev (2).
Kevin Enderbye7739d42011-12-09 18:09:40 +0000544 MCOS->EmitULEB128IntValue(2);
Kevin Enderby8d4a2202012-01-10 17:52:29 +0000545 MCOS->EmitULEB128IntValue(dwarf::DW_TAG_label);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000546 MCOS->EmitIntValue(dwarf::DW_CHILDREN_yes, 1);
547 EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
548 EmitAbbrev(MCOS, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data4);
549 EmitAbbrev(MCOS, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data4);
550 EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000551 EmitAbbrev(MCOS, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag);
552 EmitAbbrev(MCOS, 0, 0);
553
554 // DW_TAG_unspecified_parameters DIE abbrev (3).
555 MCOS->EmitULEB128IntValue(3);
556 MCOS->EmitULEB128IntValue(dwarf::DW_TAG_unspecified_parameters);
557 MCOS->EmitIntValue(dwarf::DW_CHILDREN_no, 1);
558 EmitAbbrev(MCOS, 0, 0);
559
560 // Terminate the abbreviations for this compilation unit.
561 MCOS->EmitIntValue(0, 1);
562}
563
564// When generating dwarf for assembly source files this emits the data for
Oliver Stannard8b273082014-06-19 15:52:37 +0000565// .debug_aranges section. This section contains a header and a table of pairs
566// of PointerSize'ed values for the address and size of section(s) with line
567// table entries.
Alexey Samsonov00fd5252012-11-14 09:55:38 +0000568static void EmitGenDwarfAranges(MCStreamer *MCOS,
569 const MCSymbol *InfoSectionSymbol) {
Kevin Enderbye7739d42011-12-09 18:09:40 +0000570 MCContext &context = MCOS->getContext();
571
Oliver Stannard8b273082014-06-19 15:52:37 +0000572 auto &Sections = context.getGenDwarfSectionSyms();
Kevin Enderbye7739d42011-12-09 18:09:40 +0000573
574 MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection());
575
576 // This will be the length of the .debug_aranges section, first account for
577 // the size of each item in the header (see below where we emit these items).
578 int Length = 4 + 2 + 4 + 1 + 1;
579
580 // Figure the padding after the header before the table of address and size
581 // pairs who's values are PointerSize'ed.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000582 const MCAsmInfo *asmInfo = context.getAsmInfo();
583 int AddrSize = asmInfo->getPointerSize();
Kevin Enderbye7739d42011-12-09 18:09:40 +0000584 int Pad = 2 * AddrSize - (Length & (2 * AddrSize - 1));
585 if (Pad == 2 * AddrSize)
586 Pad = 0;
587 Length += Pad;
588
589 // Add the size of the pair of PointerSize'ed values for the address and size
Oliver Stannard8b273082014-06-19 15:52:37 +0000590 // of each section we have in the table.
591 Length += 2 * AddrSize * Sections.size();
Kevin Enderbye7739d42011-12-09 18:09:40 +0000592 // And the pair of terminating zeros.
593 Length += 2 * AddrSize;
594
595
596 // Emit the header for this section.
597 // The 4 byte length not including the 4 byte value for the length.
598 MCOS->EmitIntValue(Length - 4, 4);
599 // The 2 byte version, which is 2.
600 MCOS->EmitIntValue(2, 2);
601 // The 4 byte offset to the compile unit in the .debug_info from the start
Alexey Samsonov00fd5252012-11-14 09:55:38 +0000602 // of the .debug_info.
603 if (InfoSectionSymbol)
Saleem Abdulrasoolfcefa212014-09-06 19:57:48 +0000604 MCOS->EmitSymbolValue(InfoSectionSymbol, 4,
605 asmInfo->needsDwarfSectionOffsetDirective());
Alexey Samsonov00fd5252012-11-14 09:55:38 +0000606 else
607 MCOS->EmitIntValue(0, 4);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000608 // The 1 byte size of an address.
609 MCOS->EmitIntValue(AddrSize, 1);
610 // The 1 byte size of a segment descriptor, we use a value of zero.
611 MCOS->EmitIntValue(0, 1);
612 // Align the header with the padding if needed, before we put out the table.
613 for(int i = 0; i < Pad; i++)
614 MCOS->EmitIntValue(0, 1);
615
Oliver Stannard8b273082014-06-19 15:52:37 +0000616 // Now emit the table of pairs of PointerSize'ed values for the section
617 // addresses and sizes.
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000618 for (MCSection *Sec : Sections) {
619 const MCSymbol *StartSymbol = Sec->getBeginSymbol();
Rafael Espindolae0746792015-05-21 16:52:32 +0000620 MCSymbol *EndSymbol = Sec->getEndSymbol(context);
Oliver Stannard8b273082014-06-19 15:52:37 +0000621 assert(StartSymbol && "StartSymbol must not be NULL");
622 assert(EndSymbol && "EndSymbol must not be NULL");
623
Jim Grosbach13760bd2015-05-30 01:25:56 +0000624 const MCExpr *Addr = MCSymbolRefExpr::create(
Oliver Stannard8b273082014-06-19 15:52:37 +0000625 StartSymbol, MCSymbolRefExpr::VK_None, context);
626 const MCExpr *Size = MakeStartMinusEndExpr(*MCOS,
627 *StartSymbol, *EndSymbol, 0);
628 MCOS->EmitValue(Addr, AddrSize);
Rafael Espindolac23174b2014-08-15 15:12:13 +0000629 emitAbsValue(*MCOS, Size, AddrSize);
Oliver Stannard8b273082014-06-19 15:52:37 +0000630 }
Kevin Enderbye7739d42011-12-09 18:09:40 +0000631
632 // And finally the pair of terminating zeros.
633 MCOS->EmitIntValue(0, AddrSize);
634 MCOS->EmitIntValue(0, AddrSize);
635}
636
637// When generating dwarf for assembly source files this emits the data for
638// .debug_info section which contains three parts. The header, the compile_unit
Kevin Enderby8d4a2202012-01-10 17:52:29 +0000639// DIE and a list of label DIEs.
Rafael Espindolac22c85c2012-02-28 21:13:05 +0000640static void EmitGenDwarfInfo(MCStreamer *MCOS,
641 const MCSymbol *AbbrevSectionSymbol,
Oliver Stannard8b273082014-06-19 15:52:37 +0000642 const MCSymbol *LineSectionSymbol,
643 const MCSymbol *RangesSectionSymbol) {
Kevin Enderbye7739d42011-12-09 18:09:40 +0000644 MCContext &context = MCOS->getContext();
645
Jim Grosbachdc1e36e2012-05-11 01:41:30 +0000646 MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection());
Kevin Enderbye7739d42011-12-09 18:09:40 +0000647
648 // Create a symbol at the start and end of this section used in here for the
649 // expression to calculate the length in the header.
Jim Grosbach6f482002015-05-18 18:43:14 +0000650 MCSymbol *InfoStart = context.createTempSymbol();
Kevin Enderbye7739d42011-12-09 18:09:40 +0000651 MCOS->EmitLabel(InfoStart);
Jim Grosbach6f482002015-05-18 18:43:14 +0000652 MCSymbol *InfoEnd = context.createTempSymbol();
Kevin Enderbye7739d42011-12-09 18:09:40 +0000653
654 // First part: the header.
655
656 // The 4 byte total length of the information for this compilation unit, not
657 // including these 4 bytes.
658 const MCExpr *Length = MakeStartMinusEndExpr(*MCOS, *InfoStart, *InfoEnd, 4);
Rafael Espindolac23174b2014-08-15 15:12:13 +0000659 emitAbsValue(*MCOS, Length, 4);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000660
Oliver Stannard7eacbd52014-05-01 08:46:02 +0000661 // The 2 byte DWARF version.
662 MCOS->EmitIntValue(context.getDwarfVersion(), 2);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000663
Saleem Abdulrasool00426d92014-07-19 21:01:58 +0000664 const MCAsmInfo &AsmInfo = *context.getAsmInfo();
Kevin Enderbye7739d42011-12-09 18:09:40 +0000665 // The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev,
666 // it is at the start of that section so this is zero.
Saleem Abdulrasool7d095302014-07-17 16:27:44 +0000667 if (AbbrevSectionSymbol == nullptr)
Rafael Espindolac22c85c2012-02-28 21:13:05 +0000668 MCOS->EmitIntValue(0, 4);
Saleem Abdulrasool7d095302014-07-17 16:27:44 +0000669 else
Saleem Abdulrasool00426d92014-07-19 21:01:58 +0000670 MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4,
671 AsmInfo.needsDwarfSectionOffsetDirective());
Kevin Enderbye7739d42011-12-09 18:09:40 +0000672
Bill Wendlingbc07a892013-06-18 07:20:20 +0000673 const MCAsmInfo *asmInfo = context.getAsmInfo();
674 int AddrSize = asmInfo->getPointerSize();
Kevin Enderbye7739d42011-12-09 18:09:40 +0000675 // The 1 byte size of an address.
676 MCOS->EmitIntValue(AddrSize, 1);
677
678 // Second part: the compile_unit DIE.
679
680 // The DW_TAG_compile_unit DIE abbrev (1).
681 MCOS->EmitULEB128IntValue(1);
682
683 // DW_AT_stmt_list, a 4 byte offset from the start of the .debug_line section,
684 // which is at the start of that section so this is zero.
Saleem Abdulrasool5c70de12014-09-05 04:15:00 +0000685 if (LineSectionSymbol)
686 MCOS->EmitSymbolValue(LineSectionSymbol, 4,
687 AsmInfo.needsDwarfSectionOffsetDirective());
688 else
Rafael Espindolac22c85c2012-02-28 21:13:05 +0000689 MCOS->EmitIntValue(0, 4);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000690
Oliver Stannard8b273082014-06-19 15:52:37 +0000691 if (RangesSectionSymbol) {
692 // There are multiple sections containing code, so we must use the
693 // .debug_ranges sections.
Kevin Enderbye7739d42011-12-09 18:09:40 +0000694
Oliver Stannard8b273082014-06-19 15:52:37 +0000695 // AT_ranges, the 4 byte offset from the start of the .debug_ranges section
696 // to the address range list for this compilation unit.
697 MCOS->EmitSymbolValue(RangesSectionSymbol, 4);
698 } else {
699 // If we only have one non-empty code section, we can use the simpler
700 // AT_low_pc and AT_high_pc attributes.
701
702 // Find the first (and only) non-empty text section
703 auto &Sections = context.getGenDwarfSectionSyms();
704 const auto TextSection = Sections.begin();
705 assert(TextSection != Sections.end() && "No text section found");
706
Rafael Espindolae0746792015-05-21 16:52:32 +0000707 MCSymbol *StartSymbol = (*TextSection)->getBeginSymbol();
708 MCSymbol *EndSymbol = (*TextSection)->getEndSymbol(context);
Oliver Stannard8b273082014-06-19 15:52:37 +0000709 assert(StartSymbol && "StartSymbol must not be NULL");
710 assert(EndSymbol && "EndSymbol must not be NULL");
711
712 // AT_low_pc, the first address of the default .text section.
Jim Grosbach13760bd2015-05-30 01:25:56 +0000713 const MCExpr *Start = MCSymbolRefExpr::create(
Oliver Stannard8b273082014-06-19 15:52:37 +0000714 StartSymbol, MCSymbolRefExpr::VK_None, context);
715 MCOS->EmitValue(Start, AddrSize);
716
717 // AT_high_pc, the last address of the default .text section.
Jim Grosbach13760bd2015-05-30 01:25:56 +0000718 const MCExpr *End = MCSymbolRefExpr::create(
Oliver Stannard8b273082014-06-19 15:52:37 +0000719 EndSymbol, MCSymbolRefExpr::VK_None, context);
720 MCOS->EmitValue(End, AddrSize);
721 }
Kevin Enderbye7739d42011-12-09 18:09:40 +0000722
723 // AT_name, the name of the source file. Reconstruct from the first directory
724 // and file table entries.
David Blaikie533490de2014-03-13 19:05:33 +0000725 const SmallVectorImpl<std::string> &MCDwarfDirs = context.getMCDwarfDirs();
Kevin Enderbye7739d42011-12-09 18:09:40 +0000726 if (MCDwarfDirs.size() > 0) {
Eric Christophere3ab3d02013-01-09 01:57:54 +0000727 MCOS->EmitBytes(MCDwarfDirs[0]);
Yaron Keren15217202014-05-16 13:16:30 +0000728 MCOS->EmitBytes(sys::path::get_separator());
Kevin Enderbye7739d42011-12-09 18:09:40 +0000729 }
David Blaikiea55ddad2014-03-13 18:55:04 +0000730 const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles =
Kevin Enderbye7739d42011-12-09 18:09:40 +0000731 MCOS->getContext().getMCDwarfFiles();
David Blaikiea55ddad2014-03-13 18:55:04 +0000732 MCOS->EmitBytes(MCDwarfFiles[1].Name);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000733 MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
734
735 // AT_comp_dir, the working directory the assembly was done in.
Andrew Trick32591d32013-12-10 04:39:09 +0000736 if (!context.getCompilationDir().empty()) {
737 MCOS->EmitBytes(context.getCompilationDir());
738 MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
739 }
Kevin Enderbye7739d42011-12-09 18:09:40 +0000740
741 // AT_APPLE_flags, the command line arguments of the assembler tool.
742 StringRef DwarfDebugFlags = context.getDwarfDebugFlags();
743 if (!DwarfDebugFlags.empty()){
Eric Christophere3ab3d02013-01-09 01:57:54 +0000744 MCOS->EmitBytes(DwarfDebugFlags);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000745 MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
746 }
747
748 // AT_producer, the version of the assembler tool.
Kevin Enderbye82ada62013-01-16 17:46:23 +0000749 StringRef DwarfDebugProducer = context.getDwarfDebugProducer();
Saleem Abdulrasool19f8bc62014-07-17 16:27:35 +0000750 if (!DwarfDebugProducer.empty())
Kevin Enderbye82ada62013-01-16 17:46:23 +0000751 MCOS->EmitBytes(DwarfDebugProducer);
Saleem Abdulrasool19f8bc62014-07-17 16:27:35 +0000752 else
753 MCOS->EmitBytes(StringRef("llvm-mc (based on LLVM " PACKAGE_VERSION ")"));
Kevin Enderbye7739d42011-12-09 18:09:40 +0000754 MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
755
756 // AT_language, a 4 byte value. We use DW_LANG_Mips_Assembler as the dwarf2
757 // draft has no standard code for assembler.
758 MCOS->EmitIntValue(dwarf::DW_LANG_Mips_Assembler, 2);
759
Kevin Enderby8d4a2202012-01-10 17:52:29 +0000760 // Third part: the list of label DIEs.
Kevin Enderbye7739d42011-12-09 18:09:40 +0000761
Kevin Enderbyf7d77062012-01-10 21:12:34 +0000762 // Loop on saved info for dwarf labels and create the DIEs for them.
David Blaikie1e0fc8f2014-04-11 00:43:52 +0000763 const std::vector<MCGenDwarfLabelEntry> &Entries =
764 MCOS->getContext().getMCGenDwarfLabelEntries();
765 for (const auto &Entry : Entries) {
Kevin Enderby8d4a2202012-01-10 17:52:29 +0000766 // The DW_TAG_label DIE abbrev (2).
Kevin Enderbye7739d42011-12-09 18:09:40 +0000767 MCOS->EmitULEB128IntValue(2);
768
769 // AT_name, of the label without any leading underbar.
David Blaikie1e0fc8f2014-04-11 00:43:52 +0000770 MCOS->EmitBytes(Entry.getName());
Kevin Enderbye7739d42011-12-09 18:09:40 +0000771 MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
772
773 // AT_decl_file, index into the file table.
David Blaikie1e0fc8f2014-04-11 00:43:52 +0000774 MCOS->EmitIntValue(Entry.getFileNumber(), 4);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000775
776 // AT_decl_line, source line number.
David Blaikie1e0fc8f2014-04-11 00:43:52 +0000777 MCOS->EmitIntValue(Entry.getLineNumber(), 4);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000778
779 // AT_low_pc, start address of the label.
Jim Grosbach13760bd2015-05-30 01:25:56 +0000780 const MCExpr *AT_low_pc = MCSymbolRefExpr::create(Entry.getLabel(),
Kevin Enderbye7739d42011-12-09 18:09:40 +0000781 MCSymbolRefExpr::VK_None, context);
Rafael Espindola98629c42014-03-20 21:26:38 +0000782 MCOS->EmitValue(AT_low_pc, AddrSize);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000783
Kevin Enderbye7739d42011-12-09 18:09:40 +0000784 // DW_AT_prototyped, a one byte flag value of 0 saying we have no prototype.
785 MCOS->EmitIntValue(0, 1);
786
787 // The DW_TAG_unspecified_parameters DIE abbrev (3).
788 MCOS->EmitULEB128IntValue(3);
789
790 // Add the NULL DIE terminating the DW_TAG_unspecified_parameters DIE's.
791 MCOS->EmitIntValue(0, 1);
792 }
Kevin Enderbye7739d42011-12-09 18:09:40 +0000793
794 // Add the NULL DIE terminating the Compile Unit DIE's.
795 MCOS->EmitIntValue(0, 1);
796
797 // Now set the value of the symbol at the end of the info section.
798 MCOS->EmitLabel(InfoEnd);
799}
800
Oliver Stannard8b273082014-06-19 15:52:37 +0000801// When generating dwarf for assembly source files this emits the data for
802// .debug_ranges section. We only emit one range list, which spans all of the
803// executable sections of this file.
804static void EmitGenDwarfRanges(MCStreamer *MCOS) {
805 MCContext &context = MCOS->getContext();
806 auto &Sections = context.getGenDwarfSectionSyms();
807
808 const MCAsmInfo *AsmInfo = context.getAsmInfo();
809 int AddrSize = AsmInfo->getPointerSize();
810
811 MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfRangesSection());
812
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000813 for (MCSection *Sec : Sections) {
814 const MCSymbol *StartSymbol = Sec->getBeginSymbol();
Rafael Espindolae0746792015-05-21 16:52:32 +0000815 MCSymbol *EndSymbol = Sec->getEndSymbol(context);
Oliver Stannard8b273082014-06-19 15:52:37 +0000816 assert(StartSymbol && "StartSymbol must not be NULL");
817 assert(EndSymbol && "EndSymbol must not be NULL");
818
819 // Emit a base address selection entry for the start of this section
Jim Grosbach13760bd2015-05-30 01:25:56 +0000820 const MCExpr *SectionStartAddr = MCSymbolRefExpr::create(
Oliver Stannard8b273082014-06-19 15:52:37 +0000821 StartSymbol, MCSymbolRefExpr::VK_None, context);
Petr Hosekfaef3202016-06-01 01:59:58 +0000822 MCOS->emitFill(AddrSize, 0xFF);
Oliver Stannard8b273082014-06-19 15:52:37 +0000823 MCOS->EmitValue(SectionStartAddr, AddrSize);
824
825 // Emit a range list entry spanning this section
826 const MCExpr *SectionSize = MakeStartMinusEndExpr(*MCOS,
827 *StartSymbol, *EndSymbol, 0);
828 MCOS->EmitIntValue(0, AddrSize);
Rafael Espindolac23174b2014-08-15 15:12:13 +0000829 emitAbsValue(*MCOS, SectionSize, AddrSize);
Oliver Stannard8b273082014-06-19 15:52:37 +0000830 }
831
832 // Emit end of list entry
833 MCOS->EmitIntValue(0, AddrSize);
834 MCOS->EmitIntValue(0, AddrSize);
835}
836
Kevin Enderbye7739d42011-12-09 18:09:40 +0000837//
838// When generating dwarf for assembly source files this emits the Dwarf
839// sections.
840//
David Blaikie8bf66c42014-04-01 07:35:52 +0000841void MCGenDwarfInfo::Emit(MCStreamer *MCOS) {
Kevin Enderbye7739d42011-12-09 18:09:40 +0000842 MCContext &context = MCOS->getContext();
Oliver Stannard8b273082014-06-19 15:52:37 +0000843
844 // Create the dwarf sections in this order (.debug_line already created).
Bill Wendlingbc07a892013-06-18 07:20:20 +0000845 const MCAsmInfo *AsmInfo = context.getAsmInfo();
Alexey Samsonov00fd5252012-11-14 09:55:38 +0000846 bool CreateDwarfSectionSymbols =
Bill Wendlingbc07a892013-06-18 07:20:20 +0000847 AsmInfo->doesDwarfUseRelocationsAcrossSections();
David Blaikie8bf66c42014-04-01 07:35:52 +0000848 MCSymbol *LineSectionSymbol = nullptr;
David Blaikie34641612014-04-01 08:07:52 +0000849 if (CreateDwarfSectionSymbols)
850 LineSectionSymbol = MCOS->getDwarfLineTableSymbol(0);
Craig Topperbb694de2014-04-13 04:57:38 +0000851 MCSymbol *AbbrevSectionSymbol = nullptr;
852 MCSymbol *InfoSectionSymbol = nullptr;
Hans Wennborg083ca9b2015-10-06 23:24:35 +0000853 MCSymbol *RangesSectionSymbol = nullptr;
Oliver Stannard8b273082014-06-19 15:52:37 +0000854
855 // Create end symbols for each section, and remove empty sections
856 MCOS->getContext().finalizeDwarfSections(*MCOS);
857
858 // If there are no sections to generate debug info for, we don't need
859 // to do anything
860 if (MCOS->getContext().getGenDwarfSectionSyms().empty())
861 return;
862
Oliver Stannard14f97d02014-09-22 10:45:16 +0000863 // We only use the .debug_ranges section if we have multiple code sections,
864 // and we are emitting a DWARF version which supports it.
Oliver Stannard8b273082014-06-19 15:52:37 +0000865 const bool UseRangesSection =
Oliver Stannard14f97d02014-09-22 10:45:16 +0000866 MCOS->getContext().getGenDwarfSectionSyms().size() > 1 &&
867 MCOS->getContext().getDwarfVersion() >= 3;
Oliver Stannard8b273082014-06-19 15:52:37 +0000868 CreateDwarfSectionSymbols |= UseRangesSection;
869
Kevin Enderbye7739d42011-12-09 18:09:40 +0000870 MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection());
Alexey Samsonov00fd5252012-11-14 09:55:38 +0000871 if (CreateDwarfSectionSymbols) {
Jim Grosbach6f482002015-05-18 18:43:14 +0000872 InfoSectionSymbol = context.createTempSymbol();
Alexey Samsonov00fd5252012-11-14 09:55:38 +0000873 MCOS->EmitLabel(InfoSectionSymbol);
874 }
Kevin Enderbye7739d42011-12-09 18:09:40 +0000875 MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection());
Alexey Samsonov00fd5252012-11-14 09:55:38 +0000876 if (CreateDwarfSectionSymbols) {
Jim Grosbach6f482002015-05-18 18:43:14 +0000877 AbbrevSectionSymbol = context.createTempSymbol();
Rafael Espindolac22c85c2012-02-28 21:13:05 +0000878 MCOS->EmitLabel(AbbrevSectionSymbol);
Rafael Espindolac22c85c2012-02-28 21:13:05 +0000879 }
Oliver Stannard8b273082014-06-19 15:52:37 +0000880 if (UseRangesSection) {
881 MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfRangesSection());
882 if (CreateDwarfSectionSymbols) {
Jim Grosbach6f482002015-05-18 18:43:14 +0000883 RangesSectionSymbol = context.createTempSymbol();
Oliver Stannard8b273082014-06-19 15:52:37 +0000884 MCOS->EmitLabel(RangesSectionSymbol);
885 }
886 }
Kevin Enderbye7739d42011-12-09 18:09:40 +0000887
Oliver Stannard8b273082014-06-19 15:52:37 +0000888 assert((RangesSectionSymbol != NULL) || !UseRangesSection);
889
890 MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection());
Kevin Enderbye7739d42011-12-09 18:09:40 +0000891
892 // Output the data for .debug_aranges section.
Alexey Samsonov00fd5252012-11-14 09:55:38 +0000893 EmitGenDwarfAranges(MCOS, InfoSectionSymbol);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000894
Oliver Stannard8b273082014-06-19 15:52:37 +0000895 if (UseRangesSection)
896 EmitGenDwarfRanges(MCOS);
897
Kevin Enderbye7739d42011-12-09 18:09:40 +0000898 // Output the data for .debug_abbrev section.
899 EmitGenDwarfAbbrev(MCOS);
900
901 // Output the data for .debug_info section.
Oliver Stannard8b273082014-06-19 15:52:37 +0000902 EmitGenDwarfInfo(MCOS, AbbrevSectionSymbol, LineSectionSymbol,
903 RangesSectionSymbol);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000904}
905
906//
907// When generating dwarf for assembly source files this is called when symbol
908// for a label is created. If this symbol is not a temporary and is in the
909// section that dwarf is being generated for, save the needed info to create
Kevin Enderbyf7d77062012-01-10 21:12:34 +0000910// a dwarf label.
Kevin Enderbye7739d42011-12-09 18:09:40 +0000911//
Kevin Enderbyf7d77062012-01-10 21:12:34 +0000912void MCGenDwarfLabelEntry::Make(MCSymbol *Symbol, MCStreamer *MCOS,
Kevin Enderbye7739d42011-12-09 18:09:40 +0000913 SourceMgr &SrcMgr, SMLoc &Loc) {
Oliver Stannard8b273082014-06-19 15:52:37 +0000914 // We won't create dwarf labels for temporary symbols.
Kevin Enderbye7739d42011-12-09 18:09:40 +0000915 if (Symbol->isTemporary())
916 return;
917 MCContext &context = MCOS->getContext();
Oliver Stannard8b273082014-06-19 15:52:37 +0000918 // We won't create dwarf labels for symbols in sections that we are not
919 // generating debug info for.
Eric Christopher445c9522016-10-14 05:47:37 +0000920 if (!context.getGenDwarfSectionSyms().count(MCOS->getCurrentSectionOnly()))
Kevin Enderbye7739d42011-12-09 18:09:40 +0000921 return;
922
Kevin Enderbyf7d77062012-01-10 21:12:34 +0000923 // The dwarf label's name does not have the symbol name's leading
Kevin Enderbye7739d42011-12-09 18:09:40 +0000924 // underbar if any.
925 StringRef Name = Symbol->getName();
926 if (Name.startswith("_"))
927 Name = Name.substr(1, Name.size()-1);
928
Kevin Enderbyf7d77062012-01-10 21:12:34 +0000929 // Get the dwarf file number to be used for the dwarf label.
Kevin Enderbye7739d42011-12-09 18:09:40 +0000930 unsigned FileNumber = context.getGenDwarfFileNumber();
931
932 // Finding the line number is the expensive part which is why we just don't
Kevin Enderbyf7d77062012-01-10 21:12:34 +0000933 // pass it in as for some symbols we won't create a dwarf label.
Alp Tokera55b95b2014-07-06 10:33:31 +0000934 unsigned CurBuffer = SrcMgr.FindBufferContainingLoc(Loc);
Kevin Enderbye7739d42011-12-09 18:09:40 +0000935 unsigned LineNumber = SrcMgr.FindLineNumber(Loc, CurBuffer);
936
937 // We create a temporary symbol for use for the AT_high_pc and AT_low_pc
938 // values so that they don't have things like an ARM thumb bit from the
939 // original symbol. So when used they won't get a low bit set after
940 // relocation.
Jim Grosbach6f482002015-05-18 18:43:14 +0000941 MCSymbol *Label = context.createTempSymbol();
Kevin Enderbye7739d42011-12-09 18:09:40 +0000942 MCOS->EmitLabel(Label);
943
944 // Create and entry for the info and add it to the other entries.
David Blaikie1e0fc8f2014-04-11 00:43:52 +0000945 MCOS->getContext().addMCGenDwarfLabelEntry(
946 MCGenDwarfLabelEntry(Name, FileNumber, LineNumber, Label));
Kevin Enderbye7739d42011-12-09 18:09:40 +0000947}
948
Rafael Espindola0a017a62010-12-10 07:39:47 +0000949static int getDataAlignmentFactor(MCStreamer &streamer) {
950 MCContext &context = streamer.getContext();
Bill Wendlingbc07a892013-06-18 07:20:20 +0000951 const MCAsmInfo *asmInfo = context.getAsmInfo();
952 int size = asmInfo->getCalleeSaveStackSlotSize();
953 if (asmInfo->isStackGrowthDirectionUp())
Rafael Espindola0a017a62010-12-10 07:39:47 +0000954 return size;
Evan Chenga83b37a2011-07-15 02:09:41 +0000955 else
956 return -size;
Rafael Espindola0a017a62010-12-10 07:39:47 +0000957}
958
Rafael Espindola5395f442011-04-22 00:08:43 +0000959static unsigned getSizeForEncoding(MCStreamer &streamer,
960 unsigned symbolEncoding) {
Rafael Espindola1de2dd02010-12-27 15:56:22 +0000961 MCContext &context = streamer.getContext();
Rafael Espindola1de2dd02010-12-27 15:56:22 +0000962 unsigned format = symbolEncoding & 0x0f;
Rafael Espindola1de2dd02010-12-27 15:56:22 +0000963 switch (format) {
Craig Toppera2886c22012-02-07 05:05:23 +0000964 default: llvm_unreachable("Unknown Encoding");
Rafael Espindola1de2dd02010-12-27 15:56:22 +0000965 case dwarf::DW_EH_PE_absptr:
966 case dwarf::DW_EH_PE_signed:
Bill Wendlingbc07a892013-06-18 07:20:20 +0000967 return context.getAsmInfo()->getPointerSize();
Rafael Espindola1de2dd02010-12-27 15:56:22 +0000968 case dwarf::DW_EH_PE_udata2:
969 case dwarf::DW_EH_PE_sdata2:
Rafael Espindola5395f442011-04-22 00:08:43 +0000970 return 2;
Rafael Espindola1de2dd02010-12-27 15:56:22 +0000971 case dwarf::DW_EH_PE_udata4:
972 case dwarf::DW_EH_PE_sdata4:
Rafael Espindola5395f442011-04-22 00:08:43 +0000973 return 4;
Rafael Espindola1de2dd02010-12-27 15:56:22 +0000974 case dwarf::DW_EH_PE_udata8:
975 case dwarf::DW_EH_PE_sdata8:
Rafael Espindola5395f442011-04-22 00:08:43 +0000976 return 8;
Rafael Espindola1de2dd02010-12-27 15:56:22 +0000977 }
Rafael Espindola5395f442011-04-22 00:08:43 +0000978}
979
Rafael Espindolafe963b12014-08-15 03:07:13 +0000980static void emitFDESymbol(MCObjectStreamer &streamer, const MCSymbol &symbol,
981 unsigned symbolEncoding, bool isEH) {
Rafael Espindola6bd6a702011-04-28 21:04:39 +0000982 MCContext &context = streamer.getContext();
Bill Wendlingbc07a892013-06-18 07:20:20 +0000983 const MCAsmInfo *asmInfo = context.getAsmInfo();
984 const MCExpr *v = asmInfo->getExprForFDESymbol(&symbol,
985 symbolEncoding,
986 streamer);
Rafael Espindola5395f442011-04-22 00:08:43 +0000987 unsigned size = getSizeForEncoding(streamer, symbolEncoding);
Iain Sandoe618def62014-01-08 10:22:54 +0000988 if (asmInfo->doDwarfFDESymbolsUseAbsDiff() && isEH)
Rafael Espindolac23174b2014-08-15 15:12:13 +0000989 emitAbsValue(streamer, v, size);
Iain Sandoe618def62014-01-08 10:22:54 +0000990 else
991 streamer.EmitValue(v, size);
Rafael Espindola1de2dd02010-12-27 15:56:22 +0000992}
993
Rafael Espindolac5dac4d2011-04-28 16:09:09 +0000994static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol,
995 unsigned symbolEncoding) {
996 MCContext &context = streamer.getContext();
Bill Wendlingbc07a892013-06-18 07:20:20 +0000997 const MCAsmInfo *asmInfo = context.getAsmInfo();
998 const MCExpr *v = asmInfo->getExprForPersonalitySymbol(&symbol,
999 symbolEncoding,
1000 streamer);
Rafael Espindolac5dac4d2011-04-28 16:09:09 +00001001 unsigned size = getSizeForEncoding(streamer, symbolEncoding);
Rafael Espindolafd057852011-05-01 03:50:49 +00001002 streamer.EmitValue(v, size);
Rafael Espindolac5dac4d2011-04-28 16:09:09 +00001003}
1004
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001005namespace {
Rafael Espindola68c21652015-11-05 23:54:18 +00001006class FrameEmitterImpl {
Rafael Espindolaa1d960e2015-11-05 23:55:51 +00001007 int CFAOffset = 0;
1008 int InitialCFAOffset = 0;
Rafael Espindola68c21652015-11-05 23:54:18 +00001009 bool IsEH;
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001010 MCObjectStreamer &Streamer;
Bill Wendling4d9aa512011-07-22 21:18:59 +00001011
Rafael Espindola68c21652015-11-05 23:54:18 +00001012public:
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001013 FrameEmitterImpl(bool IsEH, MCObjectStreamer &Streamer)
1014 : IsEH(IsEH), Streamer(Streamer) {}
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001015
Rafael Espindola68c21652015-11-05 23:54:18 +00001016 /// Emit the unwind information in a compact way.
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001017 void EmitCompactUnwind(const MCDwarfFrameInfo &frame);
Rafael Espindola68c21652015-11-05 23:54:18 +00001018
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001019 const MCSymbol &EmitCIE(const MCSymbol *personality,
Rafael Espindola68c21652015-11-05 23:54:18 +00001020 unsigned personalityEncoding, const MCSymbol *lsda,
1021 bool IsSignalFrame, unsigned lsdaEncoding,
1022 bool IsSimple);
Rafael Espindola46be4352015-11-06 03:02:51 +00001023 void EmitFDE(const MCSymbol &cieStart, const MCDwarfFrameInfo &frame,
Rafael Espindola97588e12015-11-06 13:14:59 +00001024 bool LastInSection, const MCSymbol &SectionStart);
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001025 void EmitCFIInstructions(ArrayRef<MCCFIInstruction> Instrs,
Rafael Espindola68c21652015-11-05 23:54:18 +00001026 MCSymbol *BaseLabel);
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001027 void EmitCFIInstruction(const MCCFIInstruction &Instr);
Rafael Espindola68c21652015-11-05 23:54:18 +00001028};
Bill Wendling567a1ae2011-06-30 21:25:51 +00001029
1030} // end anonymous namespace
1031
Rafael Espindolafe963b12014-08-15 03:07:13 +00001032static void emitEncodingByte(MCObjectStreamer &Streamer, unsigned Encoding) {
Bill Wendling567a1ae2011-06-30 21:25:51 +00001033 Streamer.EmitIntValue(Encoding, 1);
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001034}
1035
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001036void FrameEmitterImpl::EmitCFIInstruction(const MCCFIInstruction &Instr) {
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001037 int dataAlignmentFactor = getDataAlignmentFactor(Streamer);
Frederic Rissadbb3f22015-02-26 19:48:07 +00001038 auto *MRI = Streamer.getContext().getRegisterInfo();
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001039
1040 switch (Instr.getOperation()) {
Rafael Espindolacdb9a532012-11-25 15:14:49 +00001041 case MCCFIInstruction::OpRegister: {
1042 unsigned Reg1 = Instr.getRegister();
1043 unsigned Reg2 = Instr.getRegister2();
Frederic Rissadbb3f22015-02-26 19:48:07 +00001044 if (!IsEH) {
1045 Reg1 = MRI->getDwarfRegNum(MRI->getLLVMRegNum(Reg1, true), false);
1046 Reg2 = MRI->getDwarfRegNum(MRI->getLLVMRegNum(Reg2, true), false);
1047 }
Rafael Espindolacdb9a532012-11-25 15:14:49 +00001048 Streamer.EmitIntValue(dwarf::DW_CFA_register, 1);
1049 Streamer.EmitULEB128IntValue(Reg1);
1050 Streamer.EmitULEB128IntValue(Reg2);
1051 return;
1052 }
Venkatraman Govindaraju3816d432013-09-26 14:49:40 +00001053 case MCCFIInstruction::OpWindowSave: {
1054 Streamer.EmitIntValue(dwarf::DW_CFA_GNU_window_save, 1);
1055 return;
1056 }
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001057 case MCCFIInstruction::OpUndefined: {
Rafael Espindolacc0c74a2012-11-24 04:33:48 +00001058 unsigned Reg = Instr.getRegister();
Rafael Espindola9bb24782012-11-23 16:59:41 +00001059 Streamer.EmitIntValue(dwarf::DW_CFA_undefined, 1);
1060 Streamer.EmitULEB128IntValue(Reg);
1061 return;
1062 }
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001063 case MCCFIInstruction::OpAdjustCfaOffset:
1064 case MCCFIInstruction::OpDefCfaOffset: {
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001065 const bool IsRelative =
1066 Instr.getOperation() == MCCFIInstruction::OpAdjustCfaOffset;
1067
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001068 Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_offset, 1);
1069
1070 if (IsRelative)
Rafael Espindolacc0c74a2012-11-24 04:33:48 +00001071 CFAOffset += Instr.getOffset();
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001072 else
Rafael Espindolacc0c74a2012-11-24 04:33:48 +00001073 CFAOffset = -Instr.getOffset();
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001074
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001075 Streamer.EmitULEB128IntValue(CFAOffset);
1076
1077 return;
1078 }
1079 case MCCFIInstruction::OpDefCfa: {
Frederic Rissadbb3f22015-02-26 19:48:07 +00001080 unsigned Reg = Instr.getRegister();
1081 if (!IsEH)
1082 Reg = MRI->getDwarfRegNum(MRI->getLLVMRegNum(Reg, true), false);
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001083 Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa, 1);
Frederic Rissadbb3f22015-02-26 19:48:07 +00001084 Streamer.EmitULEB128IntValue(Reg);
Rafael Espindolacc0c74a2012-11-24 04:33:48 +00001085 CFAOffset = -Instr.getOffset();
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001086 Streamer.EmitULEB128IntValue(CFAOffset);
1087
1088 return;
1089 }
1090
1091 case MCCFIInstruction::OpDefCfaRegister: {
Frederic Rissadbb3f22015-02-26 19:48:07 +00001092 unsigned Reg = Instr.getRegister();
1093 if (!IsEH)
1094 Reg = MRI->getDwarfRegNum(MRI->getLLVMRegNum(Reg, true), false);
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001095 Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_register, 1);
Frederic Rissadbb3f22015-02-26 19:48:07 +00001096 Streamer.EmitULEB128IntValue(Reg);
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001097
1098 return;
1099 }
1100
1101 case MCCFIInstruction::OpOffset:
1102 case MCCFIInstruction::OpRelOffset: {
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001103 const bool IsRelative =
1104 Instr.getOperation() == MCCFIInstruction::OpRelOffset;
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001105
Rafael Espindolacc0c74a2012-11-24 04:33:48 +00001106 unsigned Reg = Instr.getRegister();
Frederic Rissadbb3f22015-02-26 19:48:07 +00001107 if (!IsEH)
1108 Reg = MRI->getDwarfRegNum(MRI->getLLVMRegNum(Reg, true), false);
1109
Rafael Espindolacc0c74a2012-11-24 04:33:48 +00001110 int Offset = Instr.getOffset();
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001111 if (IsRelative)
1112 Offset -= CFAOffset;
1113 Offset = Offset / dataAlignmentFactor;
1114
1115 if (Offset < 0) {
1116 Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended_sf, 1);
1117 Streamer.EmitULEB128IntValue(Reg);
1118 Streamer.EmitSLEB128IntValue(Offset);
1119 } else if (Reg < 64) {
1120 Streamer.EmitIntValue(dwarf::DW_CFA_offset + Reg, 1);
Rafael Espindolaea61f222011-04-21 23:26:40 +00001121 Streamer.EmitULEB128IntValue(Offset);
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001122 } else {
1123 Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended, 1);
Rafael Espindolaea61f222011-04-21 23:26:40 +00001124 Streamer.EmitULEB128IntValue(Reg);
1125 Streamer.EmitULEB128IntValue(Offset);
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001126 }
1127 return;
1128 }
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001129 case MCCFIInstruction::OpRememberState:
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001130 Streamer.EmitIntValue(dwarf::DW_CFA_remember_state, 1);
1131 return;
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001132 case MCCFIInstruction::OpRestoreState:
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001133 Streamer.EmitIntValue(dwarf::DW_CFA_restore_state, 1);
1134 return;
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001135 case MCCFIInstruction::OpSameValue: {
Rafael Espindolacc0c74a2012-11-24 04:33:48 +00001136 unsigned Reg = Instr.getRegister();
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001137 Streamer.EmitIntValue(dwarf::DW_CFA_same_value, 1);
Rafael Espindola6aea5922011-04-21 23:39:26 +00001138 Streamer.EmitULEB128IntValue(Reg);
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001139 return;
1140 }
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001141 case MCCFIInstruction::OpRestore: {
Rafael Espindolacc0c74a2012-11-24 04:33:48 +00001142 unsigned Reg = Instr.getRegister();
Frederic Rissadbb3f22015-02-26 19:48:07 +00001143 if (!IsEH)
1144 Reg = MRI->getDwarfRegNum(MRI->getLLVMRegNum(Reg, true), false);
Rafael Espindola4ea99812011-12-29 21:43:03 +00001145 Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1);
1146 return;
1147 }
Michael Kuperstein259f1502015-10-07 07:01:31 +00001148 case MCCFIInstruction::OpGnuArgsSize: {
1149 Streamer.EmitIntValue(dwarf::DW_CFA_GNU_args_size, 1);
1150 Streamer.EmitULEB128IntValue(Instr.getOffset());
1151 return;
1152 }
Rafael Espindola5dce65b2012-11-24 03:10:54 +00001153 case MCCFIInstruction::OpEscape:
Eric Christophere3ab3d02013-01-09 01:57:54 +00001154 Streamer.EmitBytes(Instr.getValues());
Rafael Espindolaef4aa352011-12-29 20:24:47 +00001155 return;
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001156 }
1157 llvm_unreachable("Unhandled case in switch");
1158}
1159
Rafael Espindolafe963b12014-08-15 03:07:13 +00001160/// Emit frame instructions to describe the layout of the frame.
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001161void FrameEmitterImpl::EmitCFIInstructions(ArrayRef<MCCFIInstruction> Instrs,
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001162 MCSymbol *BaseLabel) {
Benjamin Kramer7b4658f2016-06-26 14:49:00 +00001163 for (const MCCFIInstruction &Instr : Instrs) {
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001164 MCSymbol *Label = Instr.getLabel();
1165 // Throw out move if the label is invalid.
1166 if (Label && !Label->isDefined()) continue; // Not emitted, in dead code.
1167
1168 // Advance row if new location.
1169 if (BaseLabel && Label) {
1170 MCSymbol *ThisSym = Label;
1171 if (ThisSym != BaseLabel) {
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001172 Streamer.EmitDwarfAdvanceFrameAddr(BaseLabel, ThisSym);
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001173 BaseLabel = ThisSym;
1174 }
1175 }
1176
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001177 EmitCFIInstruction(Instr);
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001178 }
1179}
1180
Rafael Espindolafe963b12014-08-15 03:07:13 +00001181/// Emit the unwind information in a compact way.
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001182void FrameEmitterImpl::EmitCompactUnwind(const MCDwarfFrameInfo &Frame) {
Bill Wendlinge8fc92a2011-06-23 01:06:23 +00001183 MCContext &Context = Streamer.getContext();
Evan Cheng76792992011-07-20 05:58:47 +00001184 const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
Bill Wendlinge8fc92a2011-06-23 01:06:23 +00001185
Bill Wendlinge8fc92a2011-06-23 01:06:23 +00001186 // range-start range-length compact-unwind-enc personality-func lsda
1187 // _foo LfooEnd-_foo 0x00000023 0 0
1188 // _bar LbarEnd-_bar 0x00000025 __gxx_personality except_tab1
1189 //
1190 // .section __LD,__compact_unwind,regular,debug
1191 //
1192 // # compact unwind for _foo
1193 // .quad _foo
1194 // .set L1,LfooEnd-_foo
1195 // .long L1
1196 // .long 0x01010001
1197 // .quad 0
1198 // .quad 0
1199 //
1200 // # compact unwind for _bar
1201 // .quad _bar
1202 // .set L2,LbarEnd-_bar
1203 // .long L2
1204 // .long 0x01020011
1205 // .quad __gxx_personality
1206 // .quad except_tab1
1207
Bill Wendling49bc6802011-07-19 00:06:12 +00001208 uint32_t Encoding = Frame.CompactUnwindEncoding;
Bill Wendling99bce5f2013-04-18 23:16:46 +00001209 if (!Encoding) return;
Bill Wendling2d1df6b2013-04-10 21:42:06 +00001210 bool DwarfEHFrameOnly = (Encoding == MOFI->getCompactUnwindDwarfEHFrameOnly());
Bill Wendlingb6adf462011-07-07 00:54:13 +00001211
Bill Wendlingdafd5982011-07-14 23:34:45 +00001212 // The encoding needs to know we have an LSDA.
Bill Wendling2d1df6b2013-04-10 21:42:06 +00001213 if (!DwarfEHFrameOnly && Frame.Lsda)
Bill Wendlingdafd5982011-07-14 23:34:45 +00001214 Encoding |= 0x40000000;
1215
Bill Wendlinge8fc92a2011-06-23 01:06:23 +00001216 // Range Start
Rafael Espindolaaa7851d2014-05-12 13:47:05 +00001217 unsigned FDEEncoding = MOFI->getFDEEncoding();
Bill Wendling8fa4ada2011-06-29 23:49:12 +00001218 unsigned Size = getSizeForEncoding(Streamer, FDEEncoding);
Rafael Espindola88604822014-06-23 15:34:32 +00001219 Streamer.EmitSymbolValue(Frame.Begin, Size);
Bill Wendlinge8fc92a2011-06-23 01:06:23 +00001220
1221 // Range Length
1222 const MCExpr *Range = MakeStartMinusEndExpr(Streamer, *Frame.Begin,
1223 *Frame.End, 0);
Rafael Espindolac23174b2014-08-15 15:12:13 +00001224 emitAbsValue(Streamer, Range, 4);
Bill Wendling75174662011-06-30 00:30:52 +00001225
Bill Wendling75174662011-06-30 00:30:52 +00001226 // Compact Encoding
Bill Wendling75174662011-06-30 00:30:52 +00001227 Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_udata4);
1228 Streamer.EmitIntValue(Encoding, Size);
1229
Bill Wendling8fa4ada2011-06-29 23:49:12 +00001230 // Personality Function
Bill Wendlingdafd5982011-07-14 23:34:45 +00001231 Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_absptr);
Bill Wendling2d1df6b2013-04-10 21:42:06 +00001232 if (!DwarfEHFrameOnly && Frame.Personality)
Bill Wendling8fa4ada2011-06-29 23:49:12 +00001233 Streamer.EmitSymbolValue(Frame.Personality, Size);
Bill Wendling4cdb2062011-06-29 23:53:16 +00001234 else
1235 Streamer.EmitIntValue(0, Size); // No personality fn
Bill Wendling8fa4ada2011-06-29 23:49:12 +00001236
1237 // LSDA
Bill Wendling4cdb2062011-06-29 23:53:16 +00001238 Size = getSizeForEncoding(Streamer, Frame.LsdaEncoding);
Bill Wendling2d1df6b2013-04-10 21:42:06 +00001239 if (!DwarfEHFrameOnly && Frame.Lsda)
Bill Wendling8fa4ada2011-06-29 23:49:12 +00001240 Streamer.EmitSymbolValue(Frame.Lsda, Size);
Bill Wendling4cdb2062011-06-29 23:53:16 +00001241 else
1242 Streamer.EmitIntValue(0, Size); // No LSDA
Bill Wendlinge8fc92a2011-06-23 01:06:23 +00001243}
1244
Rafael Espindolaeffdc7e2015-04-28 13:55:31 +00001245static unsigned getCIEVersion(bool IsEH, unsigned DwarfVersion) {
1246 if (IsEH)
1247 return 1;
1248 switch (DwarfVersion) {
1249 case 2:
1250 return 1;
1251 case 3:
1252 return 3;
1253 case 4:
Eric Christopher2ae71802015-12-28 23:02:42 +00001254 case 5:
Rafael Espindolaeffdc7e2015-04-28 13:55:31 +00001255 return 4;
1256 }
1257 llvm_unreachable("Unknown version");
1258}
1259
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001260const MCSymbol &FrameEmitterImpl::EmitCIE(const MCSymbol *personality,
Rafael Espindola1ec0f462011-04-12 16:12:03 +00001261 unsigned personalityEncoding,
1262 const MCSymbol *lsda,
Rafael Espindola3c47e372012-01-23 21:51:52 +00001263 bool IsSignalFrame,
David Majnemere035cf92014-01-27 17:20:25 +00001264 unsigned lsdaEncoding,
1265 bool IsSimple) {
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001266 MCContext &context = Streamer.getContext();
Bill Wendlingbc07a892013-06-18 07:20:20 +00001267 const MCRegisterInfo *MRI = context.getRegisterInfo();
Evan Cheng76792992011-07-20 05:58:47 +00001268 const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
Rafael Espindolabf60fb02011-04-28 03:26:11 +00001269
Jim Grosbach6f482002015-05-18 18:43:14 +00001270 MCSymbol *sectionStart = context.createTempSymbol();
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001271 Streamer.EmitLabel(sectionStart);
Rafael Espindolabf60fb02011-04-28 03:26:11 +00001272
Jim Grosbach6f482002015-05-18 18:43:14 +00001273 MCSymbol *sectionEnd = context.createTempSymbol();
Rafael Espindola0a017a62010-12-10 07:39:47 +00001274
1275 // Length
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001276 const MCExpr *Length =
1277 MakeStartMinusEndExpr(Streamer, *sectionStart, *sectionEnd, 4);
1278 emitAbsValue(Streamer, Length, 4);
Rafael Espindola0a017a62010-12-10 07:39:47 +00001279
1280 // CIE ID
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001281 unsigned CIE_ID = IsEH ? 0 : -1;
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001282 Streamer.EmitIntValue(CIE_ID, 4);
Rafael Espindola0a017a62010-12-10 07:39:47 +00001283
1284 // Version
Rafael Espindolaeffdc7e2015-04-28 13:55:31 +00001285 uint8_t CIEVersion = getCIEVersion(IsEH, context.getDwarfVersion());
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001286 Streamer.EmitIntValue(CIEVersion, 1);
Rafael Espindola0a017a62010-12-10 07:39:47 +00001287
1288 // Augmentation String
1289 SmallString<8> Augmentation;
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001290 if (IsEH) {
1291 Augmentation += "z";
1292 if (personality)
1293 Augmentation += "P";
1294 if (lsda)
1295 Augmentation += "L";
1296 Augmentation += "R";
Rafael Espindola3c47e372012-01-23 21:51:52 +00001297 if (IsSignalFrame)
1298 Augmentation += "S";
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001299 Streamer.EmitBytes(Augmentation);
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001300 }
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001301 Streamer.EmitIntValue(0, 1);
Rafael Espindola0a017a62010-12-10 07:39:47 +00001302
Keith Walkerea9483f2015-05-12 15:25:08 +00001303 if (CIEVersion >= 4) {
1304 // Address Size
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001305 Streamer.EmitIntValue(context.getAsmInfo()->getPointerSize(), 1);
Keith Walkerea9483f2015-05-12 15:25:08 +00001306
1307 // Segment Descriptor Size
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001308 Streamer.EmitIntValue(0, 1);
Keith Walkerea9483f2015-05-12 15:25:08 +00001309 }
1310
Rafael Espindola0a017a62010-12-10 07:39:47 +00001311 // Code Alignment Factor
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001312 Streamer.EmitULEB128IntValue(context.getAsmInfo()->getMinInstAlignment());
Rafael Espindola0a017a62010-12-10 07:39:47 +00001313
1314 // Data Alignment Factor
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001315 Streamer.EmitSLEB128IntValue(getDataAlignmentFactor(Streamer));
Rafael Espindola0a017a62010-12-10 07:39:47 +00001316
1317 // Return Address Register
Oliver Stannardf7693f42014-06-19 15:39:33 +00001318 if (CIEVersion == 1) {
1319 assert(MRI->getRARegister() <= 255 &&
1320 "DWARF 2 encodes return_address_register in one byte");
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001321 Streamer.EmitIntValue(MRI->getDwarfRegNum(MRI->getRARegister(), IsEH), 1);
Oliver Stannardf7693f42014-06-19 15:39:33 +00001322 } else {
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001323 Streamer.EmitULEB128IntValue(
Frederic Rissadbb3f22015-02-26 19:48:07 +00001324 MRI->getDwarfRegNum(MRI->getRARegister(), IsEH));
Oliver Stannardf7693f42014-06-19 15:39:33 +00001325 }
Rafael Espindola0a017a62010-12-10 07:39:47 +00001326
1327 // Augmentation Data Length (optional)
Rafael Espindola6a85f9b2011-04-29 21:50:57 +00001328
1329 unsigned augmentationLength = 0;
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001330 if (IsEH) {
1331 if (personality) {
1332 // Personality Encoding
1333 augmentationLength += 1;
1334 // Personality
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001335 augmentationLength += getSizeForEncoding(Streamer, personalityEncoding);
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001336 }
1337 if (lsda)
1338 augmentationLength += 1;
1339 // Encoding of the FDE pointers
Rafael Espindola6a85f9b2011-04-29 21:50:57 +00001340 augmentationLength += 1;
Rafael Espindola6a85f9b2011-04-29 21:50:57 +00001341
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001342 Streamer.EmitULEB128IntValue(augmentationLength);
Rafael Espindola0a017a62010-12-10 07:39:47 +00001343
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001344 // Augmentation Data (optional)
1345 if (personality) {
1346 // Personality Encoding
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001347 emitEncodingByte(Streamer, personalityEncoding);
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001348 // Personality
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001349 EmitPersonality(Streamer, *personality, personalityEncoding);
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001350 }
Bill Wendling567a1ae2011-06-30 21:25:51 +00001351
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001352 if (lsda)
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001353 emitEncodingByte(Streamer, lsdaEncoding);
Bill Wendling567a1ae2011-06-30 21:25:51 +00001354
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001355 // Encoding of the FDE pointers
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001356 emitEncodingByte(Streamer, MOFI->getFDEEncoding());
Rafael Espindola1de2dd02010-12-27 15:56:22 +00001357 }
Rafael Espindola0a017a62010-12-10 07:39:47 +00001358
1359 // Initial Instructions
1360
Bill Wendlingbc07a892013-06-18 07:20:20 +00001361 const MCAsmInfo *MAI = context.getAsmInfo();
David Majnemere035cf92014-01-27 17:20:25 +00001362 if (!IsSimple) {
1363 const std::vector<MCCFIInstruction> &Instructions =
1364 MAI->getInitialFrameState();
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001365 EmitCFIInstructions(Instructions, nullptr);
David Majnemere035cf92014-01-27 17:20:25 +00001366 }
Rafael Espindola0a017a62010-12-10 07:39:47 +00001367
Rafael Espindola8b4817b2015-03-24 21:47:31 +00001368 InitialCFAOffset = CFAOffset;
1369
Rafael Espindola0a017a62010-12-10 07:39:47 +00001370 // Padding
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001371 Streamer.EmitValueToAlignment(IsEH ? 4 : MAI->getPointerSize());
Rafael Espindola0a017a62010-12-10 07:39:47 +00001372
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001373 Streamer.EmitLabel(sectionEnd);
Rafael Espindola0a017a62010-12-10 07:39:47 +00001374 return *sectionStart;
1375}
1376
Rafael Espindola46be4352015-11-06 03:02:51 +00001377void FrameEmitterImpl::EmitFDE(const MCSymbol &cieStart,
1378 const MCDwarfFrameInfo &frame,
Rafael Espindola97588e12015-11-06 13:14:59 +00001379 bool LastInSection,
1380 const MCSymbol &SectionStart) {
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001381 MCContext &context = Streamer.getContext();
Jim Grosbach6f482002015-05-18 18:43:14 +00001382 MCSymbol *fdeStart = context.createTempSymbol();
1383 MCSymbol *fdeEnd = context.createTempSymbol();
Evan Cheng76792992011-07-20 05:58:47 +00001384 const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
Rafael Espindola0a017a62010-12-10 07:39:47 +00001385
Rafael Espindola8b4817b2015-03-24 21:47:31 +00001386 CFAOffset = InitialCFAOffset;
1387
Rafael Espindola0a017a62010-12-10 07:39:47 +00001388 // Length
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001389 const MCExpr *Length = MakeStartMinusEndExpr(Streamer, *fdeStart, *fdeEnd, 0);
1390 emitAbsValue(Streamer, Length, 4);
Rafael Espindola0a017a62010-12-10 07:39:47 +00001391
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001392 Streamer.EmitLabel(fdeStart);
Rafael Espindola99f67352011-05-10 20:59:42 +00001393
Rafael Espindola0a017a62010-12-10 07:39:47 +00001394 // CIE Pointer
Bill Wendlingbc07a892013-06-18 07:20:20 +00001395 const MCAsmInfo *asmInfo = context.getAsmInfo();
Rafael Espindola27390b42011-05-10 15:20:23 +00001396 if (IsEH) {
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001397 const MCExpr *offset =
1398 MakeStartMinusEndExpr(Streamer, cieStart, *fdeStart, 0);
1399 emitAbsValue(Streamer, offset, 4);
Bill Wendlingbc07a892013-06-18 07:20:20 +00001400 } else if (!asmInfo->doesDwarfUseRelocationsAcrossSections()) {
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001401 const MCExpr *offset =
Rafael Espindola97588e12015-11-06 13:14:59 +00001402 MakeStartMinusEndExpr(Streamer, SectionStart, cieStart, 0);
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001403 emitAbsValue(Streamer, offset, 4);
Rafael Espindola27390b42011-05-10 15:20:23 +00001404 } else {
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001405 Streamer.EmitSymbolValue(&cieStart, 4);
Rafael Espindola27390b42011-05-10 15:20:23 +00001406 }
Bill Wendlingf166ab42011-06-30 22:02:20 +00001407
Rafael Espindola0a017a62010-12-10 07:39:47 +00001408 // PC Begin
Rafael Espindola01ee31b2014-05-12 13:40:49 +00001409 unsigned PCEncoding =
Rafael Espindolaaa7851d2014-05-12 13:47:05 +00001410 IsEH ? MOFI->getFDEEncoding() : (unsigned)dwarf::DW_EH_PE_absptr;
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001411 unsigned PCSize = getSizeForEncoding(Streamer, PCEncoding);
1412 emitFDESymbol(Streamer, *frame.Begin, PCEncoding, IsEH);
Rafael Espindola0a017a62010-12-10 07:39:47 +00001413
1414 // PC Range
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001415 const MCExpr *Range =
1416 MakeStartMinusEndExpr(Streamer, *frame.Begin, *frame.End, 0);
1417 emitAbsValue(Streamer, Range, PCSize);
Rafael Espindola0a017a62010-12-10 07:39:47 +00001418
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001419 if (IsEH) {
1420 // Augmentation Data Length
1421 unsigned augmentationLength = 0;
Rafael Espindola6a85f9b2011-04-29 21:50:57 +00001422
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001423 if (frame.Lsda)
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001424 augmentationLength += getSizeForEncoding(Streamer, frame.LsdaEncoding);
Rafael Espindola6a85f9b2011-04-29 21:50:57 +00001425
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001426 Streamer.EmitULEB128IntValue(augmentationLength);
Rafael Espindola0a017a62010-12-10 07:39:47 +00001427
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001428 // Augmentation Data
1429 if (frame.Lsda)
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001430 emitFDESymbol(Streamer, *frame.Lsda, frame.LsdaEncoding, true);
Rafael Espindola1ecb12f2011-05-10 03:54:12 +00001431 }
Rafael Espindola68067662011-04-29 03:06:29 +00001432
Rafael Espindola0a017a62010-12-10 07:39:47 +00001433 // Call Frame Instructions
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001434 EmitCFIInstructions(frame.Instructions, frame.Begin);
Rafael Espindolaa75b87b2010-12-28 04:15:37 +00001435
Rafael Espindola0a017a62010-12-10 07:39:47 +00001436 // Padding
Rafael Espindola46be4352015-11-06 03:02:51 +00001437 // The size of a .eh_frame section has to be a multiple of the alignment
1438 // since a null CIE is interpreted as the end. Old systems overaligned
1439 // .eh_frame, so we do too and account for it in the last FDE.
1440 unsigned Align = LastInSection ? asmInfo->getPointerSize() : PCSize;
1441 Streamer.EmitValueToAlignment(Align);
Rafael Espindola32c74ea2010-12-17 00:28:02 +00001442
Rafael Espindola46be4352015-11-06 03:02:51 +00001443 Streamer.EmitLabel(fdeEnd);
Rafael Espindola0a017a62010-12-10 07:39:47 +00001444}
1445
Benjamin Kramer570dd782010-12-30 22:34:44 +00001446namespace {
Rafael Espindola5b2131c2015-11-06 14:12:17 +00001447struct CIEKey {
1448 static const CIEKey getEmptyKey() {
1449 return CIEKey(nullptr, 0, -1, false, false);
1450 }
1451 static const CIEKey getTombstoneKey() {
1452 return CIEKey(nullptr, -1, 0, false, false);
1453 }
Rafael Espindola1de2dd02010-12-27 15:56:22 +00001454
Rafael Espindola5b2131c2015-11-06 14:12:17 +00001455 CIEKey(const MCSymbol *Personality, unsigned PersonalityEncoding,
1456 unsigned LsdaEncoding, bool IsSignalFrame, bool IsSimple)
1457 : Personality(Personality), PersonalityEncoding(PersonalityEncoding),
1458 LsdaEncoding(LsdaEncoding), IsSignalFrame(IsSignalFrame),
1459 IsSimple(IsSimple) {}
1460 const MCSymbol *Personality;
1461 unsigned PersonalityEncoding;
1462 unsigned LsdaEncoding;
1463 bool IsSignalFrame;
1464 bool IsSimple;
1465};
Hans Wennborg083ca9b2015-10-06 23:24:35 +00001466} // anonymous namespace
Rafael Espindola1de2dd02010-12-27 15:56:22 +00001467
1468namespace llvm {
Rafael Espindola5b2131c2015-11-06 14:12:17 +00001469template <> struct DenseMapInfo<CIEKey> {
1470 static CIEKey getEmptyKey() { return CIEKey::getEmptyKey(); }
1471 static CIEKey getTombstoneKey() { return CIEKey::getTombstoneKey(); }
1472 static unsigned getHashValue(const CIEKey &Key) {
1473 return static_cast<unsigned>(
1474 hash_combine(Key.Personality, Key.PersonalityEncoding, Key.LsdaEncoding,
1475 Key.IsSignalFrame, Key.IsSimple));
1476 }
1477 static bool isEqual(const CIEKey &LHS, const CIEKey &RHS) {
1478 return LHS.Personality == RHS.Personality &&
1479 LHS.PersonalityEncoding == RHS.PersonalityEncoding &&
1480 LHS.LsdaEncoding == RHS.LsdaEncoding &&
1481 LHS.IsSignalFrame == RHS.IsSignalFrame &&
1482 LHS.IsSimple == RHS.IsSimple;
1483 }
1484};
Hans Wennborg083ca9b2015-10-06 23:24:35 +00001485} // namespace llvm
Rafael Espindola1de2dd02010-12-27 15:56:22 +00001486
Rafael Espindola4066e8d2014-05-12 14:28:48 +00001487void MCDwarfFrameEmitter::Emit(MCObjectStreamer &Streamer, MCAsmBackend *MAB,
Rafael Espindola8285b772014-05-12 13:34:25 +00001488 bool IsEH) {
Bill Wendling550c76d2013-09-09 19:48:37 +00001489 Streamer.generateCompactUnwindEncodings(MAB);
1490
Bill Wendlinga4b9d1f2011-06-23 07:44:54 +00001491 MCContext &Context = Streamer.getContext();
Bill Wendlinga800f952013-05-30 18:52:57 +00001492 const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001493 FrameEmitterImpl Emitter(IsEH, Streamer);
Saleem Abdulrasool3f3cefd2014-07-13 19:03:36 +00001494 ArrayRef<MCDwarfFrameInfo> FrameArray = Streamer.getDwarfFrameInfos();
Bill Wendling4d9aa512011-07-22 21:18:59 +00001495
Bill Wendling9803abb2011-09-06 18:37:11 +00001496 // Emit the compact unwind info if available.
Tim Northoverd1c6f512014-03-29 09:03:13 +00001497 bool NeedsEHFrameSection = !MOFI->getSupportsCompactUnwindWithoutEHFrame();
Bill Wendling4e9fc022013-04-24 03:11:14 +00001498 if (IsEH && MOFI->getCompactUnwindSection()) {
Bill Wendling4e9fc022013-04-24 03:11:14 +00001499 bool SectionEmitted = false;
Benjamin Kramer7b4658f2016-06-26 14:49:00 +00001500 for (const MCDwarfFrameInfo &Frame : FrameArray) {
Bob Wilson0e180f22013-05-07 20:56:33 +00001501 if (Frame.CompactUnwindEncoding == 0) continue;
1502 if (!SectionEmitted) {
1503 Streamer.SwitchSection(MOFI->getCompactUnwindSection());
Bill Wendlingbc07a892013-06-18 07:20:20 +00001504 Streamer.EmitValueToAlignment(Context.getAsmInfo()->getPointerSize());
Bob Wilson0e180f22013-05-07 20:56:33 +00001505 SectionEmitted = true;
Bill Wendling4e9fc022013-04-24 03:11:14 +00001506 }
Tim Northoverd1c6f512014-03-29 09:03:13 +00001507 NeedsEHFrameSection |=
1508 Frame.CompactUnwindEncoding ==
1509 MOFI->getCompactUnwindDwarfEHFrameOnly();
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001510 Emitter.EmitCompactUnwind(Frame);
Bill Wendling4d9aa512011-07-22 21:18:59 +00001511 }
Bill Wendling4e9fc022013-04-24 03:11:14 +00001512 }
Bill Wendling4d9aa512011-07-22 21:18:59 +00001513
Tim Northoverd1c6f512014-03-29 09:03:13 +00001514 if (!NeedsEHFrameSection) return;
1515
Rafael Espindola0709a7b2015-05-21 19:20:38 +00001516 MCSection &Section =
1517 IsEH ? *const_cast<MCObjectFileInfo *>(MOFI)->getEHFrameSection()
1518 : *MOFI->getDwarfFrameSection();
Tim Northoverd1c6f512014-03-29 09:03:13 +00001519
Bill Wendlinga4b9d1f2011-06-23 07:44:54 +00001520 Streamer.SwitchSection(&Section);
Jim Grosbach6f482002015-05-18 18:43:14 +00001521 MCSymbol *SectionStart = Context.createTempSymbol();
Bill Wendlinga4b9d1f2011-06-23 07:44:54 +00001522 Streamer.EmitLabel(SectionStart);
Rafael Espindola7c715152011-04-29 02:42:28 +00001523
Eric Christopherd29430d2014-06-19 20:00:09 +00001524 DenseMap<CIEKey, const MCSymbol *> CIEStarts;
Rafael Espindola9141b612010-12-26 20:20:31 +00001525
Craig Topperbb694de2014-04-13 04:57:38 +00001526 const MCSymbol *DummyDebugKey = nullptr;
Tim Northoverf8e47e42015-10-28 22:56:36 +00001527 bool CanOmitDwarf = MOFI->getOmitDwarfIfHaveCompactUnwind();
Rafael Espindola46be4352015-11-06 03:02:51 +00001528 for (auto I = FrameArray.begin(), E = FrameArray.end(); I != E;) {
1529 const MCDwarfFrameInfo &Frame = *I;
1530 ++I;
Tim Northoverf8e47e42015-10-28 22:56:36 +00001531 if (CanOmitDwarf && Frame.CompactUnwindEncoding !=
Tim Northoverd1c6f512014-03-29 09:03:13 +00001532 MOFI->getCompactUnwindDwarfEHFrameOnly())
1533 // Don't generate an EH frame if we don't need one. I.e., it's taken care
1534 // of by the compact unwind encoding.
1535 continue;
1536
Bill Wendlinga4b9d1f2011-06-23 07:44:54 +00001537 CIEKey Key(Frame.Personality, Frame.PersonalityEncoding,
David Majnemere035cf92014-01-27 17:20:25 +00001538 Frame.LsdaEncoding, Frame.IsSignalFrame, Frame.IsSimple);
Bill Wendlinga4b9d1f2011-06-23 07:44:54 +00001539 const MCSymbol *&CIEStart = IsEH ? CIEStarts[Key] : DummyDebugKey;
1540 if (!CIEStart)
Rafael Espindola6efa6fb2015-11-06 00:05:57 +00001541 CIEStart = &Emitter.EmitCIE(Frame.Personality, Frame.PersonalityEncoding,
1542 Frame.Lsda, Frame.IsSignalFrame,
1543 Frame.LsdaEncoding, Frame.IsSimple);
Bill Wendlinge8fc92a2011-06-23 01:06:23 +00001544
Rafael Espindola97588e12015-11-06 13:14:59 +00001545 Emitter.EmitFDE(*CIEStart, Frame, I == E, *SectionStart);
Rafael Espindola32c74ea2010-12-17 00:28:02 +00001546 }
Rafael Espindola0a017a62010-12-10 07:39:47 +00001547}
Rafael Espindola736a35d2010-12-28 05:39:27 +00001548
Rafael Espindola4066e8d2014-05-12 14:28:48 +00001549void MCDwarfFrameEmitter::EmitAdvanceLoc(MCObjectStreamer &Streamer,
Rafael Espindola736a35d2010-12-28 05:39:27 +00001550 uint64_t AddrDelta) {
Ulrich Weigand32d725b2013-06-12 14:46:54 +00001551 MCContext &Context = Streamer.getContext();
Alp Tokere69170a2014-06-26 22:52:05 +00001552 SmallString<256> Tmp;
1553 raw_svector_ostream OS(Tmp);
Ulrich Weigand32d725b2013-06-12 14:46:54 +00001554 MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OS);
Eric Christophere3ab3d02013-01-09 01:57:54 +00001555 Streamer.EmitBytes(OS.str());
Rafael Espindola736a35d2010-12-28 05:39:27 +00001556}
1557
Ulrich Weigand32d725b2013-06-12 14:46:54 +00001558void MCDwarfFrameEmitter::EncodeAdvanceLoc(MCContext &Context,
1559 uint64_t AddrDelta,
Rafael Espindolaab39c632011-05-08 14:35:21 +00001560 raw_ostream &OS) {
Ulrich Weigand32d725b2013-06-12 14:46:54 +00001561 // Scale the address delta by the minimum instruction length.
1562 AddrDelta = ScaleAddrDelta(Context, AddrDelta);
1563
Rafael Espindola6bbfb6c2010-12-28 23:38:03 +00001564 if (AddrDelta == 0) {
Rafael Espindolaab39c632011-05-08 14:35:21 +00001565 } else if (isUIntN(6, AddrDelta)) {
Rafael Espindola736a35d2010-12-28 05:39:27 +00001566 uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta;
1567 OS << Opcode;
Rafael Espindolaab39c632011-05-08 14:35:21 +00001568 } else if (isUInt<8>(AddrDelta)) {
Rafael Espindola736a35d2010-12-28 05:39:27 +00001569 OS << uint8_t(dwarf::DW_CFA_advance_loc1);
1570 OS << uint8_t(AddrDelta);
Rafael Espindolaab39c632011-05-08 14:35:21 +00001571 } else if (isUInt<16>(AddrDelta)) {
Rafael Espindola736a35d2010-12-28 05:39:27 +00001572 OS << uint8_t(dwarf::DW_CFA_advance_loc2);
Benjamin Kramer58675d42015-06-17 15:14:35 +00001573 if (Context.getAsmInfo()->isLittleEndian())
1574 support::endian::Writer<support::little>(OS).write<uint16_t>(AddrDelta);
1575 else
1576 support::endian::Writer<support::big>(OS).write<uint16_t>(AddrDelta);
Rafael Espindola736a35d2010-12-28 05:39:27 +00001577 } else {
1578 assert(isUInt<32>(AddrDelta));
1579 OS << uint8_t(dwarf::DW_CFA_advance_loc4);
Benjamin Kramer58675d42015-06-17 15:14:35 +00001580 if (Context.getAsmInfo()->isLittleEndian())
1581 support::endian::Writer<support::little>(OS).write<uint32_t>(AddrDelta);
1582 else
1583 support::endian::Writer<support::big>(OS).write<uint32_t>(AddrDelta);
Rafael Espindola736a35d2010-12-28 05:39:27 +00001584 }
1585}