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/BinaryFormat/XCOFF.h" 17 #include "llvm/MC/MCSection.h" 18 #include "llvm/MC/MCSymbolXCOFF.h" 19 20 namespace llvm { 21 22 // This class represents an XCOFF `Control Section`, more commonly referred to 23 // as a csect. A csect represents the smallest possible unit of data/code which 24 // will be relocated as a single block. A csect can either be: 25 // 1) Initialized: The Type will be XTY_SD, and the symbols inside the csect 26 // will have a label definition representing their offset within the csect. 27 // 2) Uninitialized: The Type will be XTY_CM, it will contain a single symbol, 28 // and may not contain label definitions. 29 // 3) An external reference providing a symbol table entry for a symbol 30 // contained in another XCOFF object file. External reference csects are not 31 // implemented yet. 32 class MCSectionXCOFF final : public MCSection { 33 friend class MCContext; 34 35 XCOFF::StorageMappingClass MappingClass; 36 XCOFF::SymbolType Type; 37 MCSymbolXCOFF *const QualName; 38 StringRef SymbolTableName; 39 bool MultiSymbolsAllowed; 40 static constexpr unsigned DefaultAlignVal = 4; 41 MCSectionXCOFF(StringRef Name,XCOFF::StorageMappingClass SMC,XCOFF::SymbolType ST,SectionKind K,MCSymbolXCOFF * QualName,MCSymbol * Begin,StringRef SymbolTableName,bool MultiSymbolsAllowed)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), MappingClass(SMC), Type(ST), 47 QualName(QualName), SymbolTableName(SymbolTableName), 48 MultiSymbolsAllowed(MultiSymbolsAllowed) { 49 assert((ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) && 50 "Invalid or unhandled type for csect."); 51 assert(QualName != nullptr && "QualName is needed."); 52 QualName->setRepresentedCsect(this); 53 QualName->setStorageClass(XCOFF::C_HIDEXT); 54 // A csect is 4 byte aligned by default, except for undefined symbol csects. 55 if (Type != XCOFF::XTY_ER) 56 setAlignment(Align(DefaultAlignVal)); 57 } 58 59 void printCsectDirective(raw_ostream &OS) const; 60 61 public: 62 ~MCSectionXCOFF(); 63 classof(const MCSection * S)64 static bool classof(const MCSection *S) { 65 return S->getVariant() == SV_XCOFF; 66 } 67 getMappingClass()68 XCOFF::StorageMappingClass getMappingClass() const { return MappingClass; } getStorageClass()69 XCOFF::StorageClass getStorageClass() const { 70 return QualName->getStorageClass(); 71 } getCSectType()72 XCOFF::SymbolType getCSectType() const { return Type; } getQualNameSymbol()73 MCSymbolXCOFF *getQualNameSymbol() const { return QualName; } 74 75 void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, 76 raw_ostream &OS, 77 const MCExpr *Subsection) const override; 78 bool UseCodeAlign() const override; 79 bool isVirtualSection() const override; getSymbolTableName()80 StringRef getSymbolTableName() const { return SymbolTableName; } isMultiSymbolsAllowed()81 bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; } 82 }; 83 84 } // end namespace llvm 85 86 #endif 87