blob: aa39dff0718051392e715306a0e77e0bf2ad1130 [file] [log] [blame]
Andrew Walbran3d2c1972020-04-07 12:24:26 +01001//===- 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
Andrew Walbran3d2c1972020-04-07 12:24:26 +010016#include "llvm/BinaryFormat/XCOFF.h"
17#include "llvm/MC/MCSection.h"
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020018#include "llvm/MC/MCSymbolXCOFF.h"
Andrew Walbran3d2c1972020-04-07 12:24:26 +010019
20namespace llvm {
21
Andrew Walbran3d2c1972020-04-07 12:24:26 +010022// 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
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020024// 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.
Andrew Walbran3d2c1972020-04-07 12:24:26 +010032class MCSectionXCOFF final : public MCSection {
33 friend class MCContext;
34
Andrew Walbran3d2c1972020-04-07 12:24:26 +010035 XCOFF::StorageMappingClass MappingClass;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020036 XCOFF::SymbolType Type;
37 MCSymbolXCOFF *const QualName;
38 StringRef SymbolTableName;
39 bool MultiSymbolsAllowed;
40 static constexpr unsigned DefaultAlignVal = 4;
Andrew Walbran3d2c1972020-04-07 12:24:26 +010041
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020042 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;
Andrew Walbran3d2c1972020-04-07 12:24:26 +010060
61public:
62 ~MCSectionXCOFF();
63
64 static bool classof(const MCSection *S) {
65 return S->getVariant() == SV_XCOFF;
66 }
67
Andrew Walbran3d2c1972020-04-07 12:24:26 +010068 XCOFF::StorageMappingClass getMappingClass() const { return MappingClass; }
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020069 XCOFF::StorageClass getStorageClass() const {
70 return QualName->getStorageClass();
71 }
72 XCOFF::SymbolType getCSectType() const { return Type; }
73 MCSymbolXCOFF *getQualNameSymbol() const { return QualName; }
Andrew Walbran3d2c1972020-04-07 12:24:26 +010074
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;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020080 StringRef getSymbolTableName() const { return SymbolTableName; }
81 bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; }
Andrew Walbran3d2c1972020-04-07 12:24:26 +010082};
83
84} // end namespace llvm
85
86#endif