MCSectionXCOFF.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. Optional<XCOFF::CsectProperties> CsectProp;
  36. MCSymbolXCOFF *const QualName;
  37. StringRef SymbolTableName;
  38. Optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags;
  39. bool MultiSymbolsAllowed;
  40. static constexpr unsigned DefaultAlignVal = 4;
  41. MCSectionXCOFF(StringRef Name, XCOFF::StorageMappingClass SMC,
  42. XCOFF::SymbolType ST, SectionKind K, MCSymbolXCOFF *QualName,
  43. MCSymbol *Begin, StringRef SymbolTableName,
  44. bool MultiSymbolsAllowed)
  45. : MCSection(SV_XCOFF, Name, K, Begin),
  46. CsectProp(XCOFF::CsectProperties(SMC, ST)), QualName(QualName),
  47. SymbolTableName(SymbolTableName), DwarfSubtypeFlags(None),
  48. MultiSymbolsAllowed(MultiSymbolsAllowed) {
  49. assert(
  50. (ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
  51. "Invalid or unhandled type for csect.");
  52. assert(QualName != nullptr && "QualName is needed.");
  53. if (SMC == XCOFF::XMC_UL)
  54. assert((ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
  55. "Invalid csect type for storage mapping class XCOFF::XMC_UL");
  56. QualName->setRepresentedCsect(this);
  57. QualName->setStorageClass(XCOFF::C_HIDEXT);
  58. // A csect is 4 byte aligned by default, except for undefined symbol csects.
  59. if (ST != XCOFF::XTY_ER)
  60. setAlignment(Align(DefaultAlignVal));
  61. }
  62. MCSectionXCOFF(StringRef Name, SectionKind K, MCSymbolXCOFF *QualName,
  63. XCOFF::DwarfSectionSubtypeFlags DwarfSubtypeFlags,
  64. MCSymbol *Begin, StringRef SymbolTableName,
  65. bool MultiSymbolsAllowed)
  66. : MCSection(SV_XCOFF, Name, K, Begin), QualName(QualName),
  67. SymbolTableName(SymbolTableName), DwarfSubtypeFlags(DwarfSubtypeFlags),
  68. MultiSymbolsAllowed(MultiSymbolsAllowed) {
  69. assert(QualName != nullptr && "QualName is needed.");
  70. // FIXME: use a more meaningful name for non csect sections.
  71. QualName->setRepresentedCsect(this);
  72. // Set default alignment 4 for all non csect sections for now.
  73. // FIXME: set different alignments according to section types.
  74. setAlignment(Align(DefaultAlignVal));
  75. }
  76. void printCsectDirective(raw_ostream &OS) const;
  77. public:
  78. ~MCSectionXCOFF();
  79. static bool classof(const MCSection *S) {
  80. return S->getVariant() == SV_XCOFF;
  81. }
  82. XCOFF::StorageMappingClass getMappingClass() const {
  83. assert(isCsect() && "Only csect section has mapping class property!");
  84. return CsectProp->MappingClass;
  85. }
  86. XCOFF::StorageClass getStorageClass() const {
  87. return QualName->getStorageClass();
  88. }
  89. XCOFF::SymbolType getCSectType() const {
  90. assert(isCsect() && "Only csect section has symbol type property!");
  91. return CsectProp->Type;
  92. }
  93. MCSymbolXCOFF *getQualNameSymbol() const { return QualName; }
  94. void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
  95. raw_ostream &OS,
  96. const MCExpr *Subsection) const override;
  97. bool UseCodeAlign() const override;
  98. bool isVirtualSection() const override;
  99. StringRef getSymbolTableName() const { return SymbolTableName; }
  100. bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; }
  101. bool isCsect() const { return CsectProp.hasValue(); }
  102. bool isDwarfSect() const { return DwarfSubtypeFlags.hasValue(); }
  103. Optional<XCOFF::DwarfSectionSubtypeFlags> getDwarfSubtypeFlags() const {
  104. return DwarfSubtypeFlags;
  105. }
  106. };
  107. } // end namespace llvm
  108. #endif
  109. #ifdef __GNUC__
  110. #pragma GCC diagnostic pop
  111. #endif