LLVM 22.0.0git
MCSectionXCOFF.h
Go to the documentation of this file.
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
17#include "llvm/MC/MCSection.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 friend class MCAsmInfoXCOFF;
35
36 std::optional<XCOFF::CsectProperties> CsectProp;
37 MCSymbolXCOFF *const QualName;
38 StringRef SymbolTableName;
39 std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags;
40 bool MultiSymbolsAllowed;
41 SectionKind Kind;
42 static constexpr unsigned DefaultAlignVal = 4;
43 static constexpr unsigned DefaultTextAlignVal = 32;
44
45 // XTY_CM sections are virtual except for toc-data symbols.
48 MCSymbol *Begin, StringRef SymbolTableName,
49 bool MultiSymbolsAllowed)
50 : MCSection(Name, K.isText(),
51 /*IsVirtual=*/ST == XCOFF::XTY_CM && SMC != XCOFF::XMC_TD,
52 Begin),
53 CsectProp(XCOFF::CsectProperties(SMC, ST)), QualName(QualName),
54 SymbolTableName(SymbolTableName), DwarfSubtypeFlags(std::nullopt),
55 MultiSymbolsAllowed(MultiSymbolsAllowed), Kind(K) {
56 assert(
57 (ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
58 "Invalid or unhandled type for csect.");
59 assert(QualName != nullptr && "QualName is needed.");
60 if (SMC == XCOFF::XMC_UL)
61 assert((ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
62 "Invalid csect type for storage mapping class XCOFF::XMC_UL");
63
64 QualName->setRepresentedCsect(this);
66 if (ST != XCOFF::XTY_ER) {
67 // For a csect for program code, set the alignment to 32 bytes by default.
68 // For other csects, set the alignment to 4 bytes by default.
69 if (SMC == XCOFF::XMC_PR)
70 setAlignment(Align(DefaultTextAlignVal));
71 else
72 setAlignment(Align(DefaultAlignVal));
73 }
74 }
75
76 // DWARF sections are never virtual.
77 MCSectionXCOFF(StringRef Name, SectionKind K, MCSymbolXCOFF *QualName,
78 XCOFF::DwarfSectionSubtypeFlags DwarfSubtypeFlags,
79 MCSymbol *Begin, StringRef SymbolTableName,
80 bool MultiSymbolsAllowed)
81 : MCSection(Name, K.isText(), /*IsVirtual=*/false, Begin),
82 QualName(QualName), SymbolTableName(SymbolTableName),
83 DwarfSubtypeFlags(DwarfSubtypeFlags),
84 MultiSymbolsAllowed(MultiSymbolsAllowed), Kind(K) {
85 assert(QualName != nullptr && "QualName is needed.");
86
87 // FIXME: use a more meaningful name for non csect sections.
88 QualName->setRepresentedCsect(this);
89
90 // Use default text alignment as the alignment for DWARF sections.
91 setAlignment(Align(DefaultTextAlignVal));
92 }
93
94 void printCsectDirective(raw_ostream &OS) const;
95
96public:
98
100 assert(isCsect() && "Only csect section has mapping class property!");
101 return CsectProp->MappingClass;
102 }
104 return QualName->getStorageClass();
105 }
107 return QualName->getVisibilityType();
108 }
110 assert(isCsect() && "Only csect section has symbol type property!");
111 return CsectProp->Type;
112 }
113 MCSymbolXCOFF *getQualNameSymbol() const { return QualName; }
114
115 StringRef getSymbolTableName() const { return SymbolTableName; }
116 void setSymbolTableName(StringRef STN) { SymbolTableName = STN; }
117 bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; }
118 bool isCsect() const { return CsectProp.has_value(); }
119 bool isDwarfSect() const { return DwarfSubtypeFlags.has_value(); }
120 std::optional<XCOFF::DwarfSectionSubtypeFlags> getDwarfSubtypeFlags() const {
121 return DwarfSubtypeFlags;
122 }
123 std::optional<XCOFF::CsectProperties> getCsectProp() const {
124 return CsectProp;
125 }
126 SectionKind getKind() const { return Kind; }
127};
128
129} // end namespace llvm
130
131#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t Align
raw_pwrite_stream & OS
Context object for machine code objects.
Definition: MCContext.h:83
std::optional< XCOFF::CsectProperties > getCsectProp() const
bool isMultiSymbolsAllowed() const
StringRef getSymbolTableName() const
XCOFF::VisibilityType getVisibilityType() const
std::optional< XCOFF::DwarfSectionSubtypeFlags > getDwarfSubtypeFlags() const
void setSymbolTableName(StringRef STN)
XCOFF::StorageClass getStorageClass() const
SectionKind getKind() const
XCOFF::StorageMappingClass getMappingClass() const
MCSymbolXCOFF * getQualNameSymbol() const
bool isDwarfSect() const
XCOFF::SymbolType getCSectType() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:496
void setAlignment(Align Value)
Definition: MCSection.h:580
bool isText() const
Definition: MCSection.h:566
StringRef Name
Definition: MCSection.h:557
void setRepresentedCsect(MCSectionXCOFF *C)
void setStorageClass(XCOFF::StorageClass SC)
Definition: MCSymbolXCOFF.h:42
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
DwarfSectionSubtypeFlags
Values for defining the section subtype of sections of type STYP_DWARF as they would appear in the (s...
Definition: XCOFF.h:155
VisibilityType
Values for visibility as they would appear when encoded in the high 4 bits of the 16-bit unsigned n_t...
Definition: XCOFF.h:252
StorageClass
Definition: XCOFF.h:171
@ C_HIDEXT
Definition: XCOFF.h:207
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:104
@ XMC_TD
Scalar data item in the TOC.
Definition: XCOFF.h:121
@ XMC_UL
Uninitialized thread-local variable.
Definition: XCOFF.h:128
@ XMC_PR
Program Code.
Definition: XCOFF.h:106
@ XTY_CM
Common csect definition. For uninitialized storage.
Definition: XCOFF.h:246
@ XTY_SD
Csect definition for initialized storage.
Definition: XCOFF.h:243
@ XTY_ER
External reference.
Definition: XCOFF.h:242
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856