LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCDwarf.cpp
Go to the documentation of this file.
1 //===- 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"
11 #include "llvm/ADT/Hashing.h"
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/ADT/Twine.h"
14 #include "llvm/Config/config.h"
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCStreamer.h"
21 #include "llvm/MC/MCSymbol.h"
22 #include "llvm/Support/Debug.h"
24 #include "llvm/Support/LEB128.h"
25 #include "llvm/Support/Path.h"
26 #include "llvm/Support/SourceMgr.h"
28 using namespace llvm;
29 
30 // Given a special op, return the address skip amount (in units of
31 // DWARF2_LINE_MIN_INSN_LENGTH.
32 #define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE)
33 
34 // The maximum address skip amount that can be encoded with a special op.
35 #define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255)
36 
37 // First special line opcode - leave room for the standard opcodes.
38 // Note: If you want to change this, you'll have to update the
39 // "standard_opcode_lengths" table that is emitted in DwarfFileTable::Emit().
40 #define DWARF2_LINE_OPCODE_BASE 13
41 
42 // Minimum line offset in a special line info. opcode. This value
43 // was chosen to give a reasonable range of values.
44 #define DWARF2_LINE_BASE -5
45 
46 // Range of line offsets in a special line info. opcode.
47 #define DWARF2_LINE_RANGE 14
48 
49 static inline uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta) {
50  unsigned MinInsnLength = Context.getAsmInfo()->getMinInstAlignment();
51  if (MinInsnLength == 1)
52  return AddrDelta;
53  if (AddrDelta % MinInsnLength != 0) {
54  // TODO: report this error, but really only once.
55  ;
56  }
57  return AddrDelta / MinInsnLength;
58 }
59 
60 //
61 // This is called when an instruction is assembled into the specified section
62 // and if there is information from the last .loc directive that has yet to have
63 // a line entry made for it is made.
64 //
66  if (!MCOS->getContext().getDwarfLocSeen())
67  return;
68 
69  // Create a symbol at in the current section for use in the line entry.
70  MCSymbol *LineSym = MCOS->getContext().CreateTempSymbol();
71  // Set the value of the symbol to use for the MCLineEntry.
72  MCOS->EmitLabel(LineSym);
73 
74  // Get the current .loc info saved in the context.
75  const MCDwarfLoc &DwarfLoc = MCOS->getContext().getCurrentDwarfLoc();
76 
77  // Create a (local) line entry with the symbol and the current .loc info.
78  MCLineEntry LineEntry(LineSym, DwarfLoc);
79 
80  // clear DwarfLocSeen saying the current .loc info is now used.
81  MCOS->getContext().ClearDwarfLocSeen();
82 
83  // Get the MCLineSection for this section, if one does not exist for this
84  // section create it.
85  const DenseMap<const MCSection *, MCLineSection *> &MCLineSections =
86  MCOS->getContext().getMCLineSections();
87  MCLineSection *LineSection = MCLineSections.lookup(Section);
88  if (!LineSection) {
89  // Create a new MCLineSection. This will be deleted after the dwarf line
90  // table is created using it by iterating through the MCLineSections
91  // DenseMap.
92  LineSection = new MCLineSection;
93  // Save a pointer to the new LineSection into the MCLineSections DenseMap.
94  MCOS->getContext().addMCLineSection(Section, LineSection);
95  }
96 
97  // Add the line entry to this section's entries.
98  LineSection->addLineEntry(LineEntry,
100 }
101 
102 //
103 // This helper routine returns an expression of End - Start + IntVal .
104 //
105 static inline const MCExpr *MakeStartMinusEndExpr(const MCStreamer &MCOS,
106  const MCSymbol &Start,
107  const MCSymbol &End,
108  int IntVal) {
110  const MCExpr *Res =
111  MCSymbolRefExpr::Create(&End, Variant, MCOS.getContext());
112  const MCExpr *RHS =
113  MCSymbolRefExpr::Create(&Start, Variant, MCOS.getContext());
114  const MCExpr *Res1 =
116  const MCExpr *Res2 =
117  MCConstantExpr::Create(IntVal, MCOS.getContext());
118  const MCExpr *Res3 =
120  return Res3;
121 }
122 
123 //
124 // This emits the Dwarf line table for the specified section from the entries
125 // in the LineSection.
126 //
127 static inline void EmitDwarfLineTable(MCStreamer *MCOS,
128  const MCSection *Section,
129  const MCLineSection *LineSection,
130  unsigned CUID) {
131  // This LineSection does not contain any LineEntry for the given Compile Unit.
132  if (!LineSection->containEntriesForID(CUID))
133  return;
134 
135  unsigned FileNum = 1;
136  unsigned LastLine = 1;
137  unsigned Column = 0;
139  unsigned Isa = 0;
140  MCSymbol *LastLabel = NULL;
141 
142  // Loop through each MCLineEntry and encode the dwarf line number table.
144  it = LineSection->getMCLineEntries(CUID).begin(),
145  ie = LineSection->getMCLineEntries(CUID).end(); it != ie; ++it) {
146 
147  if (FileNum != it->getFileNum()) {
148  FileNum = it->getFileNum();
150  MCOS->EmitULEB128IntValue(FileNum);
151  }
152  if (Column != it->getColumn()) {
153  Column = it->getColumn();
155  MCOS->EmitULEB128IntValue(Column);
156  }
157  if (Isa != it->getIsa()) {
158  Isa = it->getIsa();
160  MCOS->EmitULEB128IntValue(Isa);
161  }
162  if ((it->getFlags() ^ Flags) & DWARF2_FLAG_IS_STMT) {
163  Flags = it->getFlags();
165  }
166  if (it->getFlags() & DWARF2_FLAG_BASIC_BLOCK)
168  if (it->getFlags() & DWARF2_FLAG_PROLOGUE_END)
170  if (it->getFlags() & DWARF2_FLAG_EPILOGUE_BEGIN)
172 
173  int64_t LineDelta = static_cast<int64_t>(it->getLine()) - LastLine;
174  MCSymbol *Label = it->getLabel();
175 
176  // At this point we want to emit/create the sequence to encode the delta in
177  // line numbers and the increment of the address from the previous Label
178  // and the current Label.
179  const MCAsmInfo *asmInfo = MCOS->getContext().getAsmInfo();
180  MCOS->EmitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label,
181  asmInfo->getPointerSize());
182 
183  LastLine = it->getLine();
184  LastLabel = Label;
185  }
186 
187  // Emit a DW_LNE_end_sequence for the end of the section.
188  // Using the pointer Section create a temporary label at the end of the
189  // section and use that and the LastLabel to compute the address delta
190  // and use INT64_MAX as the line delta which is the signal that this is
191  // actually a DW_LNE_end_sequence.
192 
193  // Switch to the section to be able to create a symbol at its end.
194  // TODO: keep track of the last subsection so that this symbol appears in the
195  // correct place.
196  MCOS->SwitchSection(Section);
197 
198  MCContext &context = MCOS->getContext();
199  // Create a symbol at the end of the section.
200  MCSymbol *SectionEnd = context.CreateTempSymbol();
201  // Set the value of the symbol, as we are at the end of the section.
202  MCOS->EmitLabel(SectionEnd);
203 
204  // Switch back the dwarf line section.
206 
207  const MCAsmInfo *asmInfo = MCOS->getContext().getAsmInfo();
208  MCOS->EmitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd,
209  asmInfo->getPointerSize());
210 }
211 
212 //
213 // This emits the Dwarf file and the line tables.
214 //
216  MCContext &context = MCOS->getContext();
217  // Switch to the section where the table will be emitted into.
219 
220  const DenseMap<unsigned, MCSymbol *> &MCLineTableSymbols =
222  // CUID and MCLineTableSymbols are set in DwarfDebug, when DwarfDebug does
223  // not exist, CUID will be 0 and MCLineTableSymbols will be empty.
224  // Handle Compile Unit 0, the line table start symbol is the section symbol.
225  const MCSymbol *LineStartSym = EmitCU(MCOS, 0);
226  // Handle the rest of the Compile Units.
227  for (unsigned Is = 1, Ie = MCLineTableSymbols.size(); Is < Ie; Is++)
228  EmitCU(MCOS, Is);
229 
230  // Now delete the MCLineSections that were created in MCLineEntry::Make()
231  // and used to emit the line table.
232  const DenseMap<const MCSection *, MCLineSection *> &MCLineSections =
233  MCOS->getContext().getMCLineSections();
235  MCLineSections.begin(), ie = MCLineSections.end(); it != ie;
236  ++it)
237  delete it->second;
238 
239  return LineStartSym;
240 }
241 
242 const MCSymbol *MCDwarfFileTable::EmitCU(MCStreamer *MCOS, unsigned CUID) {
243  MCContext &context = MCOS->getContext();
244 
245  // Create a symbol at the beginning of the line table.
246  MCSymbol *LineStartSym = MCOS->getContext().getMCLineTableSymbol(CUID);
247  if (!LineStartSym)
248  LineStartSym = context.CreateTempSymbol();
249  // Set the value of the symbol, as we are at the start of the line table.
250  MCOS->EmitLabel(LineStartSym);
251 
252  // Create a symbol for the end of the section (to be set when we get there).
253  MCSymbol *LineEndSym = context.CreateTempSymbol();
254 
255  // The first 4 bytes is the total length of the information for this
256  // compilation unit (not including these 4 bytes for the length).
257  MCOS->EmitAbsValue(MakeStartMinusEndExpr(*MCOS, *LineStartSym, *LineEndSym,4),
258  4);
259 
260  // Next 2 bytes is the Version, which is Dwarf 2.
261  MCOS->EmitIntValue(2, 2);
262 
263  // Create a symbol for the end of the prologue (to be set when we get there).
264  MCSymbol *ProEndSym = context.CreateTempSymbol(); // Lprologue_end
265 
266  // Length of the prologue, is the next 4 bytes. Which is the start of the
267  // section to the end of the prologue. Not including the 4 bytes for the
268  // total length, the 2 bytes for the version, and these 4 bytes for the
269  // length of the prologue.
270  MCOS->EmitAbsValue(MakeStartMinusEndExpr(*MCOS, *LineStartSym, *ProEndSym,
271  (4 + 2 + 4)), 4);
272 
273  // Parameters of the state machine, are next.
274  MCOS->EmitIntValue(context.getAsmInfo()->getMinInstAlignment(), 1);
276  MCOS->EmitIntValue(DWARF2_LINE_BASE, 1);
279 
280  // Standard opcode lengths
281  MCOS->EmitIntValue(0, 1); // length of DW_LNS_copy
282  MCOS->EmitIntValue(1, 1); // length of DW_LNS_advance_pc
283  MCOS->EmitIntValue(1, 1); // length of DW_LNS_advance_line
284  MCOS->EmitIntValue(1, 1); // length of DW_LNS_set_file
285  MCOS->EmitIntValue(1, 1); // length of DW_LNS_set_column
286  MCOS->EmitIntValue(0, 1); // length of DW_LNS_negate_stmt
287  MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_basic_block
288  MCOS->EmitIntValue(0, 1); // length of DW_LNS_const_add_pc
289  MCOS->EmitIntValue(1, 1); // length of DW_LNS_fixed_advance_pc
290  MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_prologue_end
291  MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_epilogue_begin
292  MCOS->EmitIntValue(1, 1); // DW_LNS_set_isa
293 
294  // Put out the directory and file tables.
295 
296  // First the directory table.
297  const SmallVectorImpl<StringRef> &MCDwarfDirs =
298  context.getMCDwarfDirs(CUID);
299  for (unsigned i = 0; i < MCDwarfDirs.size(); i++) {
300  MCOS->EmitBytes(MCDwarfDirs[i]); // the DirectoryName
301  MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string
302  }
303  MCOS->EmitIntValue(0, 1); // Terminate the directory list
304 
305  // Second the file table.
306  const SmallVectorImpl<MCDwarfFile *> &MCDwarfFiles =
307  MCOS->getContext().getMCDwarfFiles(CUID);
308  for (unsigned i = 1; i < MCDwarfFiles.size(); i++) {
309  MCOS->EmitBytes(MCDwarfFiles[i]->getName()); // FileName
310  MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string
311  // the Directory num
312  MCOS->EmitULEB128IntValue(MCDwarfFiles[i]->getDirIndex());
313  MCOS->EmitIntValue(0, 1); // last modification timestamp (always 0)
314  MCOS->EmitIntValue(0, 1); // filesize (always 0)
315  }
316  MCOS->EmitIntValue(0, 1); // Terminate the file list
317 
318  // This is the end of the prologue, so set the value of the symbol at the
319  // end of the prologue (that was used in a previous expression).
320  MCOS->EmitLabel(ProEndSym);
321 
322  // Put out the line tables.
323  const DenseMap<const MCSection *, MCLineSection *> &MCLineSections =
324  MCOS->getContext().getMCLineSections();
325  const std::vector<const MCSection *> &MCLineSectionOrder =
327  for (std::vector<const MCSection*>::const_iterator it =
328  MCLineSectionOrder.begin(), ie = MCLineSectionOrder.end(); it != ie;
329  ++it) {
330  const MCSection *Sec = *it;
331  const MCLineSection *Line = MCLineSections.lookup(Sec);
332  EmitDwarfLineTable(MCOS, Sec, Line, CUID);
333  }
334 
336  && MCLineSectionOrder.begin() == MCLineSectionOrder.end()) {
337  // The darwin9 linker has a bug (see PR8715). For for 32-bit architectures
338  // it requires:
339  // total_length >= prologue_length + 10
340  // We are 4 bytes short, since we have total_length = 51 and
341  // prologue_length = 45
342 
343  // The regular end_sequence should be sufficient.
344  MCDwarfLineAddr::Emit(MCOS, INT64_MAX, 0);
345  }
346 
347  // This is the end of the section, so set the value of the symbol at the end
348  // of this section (that was used in a previous expression).
349  MCOS->EmitLabel(LineEndSym);
350 
351  return LineStartSym;
352 }
353 
354 /// Utility function to emit the encoding to a streamer.
355 void MCDwarfLineAddr::Emit(MCStreamer *MCOS, int64_t LineDelta,
356  uint64_t AddrDelta) {
357  MCContext &Context = MCOS->getContext();
358  SmallString<256> Tmp;
359  raw_svector_ostream OS(Tmp);
360  MCDwarfLineAddr::Encode(Context, LineDelta, AddrDelta, OS);
361  MCOS->EmitBytes(OS.str());
362 }
363 
364 /// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
365 void MCDwarfLineAddr::Encode(MCContext &Context, int64_t LineDelta,
366  uint64_t AddrDelta, raw_ostream &OS) {
367  uint64_t Temp, Opcode;
368  bool NeedCopy = false;
369 
370  // Scale the address delta by the minimum instruction length.
371  AddrDelta = ScaleAddrDelta(Context, AddrDelta);
372 
373  // A LineDelta of INT64_MAX is a signal that this is actually a
374  // DW_LNE_end_sequence. We cannot use special opcodes here, since we want the
375  // end_sequence to emit the matrix entry.
376  if (LineDelta == INT64_MAX) {
377  if (AddrDelta == MAX_SPECIAL_ADDR_DELTA)
378  OS << char(dwarf::DW_LNS_const_add_pc);
379  else {
380  OS << char(dwarf::DW_LNS_advance_pc);
381  encodeULEB128(AddrDelta, OS);
382  }
383  OS << char(dwarf::DW_LNS_extended_op);
384  OS << char(1);
385  OS << char(dwarf::DW_LNE_end_sequence);
386  return;
387  }
388 
389  // Bias the line delta by the base.
390  Temp = LineDelta - DWARF2_LINE_BASE;
391 
392  // If the line increment is out of range of a special opcode, we must encode
393  // it with DW_LNS_advance_line.
394  if (Temp >= DWARF2_LINE_RANGE) {
395  OS << char(dwarf::DW_LNS_advance_line);
396  encodeSLEB128(LineDelta, OS);
397 
398  LineDelta = 0;
399  Temp = 0 - DWARF2_LINE_BASE;
400  NeedCopy = true;
401  }
402 
403  // Use DW_LNS_copy instead of a "line +0, addr +0" special opcode.
404  if (LineDelta == 0 && AddrDelta == 0) {
405  OS << char(dwarf::DW_LNS_copy);
406  return;
407  }
408 
409  // Bias the opcode by the special opcode base.
410  Temp += DWARF2_LINE_OPCODE_BASE;
411 
412  // Avoid overflow when addr_delta is large.
413  if (AddrDelta < 256 + MAX_SPECIAL_ADDR_DELTA) {
414  // Try using a special opcode.
415  Opcode = Temp + AddrDelta * DWARF2_LINE_RANGE;
416  if (Opcode <= 255) {
417  OS << char(Opcode);
418  return;
419  }
420 
421  // Try using DW_LNS_const_add_pc followed by special op.
422  Opcode = Temp + (AddrDelta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
423  if (Opcode <= 255) {
424  OS << char(dwarf::DW_LNS_const_add_pc);
425  OS << char(Opcode);
426  return;
427  }
428  }
429 
430  // Otherwise use DW_LNS_advance_pc.
431  OS << char(dwarf::DW_LNS_advance_pc);
432  encodeULEB128(AddrDelta, OS);
433 
434  if (NeedCopy)
435  OS << char(dwarf::DW_LNS_copy);
436  else
437  OS << char(Temp);
438 }
439 
441  OS << '"' << getName() << '"';
442 }
443 
444 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
445 void MCDwarfFile::dump() const {
446  print(dbgs());
447 }
448 #endif
449 
450 // Utility function to write a tuple for .debug_abbrev.
451 static void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form) {
452  MCOS->EmitULEB128IntValue(Name);
453  MCOS->EmitULEB128IntValue(Form);
454 }
455 
456 // When generating dwarf for assembly source files this emits
457 // the data for .debug_abbrev section which contains three DIEs.
458 static void EmitGenDwarfAbbrev(MCStreamer *MCOS) {
459  MCContext &context = MCOS->getContext();
461 
462  // DW_TAG_compile_unit DIE abbrev (1).
463  MCOS->EmitULEB128IntValue(1);
464  MCOS->EmitULEB128IntValue(dwarf::DW_TAG_compile_unit);
466  EmitAbbrev(MCOS, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4);
467  EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
468  EmitAbbrev(MCOS, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr);
469  EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
470  EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string);
471  StringRef DwarfDebugFlags = context.getDwarfDebugFlags();
472  if (!DwarfDebugFlags.empty())
473  EmitAbbrev(MCOS, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string);
474  EmitAbbrev(MCOS, dwarf::DW_AT_producer, dwarf::DW_FORM_string);
475  EmitAbbrev(MCOS, dwarf::DW_AT_language, dwarf::DW_FORM_data2);
476  EmitAbbrev(MCOS, 0, 0);
477 
478  // DW_TAG_label DIE abbrev (2).
479  MCOS->EmitULEB128IntValue(2);
480  MCOS->EmitULEB128IntValue(dwarf::DW_TAG_label);
482  EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
483  EmitAbbrev(MCOS, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data4);
484  EmitAbbrev(MCOS, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data4);
485  EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
486  EmitAbbrev(MCOS, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag);
487  EmitAbbrev(MCOS, 0, 0);
488 
489  // DW_TAG_unspecified_parameters DIE abbrev (3).
490  MCOS->EmitULEB128IntValue(3);
491  MCOS->EmitULEB128IntValue(dwarf::DW_TAG_unspecified_parameters);
493  EmitAbbrev(MCOS, 0, 0);
494 
495  // Terminate the abbreviations for this compilation unit.
496  MCOS->EmitIntValue(0, 1);
497 }
498 
499 // When generating dwarf for assembly source files this emits the data for
500 // .debug_aranges section. Which contains a header and a table of pairs of
501 // PointerSize'ed values for the address and size of section(s) with line table
502 // entries (just the default .text in our case) and a terminating pair of zeros.
503 static void EmitGenDwarfAranges(MCStreamer *MCOS,
504  const MCSymbol *InfoSectionSymbol) {
505  MCContext &context = MCOS->getContext();
506 
507  // Create a symbol at the end of the section that we are creating the dwarf
508  // debugging info to use later in here as part of the expression to calculate
509  // the size of the section for the table.
510  MCOS->SwitchSection(context.getGenDwarfSection());
511  MCSymbol *SectionEndSym = context.CreateTempSymbol();
512  MCOS->EmitLabel(SectionEndSym);
513  context.setGenDwarfSectionEndSym(SectionEndSym);
514 
516 
517  // This will be the length of the .debug_aranges section, first account for
518  // the size of each item in the header (see below where we emit these items).
519  int Length = 4 + 2 + 4 + 1 + 1;
520 
521  // Figure the padding after the header before the table of address and size
522  // pairs who's values are PointerSize'ed.
523  const MCAsmInfo *asmInfo = context.getAsmInfo();
524  int AddrSize = asmInfo->getPointerSize();
525  int Pad = 2 * AddrSize - (Length & (2 * AddrSize - 1));
526  if (Pad == 2 * AddrSize)
527  Pad = 0;
528  Length += Pad;
529 
530  // Add the size of the pair of PointerSize'ed values for the address and size
531  // of the one default .text section we have in the table.
532  Length += 2 * AddrSize;
533  // And the pair of terminating zeros.
534  Length += 2 * AddrSize;
535 
536 
537  // Emit the header for this section.
538  // The 4 byte length not including the 4 byte value for the length.
539  MCOS->EmitIntValue(Length - 4, 4);
540  // The 2 byte version, which is 2.
541  MCOS->EmitIntValue(2, 2);
542  // The 4 byte offset to the compile unit in the .debug_info from the start
543  // of the .debug_info.
544  if (InfoSectionSymbol)
545  MCOS->EmitSymbolValue(InfoSectionSymbol, 4);
546  else
547  MCOS->EmitIntValue(0, 4);
548  // The 1 byte size of an address.
549  MCOS->EmitIntValue(AddrSize, 1);
550  // The 1 byte size of a segment descriptor, we use a value of zero.
551  MCOS->EmitIntValue(0, 1);
552  // Align the header with the padding if needed, before we put out the table.
553  for(int i = 0; i < Pad; i++)
554  MCOS->EmitIntValue(0, 1);
555 
556  // Now emit the table of pairs of PointerSize'ed values for the section(s)
557  // address and size, in our case just the one default .text section.
558  const MCExpr *Addr = MCSymbolRefExpr::Create(
560  const MCExpr *Size = MakeStartMinusEndExpr(*MCOS,
561  *context.getGenDwarfSectionStartSym(), *SectionEndSym, 0);
562  MCOS->EmitAbsValue(Addr, AddrSize);
563  MCOS->EmitAbsValue(Size, AddrSize);
564 
565  // And finally the pair of terminating zeros.
566  MCOS->EmitIntValue(0, AddrSize);
567  MCOS->EmitIntValue(0, AddrSize);
568 }
569 
570 // When generating dwarf for assembly source files this emits the data for
571 // .debug_info section which contains three parts. The header, the compile_unit
572 // DIE and a list of label DIEs.
573 static void EmitGenDwarfInfo(MCStreamer *MCOS,
574  const MCSymbol *AbbrevSectionSymbol,
575  const MCSymbol *LineSectionSymbol) {
576  MCContext &context = MCOS->getContext();
577 
579 
580  // Create a symbol at the start and end of this section used in here for the
581  // expression to calculate the length in the header.
582  MCSymbol *InfoStart = context.CreateTempSymbol();
583  MCOS->EmitLabel(InfoStart);
584  MCSymbol *InfoEnd = context.CreateTempSymbol();
585 
586  // First part: the header.
587 
588  // The 4 byte total length of the information for this compilation unit, not
589  // including these 4 bytes.
590  const MCExpr *Length = MakeStartMinusEndExpr(*MCOS, *InfoStart, *InfoEnd, 4);
591  MCOS->EmitAbsValue(Length, 4);
592 
593  // The 2 byte DWARF version, which is 2.
594  MCOS->EmitIntValue(2, 2);
595 
596  // The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev,
597  // it is at the start of that section so this is zero.
598  if (AbbrevSectionSymbol) {
599  MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4);
600  } else {
601  MCOS->EmitIntValue(0, 4);
602  }
603 
604  const MCAsmInfo *asmInfo = context.getAsmInfo();
605  int AddrSize = asmInfo->getPointerSize();
606  // The 1 byte size of an address.
607  MCOS->EmitIntValue(AddrSize, 1);
608 
609  // Second part: the compile_unit DIE.
610 
611  // The DW_TAG_compile_unit DIE abbrev (1).
612  MCOS->EmitULEB128IntValue(1);
613 
614  // DW_AT_stmt_list, a 4 byte offset from the start of the .debug_line section,
615  // which is at the start of that section so this is zero.
616  if (LineSectionSymbol) {
617  MCOS->EmitSymbolValue(LineSectionSymbol, 4);
618  } else {
619  MCOS->EmitIntValue(0, 4);
620  }
621 
622  // AT_low_pc, the first address of the default .text section.
623  const MCExpr *Start = MCSymbolRefExpr::Create(
625  MCOS->EmitAbsValue(Start, AddrSize);
626 
627  // AT_high_pc, the last address of the default .text section.
628  const MCExpr *End = MCSymbolRefExpr::Create(
630  MCOS->EmitAbsValue(End, AddrSize);
631 
632  // AT_name, the name of the source file. Reconstruct from the first directory
633  // and file table entries.
634  const SmallVectorImpl<StringRef> &MCDwarfDirs =
635  context.getMCDwarfDirs();
636  if (MCDwarfDirs.size() > 0) {
637  MCOS->EmitBytes(MCDwarfDirs[0]);
638  MCOS->EmitBytes("/");
639  }
640  const SmallVectorImpl<MCDwarfFile *> &MCDwarfFiles =
641  MCOS->getContext().getMCDwarfFiles();
642  MCOS->EmitBytes(MCDwarfFiles[1]->getName());
643  MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
644 
645  // AT_comp_dir, the working directory the assembly was done in.
646  MCOS->EmitBytes(context.getCompilationDir());
647  MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
648 
649  // AT_APPLE_flags, the command line arguments of the assembler tool.
650  StringRef DwarfDebugFlags = context.getDwarfDebugFlags();
651  if (!DwarfDebugFlags.empty()){
652  MCOS->EmitBytes(DwarfDebugFlags);
653  MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
654  }
655 
656  // AT_producer, the version of the assembler tool.
657  StringRef DwarfDebugProducer = context.getDwarfDebugProducer();
658  if (!DwarfDebugProducer.empty()){
659  MCOS->EmitBytes(DwarfDebugProducer);
660  }
661  else {
662  MCOS->EmitBytes(StringRef("llvm-mc (based on LLVM "));
663  MCOS->EmitBytes(StringRef(PACKAGE_VERSION));
664  MCOS->EmitBytes(StringRef(")"));
665  }
666  MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
667 
668  // AT_language, a 4 byte value. We use DW_LANG_Mips_Assembler as the dwarf2
669  // draft has no standard code for assembler.
671 
672  // Third part: the list of label DIEs.
673 
674  // Loop on saved info for dwarf labels and create the DIEs for them.
675  const std::vector<const MCGenDwarfLabelEntry *> &Entries =
677  for (std::vector<const MCGenDwarfLabelEntry *>::const_iterator it =
678  Entries.begin(), ie = Entries.end(); it != ie;
679  ++it) {
680  const MCGenDwarfLabelEntry *Entry = *it;
681 
682  // The DW_TAG_label DIE abbrev (2).
683  MCOS->EmitULEB128IntValue(2);
684 
685  // AT_name, of the label without any leading underbar.
686  MCOS->EmitBytes(Entry->getName());
687  MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
688 
689  // AT_decl_file, index into the file table.
690  MCOS->EmitIntValue(Entry->getFileNumber(), 4);
691 
692  // AT_decl_line, source line number.
693  MCOS->EmitIntValue(Entry->getLineNumber(), 4);
694 
695  // AT_low_pc, start address of the label.
696  const MCExpr *AT_low_pc = MCSymbolRefExpr::Create(Entry->getLabel(),
697  MCSymbolRefExpr::VK_None, context);
698  MCOS->EmitAbsValue(AT_low_pc, AddrSize);
699 
700  // DW_AT_prototyped, a one byte flag value of 0 saying we have no prototype.
701  MCOS->EmitIntValue(0, 1);
702 
703  // The DW_TAG_unspecified_parameters DIE abbrev (3).
704  MCOS->EmitULEB128IntValue(3);
705 
706  // Add the NULL DIE terminating the DW_TAG_unspecified_parameters DIE's.
707  MCOS->EmitIntValue(0, 1);
708  }
709  // Deallocate the MCGenDwarfLabelEntry classes that saved away the info
710  // for the dwarf labels.
711  for (std::vector<const MCGenDwarfLabelEntry *>::const_iterator it =
712  Entries.begin(), ie = Entries.end(); it != ie;
713  ++it) {
714  const MCGenDwarfLabelEntry *Entry = *it;
715  delete Entry;
716  }
717 
718  // Add the NULL DIE terminating the Compile Unit DIE's.
719  MCOS->EmitIntValue(0, 1);
720 
721  // Now set the value of the symbol at the end of the info section.
722  MCOS->EmitLabel(InfoEnd);
723 }
724 
725 //
726 // When generating dwarf for assembly source files this emits the Dwarf
727 // sections.
728 //
729 void MCGenDwarfInfo::Emit(MCStreamer *MCOS, const MCSymbol *LineSectionSymbol) {
730  // Create the dwarf sections in this order (.debug_line already created).
731  MCContext &context = MCOS->getContext();
732  const MCAsmInfo *AsmInfo = context.getAsmInfo();
733  bool CreateDwarfSectionSymbols =
735  if (!CreateDwarfSectionSymbols)
736  LineSectionSymbol = NULL;
737  MCSymbol *AbbrevSectionSymbol = NULL;
738  MCSymbol *InfoSectionSymbol = NULL;
740  if (CreateDwarfSectionSymbols) {
741  InfoSectionSymbol = context.CreateTempSymbol();
742  MCOS->EmitLabel(InfoSectionSymbol);
743  }
745  if (CreateDwarfSectionSymbols) {
746  AbbrevSectionSymbol = context.CreateTempSymbol();
747  MCOS->EmitLabel(AbbrevSectionSymbol);
748  }
750 
751  // If there are no line table entries then do not emit any section contents.
752  if (context.getMCLineSections().empty())
753  return;
754 
755  // Output the data for .debug_aranges section.
756  EmitGenDwarfAranges(MCOS, InfoSectionSymbol);
757 
758  // Output the data for .debug_abbrev section.
759  EmitGenDwarfAbbrev(MCOS);
760 
761  // Output the data for .debug_info section.
762  EmitGenDwarfInfo(MCOS, AbbrevSectionSymbol, LineSectionSymbol);
763 }
764 
765 //
766 // When generating dwarf for assembly source files this is called when symbol
767 // for a label is created. If this symbol is not a temporary and is in the
768 // section that dwarf is being generated for, save the needed info to create
769 // a dwarf label.
770 //
772  SourceMgr &SrcMgr, SMLoc &Loc) {
773  // We won't create dwarf labels for temporary symbols or symbols not in
774  // the default text.
775  if (Symbol->isTemporary())
776  return;
777  MCContext &context = MCOS->getContext();
778  if (context.getGenDwarfSection() != MCOS->getCurrentSection().first)
779  return;
780 
781  // The dwarf label's name does not have the symbol name's leading
782  // underbar if any.
783  StringRef Name = Symbol->getName();
784  if (Name.startswith("_"))
785  Name = Name.substr(1, Name.size()-1);
786 
787  // Get the dwarf file number to be used for the dwarf label.
788  unsigned FileNumber = context.getGenDwarfFileNumber();
789 
790  // Finding the line number is the expensive part which is why we just don't
791  // pass it in as for some symbols we won't create a dwarf label.
792  int CurBuffer = SrcMgr.FindBufferContainingLoc(Loc);
793  unsigned LineNumber = SrcMgr.FindLineNumber(Loc, CurBuffer);
794 
795  // We create a temporary symbol for use for the AT_high_pc and AT_low_pc
796  // values so that they don't have things like an ARM thumb bit from the
797  // original symbol. So when used they won't get a low bit set after
798  // relocation.
799  MCSymbol *Label = context.CreateTempSymbol();
800  MCOS->EmitLabel(Label);
801 
802  // Create and entry for the info and add it to the other entries.
803  MCGenDwarfLabelEntry *Entry =
804  new MCGenDwarfLabelEntry(Name, FileNumber, LineNumber, Label);
805  MCOS->getContext().addMCGenDwarfLabelEntry(Entry);
806 }
807 
808 static int getDataAlignmentFactor(MCStreamer &streamer) {
809  MCContext &context = streamer.getContext();
810  const MCAsmInfo *asmInfo = context.getAsmInfo();
811  int size = asmInfo->getCalleeSaveStackSlotSize();
812  if (asmInfo->isStackGrowthDirectionUp())
813  return size;
814  else
815  return -size;
816 }
817 
818 static unsigned getSizeForEncoding(MCStreamer &streamer,
819  unsigned symbolEncoding) {
820  MCContext &context = streamer.getContext();
821  unsigned format = symbolEncoding & 0x0f;
822  switch (format) {
823  default: llvm_unreachable("Unknown Encoding");
826  return context.getAsmInfo()->getPointerSize();
829  return 2;
832  return 4;
835  return 8;
836  }
837 }
838 
839 static void EmitSymbol(MCStreamer &streamer, const MCSymbol &symbol,
840  unsigned symbolEncoding, const char *comment = 0) {
841  MCContext &context = streamer.getContext();
842  const MCAsmInfo *asmInfo = context.getAsmInfo();
843  const MCExpr *v = asmInfo->getExprForFDESymbol(&symbol,
844  symbolEncoding,
845  streamer);
846  unsigned size = getSizeForEncoding(streamer, symbolEncoding);
847  if (streamer.isVerboseAsm() && comment) streamer.AddComment(comment);
848  streamer.EmitAbsValue(v, size);
849 }
850 
851 static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol,
852  unsigned symbolEncoding) {
853  MCContext &context = streamer.getContext();
854  const MCAsmInfo *asmInfo = context.getAsmInfo();
855  const MCExpr *v = asmInfo->getExprForPersonalitySymbol(&symbol,
856  symbolEncoding,
857  streamer);
858  unsigned size = getSizeForEncoding(streamer, symbolEncoding);
859  streamer.EmitValue(v, size);
860 }
861 
862 namespace {
863  class FrameEmitterImpl {
864  int CFAOffset;
865  int CIENum;
866  bool UsingCFI;
867  bool IsEH;
868  const MCSymbol *SectionStart;
869  public:
870  FrameEmitterImpl(bool usingCFI, bool isEH)
871  : CFAOffset(0), CIENum(0), UsingCFI(usingCFI), IsEH(isEH),
872  SectionStart(0) {}
873 
874  void setSectionStart(const MCSymbol *Label) { SectionStart = Label; }
875 
876  /// EmitCompactUnwind - Emit the unwind information in a compact way.
877  void EmitCompactUnwind(MCStreamer &streamer,
878  const MCDwarfFrameInfo &frame);
879 
880  const MCSymbol &EmitCIE(MCStreamer &streamer,
881  const MCSymbol *personality,
882  unsigned personalityEncoding,
883  const MCSymbol *lsda,
884  bool IsSignalFrame,
885  unsigned lsdaEncoding);
886  MCSymbol *EmitFDE(MCStreamer &streamer,
887  const MCSymbol &cieStart,
888  const MCDwarfFrameInfo &frame);
889  void EmitCFIInstructions(MCStreamer &streamer,
891  MCSymbol *BaseLabel);
892  void EmitCFIInstruction(MCStreamer &Streamer,
893  const MCCFIInstruction &Instr);
894  };
895 
896 } // end anonymous namespace
897 
898 static void EmitEncodingByte(MCStreamer &Streamer, unsigned Encoding,
899  StringRef Prefix) {
900  if (Streamer.isVerboseAsm()) {
901  const char *EncStr;
902  switch (Encoding) {
903  default: EncStr = "<unknown encoding>"; break;
904  case dwarf::DW_EH_PE_absptr: EncStr = "absptr"; break;
905  case dwarf::DW_EH_PE_omit: EncStr = "omit"; break;
906  case dwarf::DW_EH_PE_pcrel: EncStr = "pcrel"; break;
907  case dwarf::DW_EH_PE_udata4: EncStr = "udata4"; break;
908  case dwarf::DW_EH_PE_udata8: EncStr = "udata8"; break;
909  case dwarf::DW_EH_PE_sdata4: EncStr = "sdata4"; break;
910  case dwarf::DW_EH_PE_sdata8: EncStr = "sdata8"; break;
912  EncStr = "pcrel udata4";
913  break;
915  EncStr = "pcrel sdata4";
916  break;
918  EncStr = "pcrel udata8";
919  break;
921  EncStr = "screl sdata8";
922  break;
924  EncStr = "indirect pcrel udata4";
925  break;
927  EncStr = "indirect pcrel sdata4";
928  break;
930  EncStr = "indirect pcrel udata8";
931  break;
933  EncStr = "indirect pcrel sdata8";
934  break;
935  }
936 
937  Streamer.AddComment(Twine(Prefix) + " = " + EncStr);
938  }
939 
940  Streamer.EmitIntValue(Encoding, 1);
941 }
942 
943 void FrameEmitterImpl::EmitCFIInstruction(MCStreamer &Streamer,
944  const MCCFIInstruction &Instr) {
945  int dataAlignmentFactor = getDataAlignmentFactor(Streamer);
946  bool VerboseAsm = Streamer.isVerboseAsm();
947 
948  switch (Instr.getOperation()) {
950  unsigned Reg1 = Instr.getRegister();
951  unsigned Reg2 = Instr.getRegister2();
952  if (VerboseAsm) {
953  Streamer.AddComment("DW_CFA_register");
954  Streamer.AddComment(Twine("Reg1 ") + Twine(Reg1));
955  Streamer.AddComment(Twine("Reg2 ") + Twine(Reg2));
956  }
958  Streamer.EmitULEB128IntValue(Reg1);
959  Streamer.EmitULEB128IntValue(Reg2);
960  return;
961  }
964  return;
965  }
967  unsigned Reg = Instr.getRegister();
968  if (VerboseAsm) {
969  Streamer.AddComment("DW_CFA_undefined");
970  Streamer.AddComment(Twine("Reg ") + Twine(Reg));
971  }
973  Streamer.EmitULEB128IntValue(Reg);
974  return;
975  }
978  const bool IsRelative =
980 
981  if (VerboseAsm)
982  Streamer.AddComment("DW_CFA_def_cfa_offset");
984 
985  if (IsRelative)
986  CFAOffset += Instr.getOffset();
987  else
988  CFAOffset = -Instr.getOffset();
989 
990  if (VerboseAsm)
991  Streamer.AddComment(Twine("Offset " + Twine(CFAOffset)));
992  Streamer.EmitULEB128IntValue(CFAOffset);
993 
994  return;
995  }
997  if (VerboseAsm)
998  Streamer.AddComment("DW_CFA_def_cfa");
999  Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa, 1);
1000 
1001  if (VerboseAsm)
1002  Streamer.AddComment(Twine("Reg ") + Twine(Instr.getRegister()));
1003  Streamer.EmitULEB128IntValue(Instr.getRegister());
1004 
1005  CFAOffset = -Instr.getOffset();
1006 
1007  if (VerboseAsm)
1008  Streamer.AddComment(Twine("Offset " + Twine(CFAOffset)));
1009  Streamer.EmitULEB128IntValue(CFAOffset);
1010 
1011  return;
1012  }
1013 
1015  if (VerboseAsm)
1016  Streamer.AddComment("DW_CFA_def_cfa_register");
1018 
1019  if (VerboseAsm)
1020  Streamer.AddComment(Twine("Reg ") + Twine(Instr.getRegister()));
1021  Streamer.EmitULEB128IntValue(Instr.getRegister());
1022 
1023  return;
1024  }
1025 
1028  const bool IsRelative =
1030 
1031  unsigned Reg = Instr.getRegister();
1032  int Offset = Instr.getOffset();
1033  if (IsRelative)
1034  Offset -= CFAOffset;
1035  Offset = Offset / dataAlignmentFactor;
1036 
1037  if (Offset < 0) {
1038  if (VerboseAsm) Streamer.AddComment("DW_CFA_offset_extended_sf");
1040  if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg));
1041  Streamer.EmitULEB128IntValue(Reg);
1042  if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset));
1043  Streamer.EmitSLEB128IntValue(Offset);
1044  } else if (Reg < 64) {
1045  if (VerboseAsm) Streamer.AddComment(Twine("DW_CFA_offset + Reg(") +
1046  Twine(Reg) + ")");
1047  Streamer.EmitIntValue(dwarf::DW_CFA_offset + Reg, 1);
1048  if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset));
1049  Streamer.EmitULEB128IntValue(Offset);
1050  } else {
1051  if (VerboseAsm) Streamer.AddComment("DW_CFA_offset_extended");
1053  if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg));
1054  Streamer.EmitULEB128IntValue(Reg);
1055  if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset));
1056  Streamer.EmitULEB128IntValue(Offset);
1057  }
1058  return;
1059  }
1061  if (VerboseAsm) Streamer.AddComment("DW_CFA_remember_state");
1063  return;
1065  if (VerboseAsm) Streamer.AddComment("DW_CFA_restore_state");
1067  return;
1069  unsigned Reg = Instr.getRegister();
1070  if (VerboseAsm) Streamer.AddComment("DW_CFA_same_value");
1072  if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg));
1073  Streamer.EmitULEB128IntValue(Reg);
1074  return;
1075  }
1077  unsigned Reg = Instr.getRegister();
1078  if (VerboseAsm) {
1079  Streamer.AddComment("DW_CFA_restore");
1080  Streamer.AddComment(Twine("Reg ") + Twine(Reg));
1081  }
1082  Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1);
1083  return;
1084  }
1086  if (VerboseAsm) Streamer.AddComment("Escape bytes");
1087  Streamer.EmitBytes(Instr.getValues());
1088  return;
1089  }
1090  llvm_unreachable("Unhandled case in switch");
1091 }
1092 
1093 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
1094 /// frame.
1095 void FrameEmitterImpl::EmitCFIInstructions(MCStreamer &streamer,
1097  MCSymbol *BaseLabel) {
1098  for (unsigned i = 0, N = Instrs.size(); i < N; ++i) {
1099  const MCCFIInstruction &Instr = Instrs[i];
1100  MCSymbol *Label = Instr.getLabel();
1101  // Throw out move if the label is invalid.
1102  if (Label && !Label->isDefined()) continue; // Not emitted, in dead code.
1103 
1104  // Advance row if new location.
1105  if (BaseLabel && Label) {
1106  MCSymbol *ThisSym = Label;
1107  if (ThisSym != BaseLabel) {
1108  if (streamer.isVerboseAsm()) streamer.AddComment("DW_CFA_advance_loc4");
1109  streamer.EmitDwarfAdvanceFrameAddr(BaseLabel, ThisSym);
1110  BaseLabel = ThisSym;
1111  }
1112  }
1113 
1114  EmitCFIInstruction(streamer, Instr);
1115  }
1116 }
1117 
1118 /// EmitCompactUnwind - Emit the unwind information in a compact way.
1119 void FrameEmitterImpl::EmitCompactUnwind(MCStreamer &Streamer,
1120  const MCDwarfFrameInfo &Frame) {
1121  MCContext &Context = Streamer.getContext();
1122  const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
1123  bool VerboseAsm = Streamer.isVerboseAsm();
1124 
1125  // range-start range-length compact-unwind-enc personality-func lsda
1126  // _foo LfooEnd-_foo 0x00000023 0 0
1127  // _bar LbarEnd-_bar 0x00000025 __gxx_personality except_tab1
1128  //
1129  // .section __LD,__compact_unwind,regular,debug
1130  //
1131  // # compact unwind for _foo
1132  // .quad _foo
1133  // .set L1,LfooEnd-_foo
1134  // .long L1
1135  // .long 0x01010001
1136  // .quad 0
1137  // .quad 0
1138  //
1139  // # compact unwind for _bar
1140  // .quad _bar
1141  // .set L2,LbarEnd-_bar
1142  // .long L2
1143  // .long 0x01020011
1144  // .quad __gxx_personality
1145  // .quad except_tab1
1146 
1147  uint32_t Encoding = Frame.CompactUnwindEncoding;
1148  if (!Encoding) return;
1149  bool DwarfEHFrameOnly = (Encoding == MOFI->getCompactUnwindDwarfEHFrameOnly());
1150 
1151  // The encoding needs to know we have an LSDA.
1152  if (!DwarfEHFrameOnly && Frame.Lsda)
1153  Encoding |= 0x40000000;
1154 
1155  // Range Start
1156  unsigned FDEEncoding = MOFI->getFDEEncoding(UsingCFI);
1157  unsigned Size = getSizeForEncoding(Streamer, FDEEncoding);
1158  if (VerboseAsm) Streamer.AddComment("Range Start");
1159  Streamer.EmitSymbolValue(Frame.Function, Size);
1160 
1161  // Range Length
1162  const MCExpr *Range = MakeStartMinusEndExpr(Streamer, *Frame.Begin,
1163  *Frame.End, 0);
1164  if (VerboseAsm) Streamer.AddComment("Range Length");
1165  Streamer.EmitAbsValue(Range, 4);
1166 
1167  // Compact Encoding
1168  Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_udata4);
1169  if (VerboseAsm) Streamer.AddComment("Compact Unwind Encoding: 0x" +
1170  Twine::utohexstr(Encoding));
1171  Streamer.EmitIntValue(Encoding, Size);
1172 
1173  // Personality Function
1174  Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_absptr);
1175  if (VerboseAsm) Streamer.AddComment("Personality Function");
1176  if (!DwarfEHFrameOnly && Frame.Personality)
1177  Streamer.EmitSymbolValue(Frame.Personality, Size);
1178  else
1179  Streamer.EmitIntValue(0, Size); // No personality fn
1180 
1181  // LSDA
1182  Size = getSizeForEncoding(Streamer, Frame.LsdaEncoding);
1183  if (VerboseAsm) Streamer.AddComment("LSDA");
1184  if (!DwarfEHFrameOnly && Frame.Lsda)
1185  Streamer.EmitSymbolValue(Frame.Lsda, Size);
1186  else
1187  Streamer.EmitIntValue(0, Size); // No LSDA
1188 }
1189 
1190 const MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer,
1191  const MCSymbol *personality,
1192  unsigned personalityEncoding,
1193  const MCSymbol *lsda,
1194  bool IsSignalFrame,
1195  unsigned lsdaEncoding) {
1196  MCContext &context = streamer.getContext();
1197  const MCRegisterInfo *MRI = context.getRegisterInfo();
1198  const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
1199  bool verboseAsm = streamer.isVerboseAsm();
1200 
1201  MCSymbol *sectionStart;
1202  if (MOFI->isFunctionEHFrameSymbolPrivate() || !IsEH)
1203  sectionStart = context.CreateTempSymbol();
1204  else
1205  sectionStart = context.GetOrCreateSymbol(Twine("EH_frame") + Twine(CIENum));
1206 
1207  streamer.EmitLabel(sectionStart);
1208  CIENum++;
1209 
1210  MCSymbol *sectionEnd = context.CreateTempSymbol();
1211 
1212  // Length
1213  const MCExpr *Length = MakeStartMinusEndExpr(streamer, *sectionStart,
1214  *sectionEnd, 4);
1215  if (verboseAsm) streamer.AddComment("CIE Length");
1216  streamer.EmitAbsValue(Length, 4);
1217 
1218  // CIE ID
1219  unsigned CIE_ID = IsEH ? 0 : -1;
1220  if (verboseAsm) streamer.AddComment("CIE ID Tag");
1221  streamer.EmitIntValue(CIE_ID, 4);
1222 
1223  // Version
1224  if (verboseAsm) streamer.AddComment("DW_CIE_VERSION");
1225  streamer.EmitIntValue(dwarf::DW_CIE_VERSION, 1);
1226 
1227  // Augmentation String
1228  SmallString<8> Augmentation;
1229  if (IsEH) {
1230  if (verboseAsm) streamer.AddComment("CIE Augmentation");
1231  Augmentation += "z";
1232  if (personality)
1233  Augmentation += "P";
1234  if (lsda)
1235  Augmentation += "L";
1236  Augmentation += "R";
1237  if (IsSignalFrame)
1238  Augmentation += "S";
1239  streamer.EmitBytes(Augmentation.str());
1240  }
1241  streamer.EmitIntValue(0, 1);
1242 
1243  // Code Alignment Factor
1244  if (verboseAsm) streamer.AddComment("CIE Code Alignment Factor");
1245  streamer.EmitULEB128IntValue(context.getAsmInfo()->getMinInstAlignment());
1246 
1247  // Data Alignment Factor
1248  if (verboseAsm) streamer.AddComment("CIE Data Alignment Factor");
1249  streamer.EmitSLEB128IntValue(getDataAlignmentFactor(streamer));
1250 
1251  // Return Address Register
1252  if (verboseAsm) streamer.AddComment("CIE Return Address Column");
1253  streamer.EmitULEB128IntValue(MRI->getDwarfRegNum(MRI->getRARegister(), true));
1254 
1255  // Augmentation Data Length (optional)
1256 
1257  unsigned augmentationLength = 0;
1258  if (IsEH) {
1259  if (personality) {
1260  // Personality Encoding
1261  augmentationLength += 1;
1262  // Personality
1263  augmentationLength += getSizeForEncoding(streamer, personalityEncoding);
1264  }
1265  if (lsda)
1266  augmentationLength += 1;
1267  // Encoding of the FDE pointers
1268  augmentationLength += 1;
1269 
1270  if (verboseAsm) streamer.AddComment("Augmentation Size");
1271  streamer.EmitULEB128IntValue(augmentationLength);
1272 
1273  // Augmentation Data (optional)
1274  if (personality) {
1275  // Personality Encoding
1276  EmitEncodingByte(streamer, personalityEncoding,
1277  "Personality Encoding");
1278  // Personality
1279  if (verboseAsm) streamer.AddComment("Personality");
1280  EmitPersonality(streamer, *personality, personalityEncoding);
1281  }
1282 
1283  if (lsda)
1284  EmitEncodingByte(streamer, lsdaEncoding, "LSDA Encoding");
1285 
1286  // Encoding of the FDE pointers
1287  EmitEncodingByte(streamer, MOFI->getFDEEncoding(UsingCFI),
1288  "FDE Encoding");
1289  }
1290 
1291  // Initial Instructions
1292 
1293  const MCAsmInfo *MAI = context.getAsmInfo();
1294  const std::vector<MCCFIInstruction> &Instructions =
1295  MAI->getInitialFrameState();
1296  EmitCFIInstructions(streamer, Instructions, NULL);
1297 
1298  // Padding
1299  streamer.EmitValueToAlignment(IsEH ? 4 : MAI->getPointerSize());
1300 
1301  streamer.EmitLabel(sectionEnd);
1302  return *sectionStart;
1303 }
1304 
1305 MCSymbol *FrameEmitterImpl::EmitFDE(MCStreamer &streamer,
1306  const MCSymbol &cieStart,
1307  const MCDwarfFrameInfo &frame) {
1308  MCContext &context = streamer.getContext();
1309  MCSymbol *fdeStart = context.CreateTempSymbol();
1310  MCSymbol *fdeEnd = context.CreateTempSymbol();
1311  const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
1312  bool verboseAsm = streamer.isVerboseAsm();
1313 
1314  if (IsEH && frame.Function && !MOFI->isFunctionEHFrameSymbolPrivate()) {
1315  MCSymbol *EHSym =
1316  context.GetOrCreateSymbol(frame.Function->getName() + Twine(".eh"));
1317  streamer.EmitEHSymAttributes(frame.Function, EHSym);
1318  streamer.EmitLabel(EHSym);
1319  }
1320 
1321  // Length
1322  const MCExpr *Length = MakeStartMinusEndExpr(streamer, *fdeStart, *fdeEnd, 0);
1323  if (verboseAsm) streamer.AddComment("FDE Length");
1324  streamer.EmitAbsValue(Length, 4);
1325 
1326  streamer.EmitLabel(fdeStart);
1327 
1328  // CIE Pointer
1329  const MCAsmInfo *asmInfo = context.getAsmInfo();
1330  if (IsEH) {
1331  const MCExpr *offset = MakeStartMinusEndExpr(streamer, cieStart, *fdeStart,
1332  0);
1333  if (verboseAsm) streamer.AddComment("FDE CIE Offset");
1334  streamer.EmitAbsValue(offset, 4);
1335  } else if (!asmInfo->doesDwarfUseRelocationsAcrossSections()) {
1336  const MCExpr *offset = MakeStartMinusEndExpr(streamer, *SectionStart,
1337  cieStart, 0);
1338  streamer.EmitAbsValue(offset, 4);
1339  } else {
1340  streamer.EmitSymbolValue(&cieStart, 4);
1341  }
1342 
1343  // PC Begin
1344  unsigned PCEncoding = IsEH ? MOFI->getFDEEncoding(UsingCFI)
1346  unsigned PCSize = getSizeForEncoding(streamer, PCEncoding);
1347  EmitSymbol(streamer, *frame.Begin, PCEncoding, "FDE initial location");
1348 
1349  // PC Range
1350  const MCExpr *Range = MakeStartMinusEndExpr(streamer, *frame.Begin,
1351  *frame.End, 0);
1352  if (verboseAsm) streamer.AddComment("FDE address range");
1353  streamer.EmitAbsValue(Range, PCSize);
1354 
1355  if (IsEH) {
1356  // Augmentation Data Length
1357  unsigned augmentationLength = 0;
1358 
1359  if (frame.Lsda)
1360  augmentationLength += getSizeForEncoding(streamer, frame.LsdaEncoding);
1361 
1362  if (verboseAsm) streamer.AddComment("Augmentation size");
1363  streamer.EmitULEB128IntValue(augmentationLength);
1364 
1365  // Augmentation Data
1366  if (frame.Lsda)
1367  EmitSymbol(streamer, *frame.Lsda, frame.LsdaEncoding,
1368  "Language Specific Data Area");
1369  }
1370 
1371  // Call Frame Instructions
1372  EmitCFIInstructions(streamer, frame.Instructions, frame.Begin);
1373 
1374  // Padding
1375  streamer.EmitValueToAlignment(PCSize);
1376 
1377  return fdeEnd;
1378 }
1379 
1380 namespace {
1381  struct CIEKey {
1382  static const CIEKey getEmptyKey() { return CIEKey(0, 0, -1, false); }
1383  static const CIEKey getTombstoneKey() { return CIEKey(0, -1, 0, false); }
1384 
1385  CIEKey(const MCSymbol* Personality_, unsigned PersonalityEncoding_,
1386  unsigned LsdaEncoding_, bool IsSignalFrame_) :
1387  Personality(Personality_), PersonalityEncoding(PersonalityEncoding_),
1388  LsdaEncoding(LsdaEncoding_), IsSignalFrame(IsSignalFrame_) {
1389  }
1390  const MCSymbol* Personality;
1391  unsigned PersonalityEncoding;
1392  unsigned LsdaEncoding;
1393  bool IsSignalFrame;
1394  };
1395 }
1396 
1397 namespace llvm {
1398  template <>
1399  struct DenseMapInfo<CIEKey> {
1400  static CIEKey getEmptyKey() {
1401  return CIEKey::getEmptyKey();
1402  }
1403  static CIEKey getTombstoneKey() {
1404  return CIEKey::getTombstoneKey();
1405  }
1406  static unsigned getHashValue(const CIEKey &Key) {
1407  return static_cast<unsigned>(hash_combine(Key.Personality,
1408  Key.PersonalityEncoding,
1409  Key.LsdaEncoding,
1410  Key.IsSignalFrame));
1411  }
1412  static bool isEqual(const CIEKey &LHS,
1413  const CIEKey &RHS) {
1414  return LHS.Personality == RHS.Personality &&
1415  LHS.PersonalityEncoding == RHS.PersonalityEncoding &&
1416  LHS.LsdaEncoding == RHS.LsdaEncoding &&
1417  LHS.IsSignalFrame == RHS.IsSignalFrame;
1418  }
1419  };
1420 }
1421 
1423  bool UsingCFI, bool IsEH) {
1424  Streamer.generateCompactUnwindEncodings(MAB);
1425 
1426  MCContext &Context = Streamer.getContext();
1427  const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
1428  FrameEmitterImpl Emitter(UsingCFI, IsEH);
1429  ArrayRef<MCDwarfFrameInfo> FrameArray = Streamer.getFrameInfos();
1430 
1431  // Emit the compact unwind info if available.
1432  if (IsEH && MOFI->getCompactUnwindSection()) {
1433  bool SectionEmitted = false;
1434  for (unsigned i = 0, n = FrameArray.size(); i < n; ++i) {
1435  const MCDwarfFrameInfo &Frame = FrameArray[i];
1436  if (Frame.CompactUnwindEncoding == 0) continue;
1437  if (!SectionEmitted) {
1438  Streamer.SwitchSection(MOFI->getCompactUnwindSection());
1439  Streamer.EmitValueToAlignment(Context.getAsmInfo()->getPointerSize());
1440  SectionEmitted = true;
1441  }
1442  Emitter.EmitCompactUnwind(Streamer, Frame);
1443  }
1444  }
1445 
1446  const MCSection &Section =
1447  IsEH ? *const_cast<MCObjectFileInfo*>(MOFI)->getEHFrameSection() :
1448  *MOFI->getDwarfFrameSection();
1449  Streamer.SwitchSection(&Section);
1450  MCSymbol *SectionStart = Context.CreateTempSymbol();
1451  Streamer.EmitLabel(SectionStart);
1452  Emitter.setSectionStart(SectionStart);
1453 
1454  MCSymbol *FDEEnd = NULL;
1456 
1457  const MCSymbol *DummyDebugKey = NULL;
1458  for (unsigned i = 0, n = FrameArray.size(); i < n; ++i) {
1459  const MCDwarfFrameInfo &Frame = FrameArray[i];
1460  CIEKey Key(Frame.Personality, Frame.PersonalityEncoding,
1461  Frame.LsdaEncoding, Frame.IsSignalFrame);
1462  const MCSymbol *&CIEStart = IsEH ? CIEStarts[Key] : DummyDebugKey;
1463  if (!CIEStart)
1464  CIEStart = &Emitter.EmitCIE(Streamer, Frame.Personality,
1465  Frame.PersonalityEncoding, Frame.Lsda,
1466  Frame.IsSignalFrame,
1467  Frame.LsdaEncoding);
1468 
1469  FDEEnd = Emitter.EmitFDE(Streamer, *CIEStart, Frame);
1470 
1471  if (i != n - 1)
1472  Streamer.EmitLabel(FDEEnd);
1473  }
1474 
1475  Streamer.EmitValueToAlignment(Context.getAsmInfo()->getPointerSize());
1476  if (FDEEnd)
1477  Streamer.EmitLabel(FDEEnd);
1478 }
1479 
1481  uint64_t AddrDelta) {
1482  MCContext &Context = Streamer.getContext();
1483  SmallString<256> Tmp;
1484  raw_svector_ostream OS(Tmp);
1485  MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OS);
1486  Streamer.EmitBytes(OS.str());
1487 }
1488 
1490  uint64_t AddrDelta,
1491  raw_ostream &OS) {
1492  // Scale the address delta by the minimum instruction length.
1493  AddrDelta = ScaleAddrDelta(Context, AddrDelta);
1494 
1495  if (AddrDelta == 0) {
1496  } else if (isUIntN(6, AddrDelta)) {
1497  uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta;
1498  OS << Opcode;
1499  } else if (isUInt<8>(AddrDelta)) {
1500  OS << uint8_t(dwarf::DW_CFA_advance_loc1);
1501  OS << uint8_t(AddrDelta);
1502  } else if (isUInt<16>(AddrDelta)) {
1503  // FIXME: check what is the correct behavior on a big endian machine.
1504  OS << uint8_t(dwarf::DW_CFA_advance_loc2);
1505  OS << uint8_t( AddrDelta & 0xff);
1506  OS << uint8_t((AddrDelta >> 8) & 0xff);
1507  } else {
1508  // FIXME: check what is the correct behavior on a big endian machine.
1509  assert(isUInt<32>(AddrDelta));
1510  OS << uint8_t(dwarf::DW_CFA_advance_loc4);
1511  OS << uint8_t( AddrDelta & 0xff);
1512  OS << uint8_t((AddrDelta >> 8) & 0xff);
1513  OS << uint8_t((AddrDelta >> 16) & 0xff);
1514  OS << uint8_t((AddrDelta >> 24) & 0xff);
1515 
1516  }
1517 }
bool isUInt< 8 >(uint64_t x)
Definition: MathExtras.h:294
const MCSymbol * Function
Definition: MCDwarf.h:446
static void Emit(MCStreamer *MCOS, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
Definition: MCDwarf.cpp:355
unsigned getFileNumber() const
Definition: MCDwarf.h:268
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number. Returns -1 if there is no equivalent va...
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:175
static int getDataAlignmentFactor(MCStreamer &streamer)
Definition: MCDwarf.cpp:808
virtual void AddComment(const Twine &T)
Definition: MCStreamer.h:207
bool getLinkerRequiresNonEmptyDwarfLines() const
Definition: MCAsmInfo.h:402
const MCSection * getDwarfAbbrevSection() const
MCSymbol * getGenDwarfSectionStartSym()
Definition: MCContext.h:369
virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize)=0
MCSymbol * getGenDwarfSectionEndSym()
Definition: MCContext.h:373
static CIEKey getTombstoneKey()
Definition: MCDwarf.cpp:1403
#define DWARF2_FLAG_PROLOGUE_END
Definition: MCDwarf.h:95
void EmitSLEB128IntValue(int64_t Value)
Definition: MCStreamer.cpp:128
size_t size() const
size - Get the string size.
Definition: StringRef.h:113
static void EmitEncodingByte(MCStreamer &Streamer, unsigned Encoding, StringRef Prefix)
Definition: MCDwarf.cpp:898
static const MCConstantExpr * Create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:152
void addLineEntry(const MCLineEntry &LineEntry, unsigned CUID)
Definition: MCDwarf.h:190
const MCSection * getDwarfLineSection() const
SourceMgr SrcMgr
MCLineEntryCollection::const_iterator const_iterator
Definition: MCDwarf.h:196
#define DWARF2_LINE_BASE
Definition: MCDwarf.cpp:44
StringRef substr(size_t Start, size_t N=npos) const
Definition: StringRef.h:392
const MCLineEntryCollection & getMCLineEntries(unsigned CUID) const
Definition: MCDwarf.h:210
const DenseMap< unsigned, MCSymbol * > & getMCLineTableSymbols() const
Definition: MCContext.h:329
unsigned LsdaEncoding
Definition: MCDwarf.h:449
StringRef getDwarfDebugFlags()
Definition: MCContext.h:386
static void Emit(MCStreamer *MCOS, const MCSymbol *LineSectionSymbol)
Definition: MCDwarf.cpp:729
unsigned getRegister() const
Definition: MCDwarf.h:411
ArrayRef< MCDwarfFrameInfo > getFrameInfos() const
Definition: MCStreamer.h:179
MCSymbol * getMCLineTableSymbol(unsigned ID) const
Definition: MCContext.h:332
void print(raw_ostream &OS) const
print - Print the value to the stream OS.
Definition: MCDwarf.cpp:440
std::vector< MCCFIInstruction > Instructions
Definition: MCDwarf.h:447
static void Encode(MCContext &Context, int64_t LineDelta, uint64_t AddrDelta, raw_ostream &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
Definition: MCDwarf.cpp:365
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:121
int getOffset() const
Definition: MCDwarf.h:424
MCSymbol * GetOrCreateSymbol(StringRef Name)
Definition: MCContext.cpp:118
static void Make(MCStreamer *MCOS, const MCSection *Section)
Definition: MCDwarf.cpp:65
#define DWARF2_FLAG_IS_STMT
Definition: MCDwarf.h:93
StringRef getDwarfDebugProducer()
Definition: MCContext.h:389
MCSymbol * CreateTempSymbol()
Definition: MCContext.cpp:165
static void EmitAdvanceLoc(MCStreamer &Streamer, uint64_t AddrDelta)
Definition: MCDwarf.cpp:1480
#define llvm_unreachable(msg)
MCSectionSubPair getCurrentSection() const
Definition: MCStreamer.h:224
unsigned getLineNumber() const
Definition: MCDwarf.h:269
void ClearDwarfLocSeen()
Definition: MCContext.h:358
virtual void EmitBytes(StringRef Data)=0
MCSymbol * Begin
Definition: MCDwarf.h:442
const std::vector< MCCFIInstruction > & getInitialFrameState() const
Definition: MCAsmInfo.h:539
const MCSymbol * Lsda
Definition: MCDwarf.h:445
const std::vector< const MCSection * > & getMCLineSectionOrder() const
Definition: MCContext.h:316
virtual bool isVerboseAsm() const
Definition: MCStreamer.h:194
MCContext & getContext() const
Definition: MCStreamer.h:168
const std::vector< const MCGenDwarfLabelEntry * > & getMCGenDwarfLabelEntries() const
Definition: MCContext.h:378
const MCSection * getGenDwarfSection()
Definition: MCContext.h:367
format_object1< T > format(const char *Fmt, const T &Val)
Definition: Format.h:180
void SwitchSection(const MCSection *Section, const MCExpr *Subsection=0)
Definition: MCStreamer.h:284
static void EmitGenDwarfAbbrev(MCStreamer *MCOS)
Definition: MCDwarf.cpp:458
#define MAX_SPECIAL_ADDR_DELTA
Definition: MCDwarf.cpp:35
void addMCLineSection(const MCSection *Sec, MCLineSection *Line)
Definition: MCContext.h:319
void setGenDwarfSectionEndSym(MCSymbol *Sym)
Definition: MCContext.h:374
unsigned getDwarfCompileUnitID()
Definition: MCContext.h:323
void dump() const
dump - Print the value to stderr.
Definition: MCDwarf.cpp:445
unsigned getGenDwarfFileNumber()
Definition: MCContext.h:365
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Definition: MCStreamer.cpp:104
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:109
void EmitValue(const MCExpr *Value, unsigned Size)
Definition: MCStreamer.cpp:141
#define DWARF2_LINE_RANGE
Definition: MCDwarf.cpp:47
static const MCSymbolRefExpr * Create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:270
static unsigned getSizeForEncoding(MCStreamer &streamer, unsigned symbolEncoding)
Definition: MCDwarf.cpp:818
StringRef getName() const
getName - Get the base name of this MCDwarfFile.
Definition: MCDwarf.h:57
const MCSection * getCompactUnwindSection() const
const MCSection * getDwarfInfoSection() const
static void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form)
Definition: MCDwarf.cpp:451
bool isFunctionEHFrameSymbolPrivate() const
const SmallVectorImpl< StringRef > & getMCDwarfDirs(unsigned CUID=0)
Definition: MCContext.h:308
const DenseMap< const MCSection *, MCLineSection * > & getMCLineSections() const
Definition: MCContext.h:313
static const MCBinaryExpr * Create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.cpp:142
#define DWARF2_FLAG_EPILOGUE_BEGIN
Definition: MCDwarf.h:96
hash_code hash_combine(const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, const T5 &arg5, const T6 &arg6)
Definition: Hashing.h:674
static const MCSymbol * Emit(MCStreamer *MCOS)
Definition: MCDwarf.cpp:215
static void EmitGenDwarfAranges(MCStreamer *MCOS, const MCSymbol *InfoSectionSymbol)
Definition: MCDwarf.cpp:503
static const MCSymbol * EmitCU(MCStreamer *MCOS, unsigned ID)
Definition: MCDwarf.cpp:242
unsigned getFDEEncoding(bool CFI) const
#define DWARF2_FLAG_BASIC_BLOCK
Definition: MCDwarf.h:94
const MCDwarfLoc & getCurrentDwarfLoc()
Definition: MCContext.h:361
unsigned PersonalityEncoding
Definition: MCDwarf.h:448
virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol)
Definition: MCStreamer.cpp:197
static void EmitSymbol(MCStreamer &streamer, const MCSymbol &symbol, unsigned symbolEncoding, const char *comment=0)
Definition: MCDwarf.cpp:839
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)=0
void generateCompactUnwindEncodings(MCAsmBackend *MAB)
Definition: MCStreamer.cpp:83
#define DWARF2_LINE_OPCODE_BASE
Definition: MCDwarf.cpp:40
unsigned getPointerSize() const
getPointerSize - Get the pointer size in bytes.
Definition: MCAsmInfo.h:323
bool containEntriesForID(unsigned CUID) const
Definition: MCDwarf.h:206
OpType getOperation() const
Definition: MCDwarf.h:408
bool isDefined() const
Definition: MCSymbol.h:89
static void EmitDwarfLineTable(MCStreamer *MCOS, const MCSection *Section, const MCLineSection *LineSection, unsigned CUID)
Definition: MCDwarf.cpp:127
const StringRef getValues() const
Definition: MCDwarf.h:431
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:208
unsigned getMinInstAlignment() const
Definition: MCAsmInfo.h:408
static unsigned getHashValue(const CIEKey &Key)
Definition: MCDwarf.cpp:1406
virtual void EmitLabel(MCSymbol *Symbol)
Definition: MCStreamer.cpp:212
static bool isEqual(const CIEKey &LHS, const CIEKey &RHS)
Definition: MCDwarf.cpp:1412
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:374
unsigned getRegister2() const
Definition: MCDwarf.h:419
void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry *E)
Definition: MCContext.h:381
static void EncodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, raw_ostream &OS)
Definition: MCDwarf.cpp:1489
uint32_t CompactUnwindEncoding
Definition: MCDwarf.h:450
bool getDwarfLocSeen()
Definition: MCContext.h:360
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
Definition: Debug.cpp:101
void encodeSLEB128(int64_t Value, raw_ostream &OS)
Utility function to encode a SLEB128 value to an output stream.
Definition: LEB128.h:23
bool isUInt< 32 >(uint64_t x)
Definition: MathExtras.h:302
static CIEKey getEmptyKey()
Definition: MCDwarf.cpp:1400
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:270
unsigned FindLineNumber(SMLoc Loc, int BufferID=-1) const
Definition: SourceMgr.h:133
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition: MCSymbol.h:76
#define DWARF2_LINE_DEFAULT_IS_STMT
Definition: MCDwarf.h:91
const SmallVectorImpl< MCDwarfFile * > & getMCDwarfFiles(unsigned CUID=0)
Definition: MCContext.h:305
static uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta)
Definition: MCDwarf.cpp:49
const MCRegisterInfo * getRegisterInfo() const
Definition: MCContext.h:177
static void Emit(MCStreamer &streamer, MCAsmBackend *MAB, bool usingCFI, bool isEH)
Definition: MCDwarf.cpp:1422
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir This can be overridden by clients which want to cont...
Definition: MCContext.h:275
static const MCExpr * MakeStartMinusEndExpr(const MCStreamer &MCOS, const MCSymbol &Start, const MCSymbol &End, int IntVal)
Definition: MCDwarf.cpp:105
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:70
std::string getName(ID id, ArrayRef< Type * > Tys=None)
Definition: Function.cpp:400
static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol, unsigned symbolEncoding)
Definition: MCDwarf.cpp:851
static void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
Definition: MCDwarf.cpp:771
const MCSymbol * Personality
Definition: MCDwarf.h:444
virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, const MCSymbol *Label)
Definition: MCStreamer.h:605
bool isStackGrowthDirectionUp() const
isStackGrowthDirectionUp - True if target stack grow up.
Definition: MCAsmInfo.h:339
#define N
unsigned getCalleeSaveStackSlotSize() const
Definition: MCAsmInfo.h:329
void EmitAbsValue(const MCExpr *Value, unsigned Size)
Definition: MCStreamer.cpp:135
int FindBufferContainingLoc(SMLoc Loc) const
Definition: SourceMgr.cpp:76
void EmitULEB128IntValue(uint64_t Value, unsigned Padding=0)
Definition: MCStreamer.cpp:119
const MCSection * getDwarfARangesSection() const
static void EmitGenDwarfInfo(MCStreamer *MCOS, const MCSymbol *AbbrevSectionSymbol, const MCSymbol *LineSectionSymbol)
Definition: MCDwarf.cpp:573
MCGenDwarfLabelEntry(StringRef name, unsigned fileNumber, unsigned lineNumber, MCSymbol *label)
Definition: MCDwarf.h:262
const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:128
StringRef getName() const
Definition: MCDwarf.h:267
MCAsmBackend - Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:34
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:179
bool isUInt< 16 >(uint64_t x)
Definition: MathExtras.h:298
unsigned getCompactUnwindDwarfEHFrameOnly() const
void encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned Padding=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:38
Subtraction.
Definition: MCExpr.h:379
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size)
Definition: MCStreamer.cpp:145
const MCSection * getDwarfFrameSection() const
MCSymbol * getLabel() const
Definition: MCDwarf.h:270
const MCRegisterInfo & MRI
unsigned getRARegister() const
This method should return the register where the return address can be found.
Represents a location in source code.
Definition: SMLoc.h:23
bool isUIntN(unsigned N, uint64_t x)
Definition: MathExtras.h:315
MCSymbol * getLabel() const
Definition: MCDwarf.h:409
bool doesDwarfUseRelocationsAcrossSections() const
Definition: MCAsmInfo.h:528
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110