MCSectionCOFF.h 3.5 KB

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