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 20namespace 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. 32class MCSectionXCOFF final : public MCSection { 33 friend class MCContext; 34 35 XCOFF::StorageMappingClass MappingClass; 36 XCOFF::SymbolType Type; 37 XCOFF::StorageClass StorageClass; 38 MCSymbolXCOFF *const QualName; 39 StringRef SymbolTableName; 40 static constexpr unsigned DefaultAlignVal = 4; 41 42 MCSectionXCOFF(StringRef Name, XCOFF::StorageMappingClass SMC, 43 XCOFF::SymbolType ST, XCOFF::StorageClass SC, SectionKind K, 44 MCSymbolXCOFF *QualName, MCSymbol *Begin, 45 StringRef SymbolTableName) 46 : MCSection(SV_XCOFF, Name, K, Begin), MappingClass(SMC), Type(ST), 47 StorageClass(SC), QualName(QualName), SymbolTableName(SymbolTableName) { 48 assert((ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) && 49 "Invalid or unhandled type for csect."); 50 assert(QualName != nullptr && "QualName is needed."); 51 QualName->setStorageClass(SC); 52 QualName->setRepresentedCsect(this); 53 // A csect is 4 byte aligned by default, except for undefined symbol csects. 54 if (Type != XCOFF::XTY_ER) 55 setAlignment(Align(DefaultAlignVal)); 56 } 57 58 void printCsectDirective(raw_ostream &OS) const; 59 60public: 61 ~MCSectionXCOFF(); 62 63 static bool classof(const MCSection *S) { 64 return S->getVariant() == SV_XCOFF; 65 } 66 67 XCOFF::StorageMappingClass getMappingClass() const { return MappingClass; } 68 XCOFF::StorageClass getStorageClass() const { return StorageClass; } 69 XCOFF::SymbolType getCSectType() const { return Type; } 70 MCSymbolXCOFF *getQualNameSymbol() const { return QualName; } 71 72 void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, 73 raw_ostream &OS, 74 const MCExpr *Subsection) const override; 75 bool UseCodeAlign() const override; 76 bool isVirtualSection() const override; 77 StringRef getSymbolTableName() const { return SymbolTableName; } 78}; 79 80} // end namespace llvm 81 82#endif 83