LLVM  8.0.1
MCWin64EH.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCWin64EH.cpp - MCWin64EH 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/MCWin64EH.h"
11 #include "llvm/ADT/Twine.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCSectionCOFF.h"
17 #include "llvm/MC/MCStreamer.h"
18 #include "llvm/MC/MCSymbol.h"
19 #include "llvm/Support/Win64EH.h"
20 
21 using namespace llvm;
22 
23 // NOTE: All relocations generated here are 4-byte image-relative.
24 
25 static uint8_t CountOfUnwindCodes(std::vector<WinEH::Instruction> &Insns) {
26  uint8_t Count = 0;
27  for (const auto &I : Insns) {
28  switch (static_cast<Win64EH::UnwindOpcodes>(I.Operation)) {
29  default:
30  llvm_unreachable("Unsupported unwind code");
35  Count += 1;
36  break;
39  Count += 2;
40  break;
43  Count += 3;
44  break;
46  Count += (I.Offset > 512 * 1024 - 8) ? 3 : 2;
47  break;
48  }
49  }
50  return Count;
51 }
52 
53 static void EmitAbsDifference(MCStreamer &Streamer, const MCSymbol *LHS,
54  const MCSymbol *RHS) {
55  MCContext &Context = Streamer.getContext();
56  const MCExpr *Diff =
58  MCSymbolRefExpr::create(RHS, Context), Context);
59  Streamer.EmitValue(Diff, 1);
60 }
61 
62 static void EmitUnwindCode(MCStreamer &streamer, const MCSymbol *begin,
63  WinEH::Instruction &inst) {
64  uint8_t b2;
65  uint16_t w;
66  b2 = (inst.Operation & 0x0F);
67  switch (static_cast<Win64EH::UnwindOpcodes>(inst.Operation)) {
68  default:
69  llvm_unreachable("Unsupported unwind code");
71  EmitAbsDifference(streamer, inst.Label, begin);
72  b2 |= (inst.Register & 0x0F) << 4;
73  streamer.EmitIntValue(b2, 1);
74  break;
76  EmitAbsDifference(streamer, inst.Label, begin);
77  if (inst.Offset > 512 * 1024 - 8) {
78  b2 |= 0x10;
79  streamer.EmitIntValue(b2, 1);
80  w = inst.Offset & 0xFFF8;
81  streamer.EmitIntValue(w, 2);
82  w = inst.Offset >> 16;
83  } else {
84  streamer.EmitIntValue(b2, 1);
85  w = inst.Offset >> 3;
86  }
87  streamer.EmitIntValue(w, 2);
88  break;
90  b2 |= (((inst.Offset - 8) >> 3) & 0x0F) << 4;
91  EmitAbsDifference(streamer, inst.Label, begin);
92  streamer.EmitIntValue(b2, 1);
93  break;
95  EmitAbsDifference(streamer, inst.Label, begin);
96  streamer.EmitIntValue(b2, 1);
97  break;
100  b2 |= (inst.Register & 0x0F) << 4;
101  EmitAbsDifference(streamer, inst.Label, begin);
102  streamer.EmitIntValue(b2, 1);
103  w = inst.Offset >> 3;
105  w >>= 1;
106  streamer.EmitIntValue(w, 2);
107  break;
110  b2 |= (inst.Register & 0x0F) << 4;
111  EmitAbsDifference(streamer, inst.Label, begin);
112  streamer.EmitIntValue(b2, 1);
114  w = inst.Offset & 0xFFF0;
115  else
116  w = inst.Offset & 0xFFF8;
117  streamer.EmitIntValue(w, 2);
118  w = inst.Offset >> 16;
119  streamer.EmitIntValue(w, 2);
120  break;
122  if (inst.Offset == 1)
123  b2 |= 0x10;
124  EmitAbsDifference(streamer, inst.Label, begin);
125  streamer.EmitIntValue(b2, 1);
126  break;
127  }
128 }
129 
130 static void EmitSymbolRefWithOfs(MCStreamer &streamer,
131  const MCSymbol *Base,
132  const MCSymbol *Other) {
133  MCContext &Context = streamer.getContext();
134  const MCSymbolRefExpr *BaseRef = MCSymbolRefExpr::create(Base, Context);
135  const MCSymbolRefExpr *OtherRef = MCSymbolRefExpr::create(Other, Context);
136  const MCExpr *Ofs = MCBinaryExpr::createSub(OtherRef, BaseRef, Context);
137  const MCSymbolRefExpr *BaseRefRel = MCSymbolRefExpr::create(Base,
139  Context);
140  streamer.EmitValue(MCBinaryExpr::createAdd(BaseRefRel, Ofs, Context), 4);
141 }
142 
143 static void EmitRuntimeFunction(MCStreamer &streamer,
144  const WinEH::FrameInfo *info) {
145  MCContext &context = streamer.getContext();
146 
147  streamer.EmitValueToAlignment(4);
148  EmitSymbolRefWithOfs(streamer, info->Function, info->Begin);
149  EmitSymbolRefWithOfs(streamer, info->Function, info->End);
152  context), 4);
153 }
154 
155 static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info) {
156  // If this UNWIND_INFO already has a symbol, it's already been emitted.
157  if (info->Symbol)
158  return;
159 
160  MCContext &context = streamer.getContext();
161  MCSymbol *Label = context.createTempSymbol();
162 
163  streamer.EmitValueToAlignment(4);
164  streamer.EmitLabel(Label);
165  info->Symbol = Label;
166 
167  // Upper 3 bits are the version number (currently 1).
168  uint8_t flags = 0x01;
169  if (info->ChainedParent)
170  flags |= Win64EH::UNW_ChainInfo << 3;
171  else {
172  if (info->HandlesUnwind)
173  flags |= Win64EH::UNW_TerminateHandler << 3;
174  if (info->HandlesExceptions)
175  flags |= Win64EH::UNW_ExceptionHandler << 3;
176  }
177  streamer.EmitIntValue(flags, 1);
178 
179  if (info->PrologEnd)
180  EmitAbsDifference(streamer, info->PrologEnd, info->Begin);
181  else
182  streamer.EmitIntValue(0, 1);
183 
184  uint8_t numCodes = CountOfUnwindCodes(info->Instructions);
185  streamer.EmitIntValue(numCodes, 1);
186 
187  uint8_t frame = 0;
188  if (info->LastFrameInst >= 0) {
189  WinEH::Instruction &frameInst = info->Instructions[info->LastFrameInst];
190  assert(frameInst.Operation == Win64EH::UOP_SetFPReg);
191  frame = (frameInst.Register & 0x0F) | (frameInst.Offset & 0xF0);
192  }
193  streamer.EmitIntValue(frame, 1);
194 
195  // Emit unwind instructions (in reverse order).
196  uint8_t numInst = info->Instructions.size();
197  for (uint8_t c = 0; c < numInst; ++c) {
198  WinEH::Instruction inst = info->Instructions.back();
199  info->Instructions.pop_back();
200  EmitUnwindCode(streamer, info->Begin, inst);
201  }
202 
203  // For alignment purposes, the instruction array will always have an even
204  // number of entries, with the final entry potentially unused (in which case
205  // the array will be one longer than indicated by the count of unwind codes
206  // field).
207  if (numCodes & 1) {
208  streamer.EmitIntValue(0, 2);
209  }
210 
211  if (flags & (Win64EH::UNW_ChainInfo << 3))
212  EmitRuntimeFunction(streamer, info->ChainedParent);
213  else if (flags &
217  context), 4);
218  else if (numCodes == 0) {
219  // The minimum size of an UNWIND_INFO struct is 8 bytes. If we're not
220  // a chained unwind info, if there is no handler, and if there are fewer
221  // than 2 slots used in the unwind code array, we have to pad to 8 bytes.
222  streamer.EmitIntValue(0, 4);
223  }
224 }
225 
227  // Emit the unwind info structs first.
228  for (const auto &CFI : Streamer.getWinFrameInfos()) {
229  MCSection *XData = Streamer.getAssociatedXDataSection(CFI->TextSection);
230  Streamer.SwitchSection(XData);
231  ::EmitUnwindInfo(Streamer, CFI.get());
232  }
233 
234  // Now emit RUNTIME_FUNCTION entries.
235  for (const auto &CFI : Streamer.getWinFrameInfos()) {
236  MCSection *PData = Streamer.getAssociatedPDataSection(CFI->TextSection);
237  Streamer.SwitchSection(PData);
238  EmitRuntimeFunction(Streamer, CFI.get());
239  }
240 }
241 
243  MCStreamer &Streamer, WinEH::FrameInfo *info) const {
244  // Switch sections (the static function above is meant to be called from
245  // here and from Emit().
246  MCSection *XData = Streamer.getAssociatedXDataSection(info->TextSection);
247  Streamer.SwitchSection(XData);
248 
249  ::EmitUnwindInfo(Streamer, info);
250 }
251 
252 static int64_t GetAbsDifference(MCStreamer &Streamer, const MCSymbol *LHS,
253  const MCSymbol *RHS) {
254  MCContext &Context = Streamer.getContext();
255  const MCExpr *Diff =
257  MCSymbolRefExpr::create(RHS, Context), Context);
258  MCObjectStreamer *OS = (MCObjectStreamer *)(&Streamer);
259  int64_t value;
260  Diff->evaluateAsAbsolute(value, OS->getAssembler());
261  return value;
262 }
263 
264 static uint32_t
265 ARM64CountOfUnwindCodes(const std::vector<WinEH::Instruction> &Insns) {
266  uint32_t Count = 0;
267  for (const auto &I : Insns) {
268  switch (static_cast<Win64EH::UnwindOpcodes>(I.Operation)) {
269  default:
270  llvm_unreachable("Unsupported ARM64 unwind code");
272  Count += 1;
273  break;
275  Count += 2;
276  break;
278  Count += 4;
279  break;
281  Count += 1;
282  break;
284  Count += 1;
285  break;
287  Count += 2;
288  break;
290  Count += 2;
291  break;
293  Count += 2;
294  break;
296  Count += 2;
297  break;
299  Count += 2;
300  break;
302  Count += 2;
303  break;
305  Count += 2;
306  break;
308  Count += 2;
309  break;
310  case Win64EH::UOP_SetFP:
311  Count += 1;
312  break;
313  case Win64EH::UOP_AddFP:
314  Count += 2;
315  break;
316  case Win64EH::UOP_Nop:
317  Count += 1;
318  break;
319  case Win64EH::UOP_End:
320  Count += 1;
321  break;
322  }
323  }
324  return Count;
325 }
326 
327 // Unwind opcode encodings and restrictions are documented at
328 // https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling
329 static void ARM64EmitUnwindCode(MCStreamer &streamer, const MCSymbol *begin,
330  WinEH::Instruction &inst) {
331  uint8_t b, reg;
332  switch (static_cast<Win64EH::UnwindOpcodes>(inst.Operation)) {
333  default:
334  llvm_unreachable("Unsupported ARM64 unwind code");
336  b = (inst.Offset >> 4) & 0x1F;
337  streamer.EmitIntValue(b, 1);
338  break;
340  uint16_t hw = (inst.Offset >> 4) & 0x7FF;
341  b = 0xC0;
342  b |= (hw >> 8);
343  streamer.EmitIntValue(b, 1);
344  b = hw & 0xFF;
345  streamer.EmitIntValue(b, 1);
346  break;
347  }
349  uint32_t w;
350  b = 0xE0;
351  streamer.EmitIntValue(b, 1);
352  w = inst.Offset >> 4;
353  b = (w & 0x00FF0000) >> 16;
354  streamer.EmitIntValue(b, 1);
355  b = (w & 0x0000FF00) >> 8;
356  streamer.EmitIntValue(b, 1);
357  b = w & 0x000000FF;
358  streamer.EmitIntValue(b, 1);
359  break;
360  }
361  case Win64EH::UOP_SetFP:
362  b = 0xE1;
363  streamer.EmitIntValue(b, 1);
364  break;
365  case Win64EH::UOP_AddFP:
366  b = 0xE2;
367  streamer.EmitIntValue(b, 1);
368  b = (inst.Offset >> 3);
369  streamer.EmitIntValue(b, 1);
370  break;
371  case Win64EH::UOP_Nop:
372  b = 0xE3;
373  streamer.EmitIntValue(b, 1);
374  break;
376  b = 0x80;
377  b |= ((inst.Offset - 1) >> 3) & 0x3F;
378  streamer.EmitIntValue(b, 1);
379  break;
381  b = 0x40;
382  b |= (inst.Offset >> 3) & 0x3F;
383  streamer.EmitIntValue(b, 1);
384  break;
386  assert(inst.Register >= 19 && "Saved reg must be >= 19");
387  reg = inst.Register - 19;
388  b = 0xD0 | ((reg & 0xC) >> 2);
389  streamer.EmitIntValue(b, 1);
390  b = ((reg & 0x3) << 6) | (inst.Offset >> 3);
391  streamer.EmitIntValue(b, 1);
392  break;
394  assert(inst.Register >= 19 && "Saved reg must be >= 19");
395  reg = inst.Register - 19;
396  b = 0xD4 | ((reg & 0x8) >> 3);
397  streamer.EmitIntValue(b, 1);
398  b = ((reg & 0x7) << 5) | ((inst.Offset >> 3) - 1);
399  streamer.EmitIntValue(b, 1);
400  break;
402  assert(inst.Register >= 19 && "Saved registers must be >= 19");
403  reg = inst.Register - 19;
404  b = 0xC8 | ((reg & 0xC) >> 2);
405  streamer.EmitIntValue(b, 1);
406  b = ((reg & 0x3) << 6) | (inst.Offset >> 3);
407  streamer.EmitIntValue(b, 1);
408  break;
410  assert(inst.Register >= 19 && "Saved registers must be >= 19");
411  reg = inst.Register - 19;
412  b = 0xCC | ((reg & 0xC) >> 2);
413  streamer.EmitIntValue(b, 1);
414  b = ((reg & 0x3) << 6) | ((inst.Offset >> 3) - 1);
415  streamer.EmitIntValue(b, 1);
416  break;
418  assert(inst.Register >= 8 && "Saved dreg must be >= 8");
419  reg = inst.Register - 8;
420  b = 0xDC | ((reg & 0x4) >> 2);
421  streamer.EmitIntValue(b, 1);
422  b = ((reg & 0x3) << 6) | (inst.Offset >> 3);
423  streamer.EmitIntValue(b, 1);
424  break;
426  assert(inst.Register >= 8 && "Saved dreg must be >= 8");
427  reg = inst.Register - 8;
428  b = 0xDE;
429  streamer.EmitIntValue(b, 1);
430  b = ((reg & 0x7) << 5) | ((inst.Offset >> 3) - 1);
431  streamer.EmitIntValue(b, 1);
432  break;
434  assert(inst.Register >= 8 && "Saved dregs must be >= 8");
435  reg = inst.Register - 8;
436  b = 0xD8 | ((reg & 0x4) >> 2);
437  streamer.EmitIntValue(b, 1);
438  b = ((reg & 0x3) << 6) | (inst.Offset >> 3);
439  streamer.EmitIntValue(b, 1);
440  break;
442  assert(inst.Register >= 8 && "Saved dregs must be >= 8");
443  reg = inst.Register - 8;
444  b = 0xDA | ((reg & 0x4) >> 2);
445  streamer.EmitIntValue(b, 1);
446  b = ((reg & 0x3) << 6) | ((inst.Offset >> 3) - 1);
447  streamer.EmitIntValue(b, 1);
448  break;
449  case Win64EH::UOP_End:
450  b = 0xE4;
451  streamer.EmitIntValue(b, 1);
452  break;
453  }
454 }
455 
456 // Returns the epilog symbol of an epilog with the exact same unwind code
457 // sequence, if it exists. Otherwise, returns nulltpr.
458 // EpilogInstrs - Unwind codes for the current epilog.
459 // Epilogs - Epilogs that potentialy match the current epilog.
460 static MCSymbol*
461 FindMatchingEpilog(const std::vector<WinEH::Instruction>& EpilogInstrs,
462  const std::vector<MCSymbol *>& Epilogs,
463  const WinEH::FrameInfo *info) {
464  for (auto *EpilogStart : Epilogs) {
465  auto InstrsIter = info->EpilogMap.find(EpilogStart);
466  assert(InstrsIter != info->EpilogMap.end() &&
467  "Epilog not found in EpilogMap");
468  const auto &Instrs = InstrsIter->second;
469 
470  if (Instrs.size() != EpilogInstrs.size())
471  continue;
472 
473  bool Match = true;
474  for (unsigned i = 0; i < Instrs.size(); ++i)
475  if (Instrs[i].Operation != EpilogInstrs[i].Operation ||
476  Instrs[i].Offset != EpilogInstrs[i].Offset ||
477  Instrs[i].Register != EpilogInstrs[i].Register) {
478  Match = false;
479  break;
480  }
481 
482  if (Match)
483  return EpilogStart;
484  }
485  return nullptr;
486 }
487 
488 // Populate the .xdata section. The format of .xdata on ARM64 is documented at
489 // https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling
491  // If this UNWIND_INFO already has a symbol, it's already been emitted.
492  if (info->Symbol)
493  return;
494 
495  MCContext &context = streamer.getContext();
496  MCSymbol *Label = context.createTempSymbol();
497 
498  streamer.EmitValueToAlignment(4);
499  streamer.EmitLabel(Label);
500  info->Symbol = Label;
501 
502  uint32_t FuncLength = 0x0;
503  if (info->FuncletOrFuncEnd)
504  FuncLength = (uint32_t)GetAbsDifference(streamer, info->FuncletOrFuncEnd,
505  info->Begin);
506  FuncLength /= 4;
507  uint32_t PrologCodeBytes = ARM64CountOfUnwindCodes(info->Instructions);
508  uint32_t TotalCodeBytes = PrologCodeBytes;
509 
510  // Process epilogs.
512  // Epilogs processed so far.
513  std::vector<MCSymbol *> AddedEpilogs;
514 
515  for (auto &I : info->EpilogMap) {
516  MCSymbol *EpilogStart = I.first;
517  auto &EpilogInstrs = I.second;
518  uint32_t CodeBytes = ARM64CountOfUnwindCodes(EpilogInstrs);
519 
520  MCSymbol* MatchingEpilog =
521  FindMatchingEpilog(EpilogInstrs, AddedEpilogs, info);
522  if (MatchingEpilog) {
523  assert(EpilogInfo.find(MatchingEpilog) != EpilogInfo.end() &&
524  "Duplicate epilog not found");
525  EpilogInfo[EpilogStart] = EpilogInfo.lookup(MatchingEpilog);
526  // Clear the unwind codes in the EpilogMap, so that they don't get output
527  // in the logic below.
528  EpilogInstrs.clear();
529  } else {
530  EpilogInfo[EpilogStart] = TotalCodeBytes;
531  TotalCodeBytes += CodeBytes;
532  AddedEpilogs.push_back(EpilogStart);
533  }
534  }
535 
536  // Code Words, Epilog count, E, X, Vers, Function Length
537  uint32_t row1 = 0x0;
538  uint32_t CodeWords = TotalCodeBytes / 4;
539  uint32_t CodeWordsMod = TotalCodeBytes % 4;
540  if (CodeWordsMod)
541  CodeWords++;
542  uint32_t EpilogCount = info->EpilogMap.size();
543  bool ExtensionWord = EpilogCount > 31 || TotalCodeBytes > 124;
544  if (!ExtensionWord) {
545  row1 |= (EpilogCount & 0x1F) << 22;
546  row1 |= (CodeWords & 0x1F) << 27;
547  }
548  // E is always 0 right now, TODO: packed epilog setup
549  if (info->HandlesExceptions) // X
550  row1 |= 1 << 20;
551  row1 |= FuncLength & 0x3FFFF;
552  streamer.EmitIntValue(row1, 4);
553 
554  // Extended Code Words, Extended Epilog Count
555  if (ExtensionWord) {
556  // FIXME: We should be able to split unwind info into multiple sections.
557  // FIXME: We should share epilog codes across epilogs, where possible,
558  // which would make this issue show up less frequently.
559  if (CodeWords > 0xFF || EpilogCount > 0xFFFF)
560  report_fatal_error("SEH unwind data splitting not yet implemented");
561  uint32_t row2 = 0x0;
562  row2 |= (CodeWords & 0xFF) << 16;
563  row2 |= (EpilogCount & 0xFFFF);
564  streamer.EmitIntValue(row2, 4);
565  }
566 
567  // Epilog Start Index, Epilog Start Offset
568  for (auto &I : EpilogInfo) {
569  MCSymbol *EpilogStart = I.first;
570  uint32_t EpilogIndex = I.second;
571  uint32_t EpilogOffset =
572  (uint32_t)GetAbsDifference(streamer, EpilogStart, info->Begin);
573  if (EpilogOffset)
574  EpilogOffset /= 4;
575  uint32_t row3 = EpilogOffset;
576  row3 |= (EpilogIndex & 0x3FF) << 22;
577  streamer.EmitIntValue(row3, 4);
578  }
579 
580  // Emit prolog unwind instructions (in reverse order).
581  uint8_t numInst = info->Instructions.size();
582  for (uint8_t c = 0; c < numInst; ++c) {
583  WinEH::Instruction inst = info->Instructions.back();
584  info->Instructions.pop_back();
585  ARM64EmitUnwindCode(streamer, info->Begin, inst);
586  }
587 
588  // Emit epilog unwind instructions
589  for (auto &I : info->EpilogMap) {
590  auto &EpilogInstrs = I.second;
591  for (uint32_t i = 0; i < EpilogInstrs.size(); i++) {
592  WinEH::Instruction inst = EpilogInstrs[i];
593  ARM64EmitUnwindCode(streamer, info->Begin, inst);
594  }
595  }
596 
597  int32_t BytesMod = CodeWords * 4 - TotalCodeBytes;
598  assert(BytesMod >= 0);
599  for (int i = 0; i < BytesMod; i++)
600  streamer.EmitIntValue(0xE3, 1);
601 
602  if (info->HandlesExceptions)
603  streamer.EmitValue(
606  4);
607 }
608 
609 static void ARM64EmitRuntimeFunction(MCStreamer &streamer,
610  const WinEH::FrameInfo *info) {
611  MCContext &context = streamer.getContext();
612 
613  streamer.EmitValueToAlignment(4);
614  EmitSymbolRefWithOfs(streamer, info->Function, info->Begin);
617  context),
618  4);
619 }
620 
622  // Emit the unwind info structs first.
623  for (const auto &CFI : Streamer.getWinFrameInfos()) {
624  MCSection *XData = Streamer.getAssociatedXDataSection(CFI->TextSection);
625  Streamer.SwitchSection(XData);
626  ARM64EmitUnwindInfo(Streamer, CFI.get());
627  }
628 
629  // Now emit RUNTIME_FUNCTION entries.
630  for (const auto &CFI : Streamer.getWinFrameInfos()) {
631  MCSection *PData = Streamer.getAssociatedPDataSection(CFI->TextSection);
632  Streamer.SwitchSection(PData);
633  ARM64EmitRuntimeFunction(Streamer, CFI.get());
634  }
635 }
636 
638  MCStreamer &Streamer, WinEH::FrameInfo *info) const {
639  // Switch sections (the static function above is meant to be called from
640  // here and from Emit().
641  MCSection *XData = Streamer.getAssociatedXDataSection(info->TextSection);
642  Streamer.SwitchSection(XData);
643  ARM64EmitUnwindInfo(Streamer, info);
644 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
LLVMContext & Context
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:250
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:323
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
static void ARM64EmitRuntimeFunction(MCStreamer &streamer, const WinEH::FrameInfo *info)
Definition: MCWin64EH.cpp:609
const MCSymbol * End
Definition: MCWinEH.h:34
static void EmitUnwindCode(MCStreamer &streamer, const MCSymbol *begin, WinEH::Instruction &inst)
Definition: MCWin64EH.cpp:62
This class implements a map that also provides access to all stored values in a deterministic order...
Definition: MapVector.h:38
std::vector< Instruction > Instructions
Definition: MCWinEH.h:47
static void ARM64EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info)
Definition: MCWin64EH.cpp:490
MCContext & getContext() const
Definition: MCStreamer.h:251
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
static void EmitAbsDifference(MCStreamer &Streamer, const MCSymbol *LHS, const MCSymbol *RHS)
Definition: MCWin64EH.cpp:53
ArrayRef< std::unique_ptr< WinEH::FrameInfo > > getWinFrameInfos() const
Definition: MCStreamer.h:278
Context object for machine code objects.
Definition: MCContext.h:63
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:546
Streaming object file generation interface.
UNW_ExceptionHandler - Specifies that this function has an exception handler.
Definition: Win64EH.h:76
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:461
iterator find(const KeyT &Key)
Definition: MapVector.h:148
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Definition: MCStreamer.cpp:124
void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:155
static uint32_t ARM64CountOfUnwindCodes(const std::vector< WinEH::Instruction > &Insns)
Definition: MCWin64EH.cpp:265
static void EmitSymbolRefWithOfs(MCStreamer &streamer, const MCSymbol *Base, const MCSymbol *Other)
Definition: MCWin64EH.cpp:130
Streaming machine code generation interface.
Definition: MCStreamer.h:189
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:217
const FrameInfo * ChainedParent
Definition: MCWinEH.h:46
static void EmitRuntimeFunction(MCStreamer &streamer, const WinEH::FrameInfo *info)
Definition: MCWin64EH.cpp:143
PowerPC Reduce CR logical Operation
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
MCAssembler & getAssembler()
MCSection * getAssociatedPDataSection(const MCSection *TextSec)
Get the .pdata section used for the given section.
Definition: MCStreamer.cpp:748
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void EmitUnwindInfo(MCStreamer &Streamer, WinEH::FrameInfo *FI) const override
Definition: MCWin64EH.cpp:242
const MCSymbol * Symbol
Definition: MCWinEH.h:39
lazy value info
const MCSymbol * Begin
Definition: MCWinEH.h:33
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const MCSymbol * PrologEnd
Definition: MCWinEH.h:38
const MCSection * TextSection
Definition: MCWinEH.h:40
const MCSymbol * Label
Definition: MCWinEH.h:23
void Emit(MCStreamer &Streamer) const override
This emits the unwind info sections (.pdata and .xdata in PE/COFF).
Definition: MCWin64EH.cpp:621
Promote Memory to Register
Definition: Mem2Reg.cpp:110
MapVector< MCSymbol *, std::vector< Instruction > > EpilogMap
Definition: MCWinEH.h:48
const MCSymbol * Function
Definition: MCWinEH.h:37
ValueT lookup(const KeyT &Key) const
Definition: MapVector.h:111
static MCSymbol * FindMatchingEpilog(const std::vector< WinEH::Instruction > &EpilogInstrs, const std::vector< MCSymbol *> &Epilogs, const WinEH::FrameInfo *info)
Definition: MCWin64EH.cpp:461
UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to another one.
Definition: Win64EH.h:82
const MCSymbol * FuncletOrFuncEnd
Definition: MCWinEH.h:35
#define I(x, y, z)
Definition: MD5.cpp:58
static uint8_t CountOfUnwindCodes(std::vector< WinEH::Instruction > &Insns)
Definition: MCWin64EH.cpp:25
iterator end()
Definition: MapVector.h:72
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static int64_t GetAbsDifference(MCStreamer &Streamer, const MCSymbol *LHS, const MCSymbol *RHS)
Definition: MCWin64EH.cpp:252
static void ARM64EmitUnwindCode(MCStreamer &streamer, const MCSymbol *begin, WinEH::Instruction &inst)
Definition: MCWin64EH.cpp:329
void EmitUnwindInfo(MCStreamer &Streamer, WinEH::FrameInfo *FI) const override
Definition: MCWin64EH.cpp:637
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:347
static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info)
Definition: MCWin64EH.cpp:155
const MCSymbol * ExceptionHandler
Definition: MCWinEH.h:36
UNW_TerminateHandler - Specifies that this function has a termination handler.
Definition: Win64EH.h:79
void Emit(MCStreamer &Streamer) const override
This emits the unwind info sections (.pdata and .xdata in PE/COFF).
Definition: MCWin64EH.cpp:226
MCSection * getAssociatedXDataSection(const MCSection *TextSec)
Get the .xdata section used for the given section.
Definition: MCStreamer.cpp:754