1 //===- MCSectionXCOFF.h - XCOFF 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 MCSectionXCOFF class. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_MC_MCSECTIONXCOFF_H 14 #define LLVM_MC_MCSECTIONXCOFF_H 15 16 #include "llvm/ADT/Twine.h" 17 #include "llvm/BinaryFormat/XCOFF.h" 18 #include "llvm/MC/MCSection.h" 19 #include "llvm/MC/MCSymbolXCOFF.h" 20 21 namespace llvm { 22 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 36 StringRef Name; 37 XCOFF::StorageMappingClass MappingClass; 38 XCOFF::SymbolType Type; 39 XCOFF::StorageClass StorageClass; 40 MCSymbolXCOFF *const QualName; 41 MCSectionXCOFF(StringRef Section,XCOFF::StorageMappingClass SMC,XCOFF::SymbolType ST,XCOFF::StorageClass SC,SectionKind K,MCSymbolXCOFF * QualName,MCSymbol * Begin)42 MCSectionXCOFF(StringRef Section, XCOFF::StorageMappingClass SMC, 43 XCOFF::SymbolType ST, XCOFF::StorageClass SC, SectionKind K, 44 MCSymbolXCOFF *QualName, MCSymbol *Begin) 45 : MCSection(SV_XCOFF, K, Begin), Name(Section), MappingClass(SMC), 46 Type(ST), StorageClass(SC), QualName(QualName) { 47 assert((ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) && 48 "Invalid or unhandled type for csect."); 49 assert(QualName != nullptr && "QualName is needed."); 50 QualName->setStorageClass(SC); 51 QualName->setContainingCsect(this); 52 } 53 54 public: 55 ~MCSectionXCOFF(); 56 classof(const MCSection * S)57 static bool classof(const MCSection *S) { 58 return S->getVariant() == SV_XCOFF; 59 } 60 getSectionName()61 StringRef getSectionName() const { return Name; } getMappingClass()62 XCOFF::StorageMappingClass getMappingClass() const { return MappingClass; } getStorageClass()63 XCOFF::StorageClass getStorageClass() const { return StorageClass; } getCSectType()64 XCOFF::SymbolType getCSectType() const { return Type; } getQualNameSymbol()65 MCSymbolXCOFF *getQualNameSymbol() const { return QualName; } 66 67 void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, 68 raw_ostream &OS, 69 const MCExpr *Subsection) const override; 70 bool UseCodeAlign() const override; 71 bool isVirtualSection() const override; 72 }; 73 74 } // end namespace llvm 75 76 #endif 77