WinException.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //===-- WinException.h - Windows Exception Handling ----------*- C++ -*--===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file contains support for writing windows exception info into asm files.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_WIN64EXCEPTION_H
  13. #define LLVM_LIB_CODEGEN_ASMPRINTER_WIN64EXCEPTION_H
  14. #include "EHStreamer.h"
  15. #include <vector>
  16. namespace llvm {
  17. class GlobalValue;
  18. class MachineFunction;
  19. class MCExpr;
  20. class MCSection;
  21. struct WinEHFuncInfo;
  22. class LLVM_LIBRARY_VISIBILITY WinException : public EHStreamer {
  23. /// Per-function flag to indicate if personality info should be emitted.
  24. bool shouldEmitPersonality = false;
  25. /// Per-function flag to indicate if the LSDA should be emitted.
  26. bool shouldEmitLSDA = false;
  27. /// Per-function flag to indicate if frame moves info should be emitted.
  28. bool shouldEmitMoves = false;
  29. /// True if this is a 64-bit target and we should use image relative offsets.
  30. bool useImageRel32 = false;
  31. /// True if we are generating exception handling on Windows for ARM64.
  32. bool isAArch64 = false;
  33. /// True if we are generating exception handling on Windows for ARM (Thumb).
  34. bool isThumb = false;
  35. /// Pointer to the current funclet entry BB.
  36. const MachineBasicBlock *CurrentFuncletEntry = nullptr;
  37. /// The section of the last funclet start.
  38. MCSection *CurrentFuncletTextSection = nullptr;
  39. /// The list of symbols to add to the ehcont section
  40. std::vector<const MCSymbol *> EHContTargets;
  41. void emitCSpecificHandlerTable(const MachineFunction *MF);
  42. void emitSEHActionsForRange(const WinEHFuncInfo &FuncInfo,
  43. const MCSymbol *BeginLabel,
  44. const MCSymbol *EndLabel, int State);
  45. /// Emit the EH table data for 32-bit and 64-bit functions using
  46. /// the __CxxFrameHandler3 personality.
  47. void emitCXXFrameHandler3Table(const MachineFunction *MF);
  48. /// Emit the EH table data for _except_handler3 and _except_handler4
  49. /// personality functions. These are only used on 32-bit and do not use CFI
  50. /// tables.
  51. void emitExceptHandlerTable(const MachineFunction *MF);
  52. void emitCLRExceptionTable(const MachineFunction *MF);
  53. void computeIP2StateTable(
  54. const MachineFunction *MF, const WinEHFuncInfo &FuncInfo,
  55. SmallVectorImpl<std::pair<const MCExpr *, int>> &IPToStateTable);
  56. /// Emits the label used with llvm.eh.recoverfp, which is used by
  57. /// outlined funclets.
  58. void emitEHRegistrationOffsetLabel(const WinEHFuncInfo &FuncInfo,
  59. StringRef FLinkageName);
  60. const MCExpr *create32bitRef(const MCSymbol *Value);
  61. const MCExpr *create32bitRef(const GlobalValue *GV);
  62. const MCExpr *getLabel(const MCSymbol *Label);
  63. const MCExpr *getLabelPlusOne(const MCSymbol *Label);
  64. const MCExpr *getOffset(const MCSymbol *OffsetOf, const MCSymbol *OffsetFrom);
  65. const MCExpr *getOffsetPlusOne(const MCSymbol *OffsetOf,
  66. const MCSymbol *OffsetFrom);
  67. /// Gets the offset that we should use in a table for a stack object with the
  68. /// given index. For targets using CFI (Win64, etc), this is relative to the
  69. /// established SP at the end of the prologue. For targets without CFI (Win32
  70. /// only), it is relative to the frame pointer.
  71. int getFrameIndexOffset(int FrameIndex, const WinEHFuncInfo &FuncInfo);
  72. void endFuncletImpl();
  73. public:
  74. //===--------------------------------------------------------------------===//
  75. // Main entry points.
  76. //
  77. WinException(AsmPrinter *A);
  78. ~WinException() override;
  79. /// Emit all exception information that should come after the content.
  80. void endModule() override;
  81. /// Gather pre-function exception information. Assumes being emitted
  82. /// immediately after the function entry point.
  83. void beginFunction(const MachineFunction *MF) override;
  84. void markFunctionEnd() override;
  85. /// Gather and emit post-function exception information.
  86. void endFunction(const MachineFunction *) override;
  87. /// Emit target-specific EH funclet machinery.
  88. void beginFunclet(const MachineBasicBlock &MBB, MCSymbol *Sym) override;
  89. void endFunclet() override;
  90. };
  91. }
  92. #endif