LLVM 24.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
35 std::optional<XCOFF::CsectProperties> CsectProp;
36 MCSymbolXCOFF *const QualName;
37 StringRef SymbolTableName;
38 std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags;
39 bool MultiSymbolsAllowed;
40 SectionKind Kind;
41 static constexpr unsigned DefaultAlignVal = 4;
42 static constexpr unsigned DefaultTextAlignVal = 32;
43
44 // XTY_CM sections are virtual except for toc-data symbols.
45 MCSectionXCOFF(StringRef Name, XCOFF::StorageMappingClass SMC,
47 MCSymbol *Begin, StringRef SymbolTableName,
48 bool MultiSymbolsAllowed)
50 /*IsVirtual=*/ST == XCOFF::XTY_CM && SMC != XCOFF::XMC_TD,
51 Begin),
52 CsectProp(XCOFF::CsectProperties(SMC, ST)), QualName(QualName),
53 SymbolTableName(SymbolTableName), DwarfSubtypeFlags(std::nullopt),
54 MultiSymbolsAllowed(MultiSymbolsAllowed), Kind(K) {
55 assert(
56 (ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
57 "Invalid or unhandled type for csect.");
58 assert(QualName != nullptr && "QualName is needed.");
59 if (SMC == XCOFF::XMC_UL)
60 assert((ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
61 "Invalid csect type for storage mapping class XCOFF::XMC_UL");
62
63 QualName->setRepresentedCsect(this);
64 QualName->setStorageClass(XCOFF::C_HIDEXT);
65 if (ST != XCOFF::XTY_ER) {
66 // For a csect for program code, set the alignment to 32 bytes by default.
67 // For other csects, set the alignment to 4 bytes by default.
68 if (SMC == XCOFF::XMC_PR)
69 setAlignment(Align(DefaultTextAlignVal));
70 else
71 setAlignment(Align(DefaultAlignVal));
72 }
73 }
74
75 // DWARF sections are never virtual.
76 MCSectionXCOFF(StringRef Name, SectionKind K, MCSymbolXCOFF *QualName,
77 XCOFF::DwarfSectionSubtypeFlags DwarfSubtypeFlags,
78 MCSymbol *Begin, StringRef SymbolTableName,
79 bool MultiSymbolsAllowed)
80 : MCSection(Name, K.isText(), /*IsVirtual=*/false, Begin),
81 QualName(QualName), SymbolTableName(SymbolTableName),
82 DwarfSubtypeFlags(DwarfSubtypeFlags),
83 MultiSymbolsAllowed(MultiSymbolsAllowed), Kind(K) {
84 assert(QualName != nullptr && "QualName is needed.");
85
86 // FIXME: use a more meaningful name for non csect sections.
87 QualName->setRepresentedCsect(this);
88
89 // Use default text alignment as the alignment for DWARF sections.
90 setAlignment(Align(DefaultTextAlignVal));
91 }
92
93public:
95
97 assert(isCsect() && "Only csect section has mapping class property!");
98 return CsectProp->MappingClass;
99 }
101 return QualName->getStorageClass();
102 }
104 return QualName->getVisibilityType();
105 }
107 assert(isCsect() && "Only csect section has symbol type property!");
108 return CsectProp->Type;
109 }
110 MCSymbolXCOFF *getQualNameSymbol() const { return QualName; }
111
112 StringRef getSymbolTableName() const { return SymbolTableName; }
113 void setSymbolTableName(StringRef STN) { SymbolTableName = STN; }
114 bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; }
115 bool isCsect() const { return CsectProp.has_value(); }
116 bool isDwarfSect() const { return DwarfSubtypeFlags.has_value(); }
117 std::optional<XCOFF::DwarfSectionSubtypeFlags> getDwarfSubtypeFlags() const {
118 return DwarfSubtypeFlags;
119 }
120 std::optional<XCOFF::CsectProperties> getCsectProp() const {
121 return CsectProp;
122 }
123 SectionKind getKind() const { return Kind; }
124};
125
126} // end namespace llvm
127
128#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:211
std::optional< XCOFF::CsectProperties > getCsectProp() const
bool isMultiSymbolsAllowed() const
LLVM_ABI ~MCSectionXCOFF()
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
XCOFF::SymbolType getCSectType() const
void setAlignment(Align Value)
Definition MCSection.h:662
bool isText() const
Definition MCSection.h:648
StringRef Name
Definition MCSection.h:639
MCSection(StringRef Name, bool IsText, bool IsBss, MCSymbol *Begin)
Definition MCSection.cpp:21
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
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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
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.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39