MCSectionXCOFF.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- MCSectionXCOFF.h - XCOFF 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 MCSectionXCOFF class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_MC_MCSECTIONXCOFF_H
  18. #define LLVM_MC_MCSECTIONXCOFF_H
  19. #include "llvm/BinaryFormat/XCOFF.h"
  20. #include "llvm/MC/MCSection.h"
  21. #include "llvm/MC/MCSymbolXCOFF.h"
  22. namespace llvm {
  23. // This class represents an XCOFF `Control Section`, more commonly referred to
  24. // as a csect. A csect represents the smallest possible unit of data/code which
  25. // will be relocated as a single block. A csect can either be:
  26. // 1) Initialized: The Type will be XTY_SD, and the symbols inside the csect
  27. // will have a label definition representing their offset within the csect.
  28. // 2) Uninitialized: The Type will be XTY_CM, it will contain a single symbol,
  29. // and may not contain label definitions.
  30. // 3) An external reference providing a symbol table entry for a symbol
  31. // contained in another XCOFF object file. External reference csects are not
  32. // implemented yet.
  33. class MCSectionXCOFF final : public MCSection {
  34. friend class MCContext;
  35. std::optional<XCOFF::CsectProperties> CsectProp;
  36. MCSymbolXCOFF *const QualName;
  37. StringRef SymbolTableName;
  38. std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags;
  39. bool MultiSymbolsAllowed;
  40. static constexpr unsigned DefaultAlignVal = 4;
  41. static constexpr unsigned DefaultTextAlignVal = 32;
  42. MCSectionXCOFF(StringRef Name, XCOFF::StorageMappingClass SMC,
  43. XCOFF::SymbolType ST, SectionKind K, MCSymbolXCOFF *QualName,
  44. MCSymbol *Begin, StringRef SymbolTableName,
  45. bool MultiSymbolsAllowed)
  46. : MCSection(SV_XCOFF, Name, K, Begin),
  47. CsectProp(XCOFF::CsectProperties(SMC, ST)), QualName(QualName),
  48. SymbolTableName(SymbolTableName), DwarfSubtypeFlags(std::nullopt),
  49. MultiSymbolsAllowed(MultiSymbolsAllowed) {
  50. assert(
  51. (ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
  52. "Invalid or unhandled type for csect.");
  53. assert(QualName != nullptr && "QualName is needed.");
  54. if (SMC == XCOFF::XMC_UL)
  55. assert((ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
  56. "Invalid csect type for storage mapping class XCOFF::XMC_UL");
  57. QualName->setRepresentedCsect(this);
  58. QualName->setStorageClass(XCOFF::C_HIDEXT);
  59. if (ST != XCOFF::XTY_ER) {
  60. // For a csect for program code, set the alignment to 32 bytes by default.
  61. // For other csects, set the alignment to 4 bytes by default.
  62. if (SMC == XCOFF::XMC_PR)
  63. setAlignment(Align(DefaultTextAlignVal));
  64. else
  65. setAlignment(Align(DefaultAlignVal));
  66. }
  67. }
  68. MCSectionXCOFF(StringRef Name, SectionKind K, MCSymbolXCOFF *QualName,
  69. XCOFF::DwarfSectionSubtypeFlags DwarfSubtypeFlags,
  70. MCSymbol *Begin, StringRef SymbolTableName,
  71. bool MultiSymbolsAllowed)
  72. : MCSection(SV_XCOFF, Name, K, Begin), QualName(QualName),
  73. SymbolTableName(SymbolTableName), DwarfSubtypeFlags(DwarfSubtypeFlags),
  74. MultiSymbolsAllowed(MultiSymbolsAllowed) {
  75. assert(QualName != nullptr && "QualName is needed.");
  76. // FIXME: use a more meaningful name for non csect sections.
  77. QualName->setRepresentedCsect(this);
  78. // Use default text alignment as the alignment for DWARF sections.
  79. setAlignment(Align(DefaultTextAlignVal));
  80. }
  81. void printCsectDirective(raw_ostream &OS) const;
  82. public:
  83. ~MCSectionXCOFF();
  84. static bool classof(const MCSection *S) {
  85. return S->getVariant() == SV_XCOFF;
  86. }
  87. XCOFF::StorageMappingClass getMappingClass() const {
  88. assert(isCsect() && "Only csect section has mapping class property!");
  89. return CsectProp->MappingClass;
  90. }
  91. XCOFF::StorageClass getStorageClass() const {
  92. return QualName->getStorageClass();
  93. }
  94. XCOFF::VisibilityType getVisibilityType() const {
  95. return QualName->getVisibilityType();
  96. }
  97. XCOFF::SymbolType getCSectType() const {
  98. assert(isCsect() && "Only csect section has symbol type property!");
  99. return CsectProp->Type;
  100. }
  101. MCSymbolXCOFF *getQualNameSymbol() const { return QualName; }
  102. void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
  103. raw_ostream &OS,
  104. const MCExpr *Subsection) const override;
  105. bool useCodeAlign() const override;
  106. bool isVirtualSection() const override;
  107. StringRef getSymbolTableName() const { return SymbolTableName; }
  108. bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; }
  109. bool isCsect() const { return CsectProp.has_value(); }
  110. bool isDwarfSect() const { return DwarfSubtypeFlags.has_value(); }
  111. std::optional<XCOFF::DwarfSectionSubtypeFlags> getDwarfSubtypeFlags() const {
  112. return DwarfSubtypeFlags;
  113. }
  114. std::optional<XCOFF::CsectProperties> getCsectProp() const {
  115. return CsectProp;
  116. }
  117. };
  118. } // end namespace llvm
  119. #endif
  120. #ifdef __GNUC__
  121. #pragma GCC diagnostic pop
  122. #endif