MCSectionCOFF.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //===- MCSectionCOFF.h - COFF Machine Code Sections -------------*- 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 declares the MCSectionCOFF class.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_MC_MCSECTIONCOFF_H
  13. #define LLVM_MC_MCSECTIONCOFF_H
  14. #include "llvm/ADT/StringRef.h"
  15. #include "llvm/MC/MCSection.h"
  16. #include "llvm/MC/SectionKind.h"
  17. #include <cassert>
  18. namespace llvm {
  19. class MCSymbol;
  20. /// This represents a section on Windows
  21. class MCSectionCOFF final : public MCSection {
  22. // FIXME: The following fields should not be mutable, but are for now so the
  23. // asm parser can honor the .linkonce directive.
  24. /// This is the Characteristics field of a section, drawn from the enums
  25. /// below.
  26. mutable unsigned Characteristics;
  27. /// The unique IDs used with the .pdata and .xdata sections created internally
  28. /// by the assembler. This ID is used to ensure that for every .text section,
  29. /// there is exactly one .pdata and one .xdata section, which is required by
  30. /// the Microsoft incremental linker. This data is mutable because this ID is
  31. /// not notionally part of the section.
  32. mutable unsigned WinCFISectionID = ~0U;
  33. /// The COMDAT symbol of this section. Only valid if this is a COMDAT section.
  34. /// Two COMDAT sections are merged if they have the same COMDAT symbol.
  35. MCSymbol *COMDATSymbol;
  36. /// This is the Selection field for the section symbol, if it is a COMDAT
  37. /// section (Characteristics & IMAGE_SCN_LNK_COMDAT) != 0
  38. mutable int Selection;
  39. private:
  40. friend class MCContext;
  41. // The storage of Name is owned by MCContext's COFFUniquingMap.
  42. MCSectionCOFF(StringRef Name, unsigned Characteristics,
  43. MCSymbol *COMDATSymbol, int Selection, SectionKind K,
  44. MCSymbol *Begin)
  45. : MCSection(SV_COFF, Name, K, Begin), Characteristics(Characteristics),
  46. COMDATSymbol(COMDATSymbol), Selection(Selection) {
  47. assert((Characteristics & 0x00F00000) == 0 &&
  48. "alignment must not be set upon section creation");
  49. }
  50. public:
  51. /// Decides whether a '.section' directive should be printed before the
  52. /// section name
  53. bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
  54. unsigned getCharacteristics() const { return Characteristics; }
  55. MCSymbol *getCOMDATSymbol() const { return COMDATSymbol; }
  56. int getSelection() const { return Selection; }
  57. void setSelection(int Selection) const;
  58. void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
  59. raw_ostream &OS,
  60. const MCExpr *Subsection) const override;
  61. bool UseCodeAlign() const override;
  62. bool isVirtualSection() const override;
  63. StringRef getVirtualSectionKind() const override;
  64. unsigned getOrAssignWinCFISectionID(unsigned *NextID) const {
  65. if (WinCFISectionID == ~0U)
  66. WinCFISectionID = (*NextID)++;
  67. return WinCFISectionID;
  68. }
  69. static bool isImplicitlyDiscardable(StringRef Name) {
  70. return Name.startswith(".debug");
  71. }
  72. static bool classof(const MCSection *S) { return S->getVariant() == SV_COFF; }
  73. };
  74. } // end namespace llvm
  75. #endif // LLVM_MC_MCSECTIONCOFF_H