LLVM 22.0.0git
SectionKind.h
Go to the documentation of this file.
1//===-- llvm/MC/SectionKind.h - Classification of 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#ifndef LLVM_MC_SECTIONKIND_H
10#define LLVM_MC_SECTIONKIND_H
11
12namespace llvm {
13
14/// SectionKind - This is a simple POD value that classifies the properties of
15/// a section. A section is classified into the deepest possible
16/// classification, and then the target maps them onto their sections based on
17/// what capabilities they have.
18///
19/// The comments below describe these as if they were an inheritance hierarchy
20/// in order to explain the predicates below.
21///
23 enum Kind {
24 /// Metadata - Debug info sections or other metadata.
25 Metadata,
26
27 /// Exclude - This section will be excluded from the final executable or
28 /// shared library. Only valid for ELF / COFF targets.
29 Exclude,
30
31 /// Text - Text section, used for functions and other executable code.
32 Text,
33
34 /// ExecuteOnly, Text section that is not readable.
35 ExecuteOnly,
36
37 /// ReadOnly - Data that is never written to at program runtime by the
38 /// program or the dynamic linker. Things in the top-level readonly
39 /// SectionKind are not mergeable.
40 ReadOnly,
41
42 /// MergableCString - Any null-terminated string which allows merging.
43 /// These values are known to end in a nul value of the specified size,
44 /// not otherwise contain a nul value, and be mergable. This allows the
45 /// linker to unique the strings if it so desires.
46
47 /// Mergeable1ByteCString - 1 byte mergable, null terminated, string.
48 Mergeable1ByteCString,
49
50 /// Mergeable2ByteCString - 2 byte mergable, null terminated, string.
51 Mergeable2ByteCString,
52
53 /// Mergeable4ByteCString - 4 byte mergable, null terminated, string.
54 Mergeable4ByteCString,
55
56 /// MergeableConst - These are sections for merging fixed-length
57 /// constants together. For example, this can be used to unique
58 /// constant pool entries etc.
59
60 /// MergeableConst4 - This is a section used by 4-byte constants,
61 /// for example, floats.
62 MergeableConst4,
63
64 /// MergeableConst8 - This is a section used by 8-byte constants,
65 /// for example, doubles.
66 MergeableConst8,
67
68 /// MergeableConst16 - This is a section used by 16-byte constants,
69 /// for example, vectors.
70 MergeableConst16,
71
72 /// MergeableConst32 - This is a section used by 32-byte constants,
73 /// for example, vectors.
74 MergeableConst32,
75
76 /// Writeable - This is the base of all segments that need to be written
77 /// to during program runtime.
78
79 /// ThreadLocal - This is the base of all TLS segments. All TLS
80 /// objects must be writeable, otherwise there is no reason for them to
81 /// be thread local!
82
83 /// ThreadBSS - Zero-initialized TLS data objects.
84 ThreadBSS,
85
86 /// ThreadData - Initialized TLS data objects.
87 ThreadData,
88
89 /// ThreadBSSLocal - Zero-initialized TLS data objects with local linkage.
90 ThreadBSSLocal,
91
92 /// GlobalWriteableData - Writeable data that is global (not thread
93 /// local).
94
95 /// BSS - Zero initialized writeable data.
96 BSS,
97
98 /// BSSLocal - This is BSS (zero initialized and writable) data
99 /// which has local linkage.
100 BSSLocal,
101
102 /// BSSExtern - This is BSS data with normal external linkage.
103 BSSExtern,
104
105 /// Common - Data with common linkage. These represent tentative
106 /// definitions, which always have a zero initializer and are never
107 /// marked 'constant'.
108 Common,
109
110 /// This is writeable data that has a non-zero initializer.
111 Data,
112
113 /// ReadOnlyWithRel - These are global variables that are never
114 /// written to by the program, but that have relocations, so they
115 /// must be stuck in a writeable section so that the dynamic linker
116 /// can write to them. If it chooses to, the dynamic linker can
117 /// mark the pages these globals end up on as read-only after it is
118 /// done with its relocation phase.
119 ReadOnlyWithRel
120 } K : 8;
121public:
122
123 bool isMetadata() const { return K == Metadata; }
124
125 bool isExclude() const { return K == Exclude; }
126
127 bool isText() const { return K == Text || K == ExecuteOnly; }
128
129 bool isExecuteOnly() const { return K == ExecuteOnly; }
130
131 bool isReadOnly() const {
132 return K == ReadOnly || isMergeableCString() ||
134 }
135
136 bool isMergeableCString() const {
137 return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
138 K == Mergeable4ByteCString;
139 }
140 bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
141 bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
142 bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
143
144 bool isMergeableConst() const {
145 return K == MergeableConst4 || K == MergeableConst8 ||
146 K == MergeableConst16 || K == MergeableConst32;
147 }
148 bool isMergeableConst4() const { return K == MergeableConst4; }
149 bool isMergeableConst8() const { return K == MergeableConst8; }
150 bool isMergeableConst16() const { return K == MergeableConst16; }
151 bool isMergeableConst32() const { return K == MergeableConst32; }
152
153 bool isWriteable() const {
155 }
156
157 bool isThreadLocal() const {
158 return K == ThreadData || K == ThreadBSS || K == ThreadBSSLocal;
159 }
160
161 bool isThreadBSS() const { return K == ThreadBSS || K == ThreadBSSLocal; }
162 bool isThreadData() const { return K == ThreadData; }
163 bool isThreadBSSLocal() const { return K == ThreadBSSLocal; }
164
166 return isBSS() || isCommon() || isData() || isReadOnlyWithRel();
167 }
168
169 bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; }
170 bool isBSSLocal() const { return K == BSSLocal; }
171 bool isBSSExtern() const { return K == BSSExtern; }
172
173 bool isCommon() const { return K == Common; }
174
175 bool isData() const { return K == Data; }
176
177 bool isReadOnlyWithRel() const {
178 return K == ReadOnlyWithRel;
179 }
180private:
181 static SectionKind get(Kind K) {
182 SectionKind Res;
183 Res.K = K;
184 return Res;
185 }
186public:
187
188 static SectionKind getMetadata() { return get(Metadata); }
189 static SectionKind getExclude() { return get(Exclude); }
190 static SectionKind getText() { return get(Text); }
191 static SectionKind getExecuteOnly() { return get(ExecuteOnly); }
192 static SectionKind getReadOnly() { return get(ReadOnly); }
194 return get(Mergeable1ByteCString);
195 }
197 return get(Mergeable2ByteCString);
198 }
200 return get(Mergeable4ByteCString);
201 }
202 static SectionKind getMergeableConst4() { return get(MergeableConst4); }
203 static SectionKind getMergeableConst8() { return get(MergeableConst8); }
204 static SectionKind getMergeableConst16() { return get(MergeableConst16); }
205 static SectionKind getMergeableConst32() { return get(MergeableConst32); }
206 static SectionKind getThreadBSS() { return get(ThreadBSS); }
207 static SectionKind getThreadData() { return get(ThreadData); }
208 static SectionKind getThreadBSSLocal() { return get(ThreadBSSLocal); }
209 static SectionKind getBSS() { return get(BSS); }
210 static SectionKind getBSSLocal() { return get(BSSLocal); }
211 static SectionKind getBSSExtern() { return get(BSSExtern); }
212 static SectionKind getCommon() { return get(Common); }
213 static SectionKind getData() { return get(Data); }
214 static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
215};
216
217} // end namespace llvm
218
219#endif
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition SectionKind.h:22
static SectionKind getThreadData()
bool isCommon() const
bool isBSS() const
static SectionKind getBSSExtern()
bool isMergeable2ByteCString() const
static SectionKind getMetadata()
bool isThreadBSSLocal() const
bool isReadOnlyWithRel() const
static SectionKind getMergeable2ByteCString()
bool isMergeableConst4() const
static SectionKind getExclude()
static SectionKind getBSSLocal()
static SectionKind getMergeableConst4()
static SectionKind getCommon()
static SectionKind getText()
static SectionKind getThreadBSSLocal()
static SectionKind getReadOnlyWithRel()
bool isMergeableConst() const
bool isBSSLocal() const
bool isMergeableConst8() const
static SectionKind getData()
bool isExclude() const
bool isMetadata() const
static SectionKind getMergeableConst8()
bool isMergeable1ByteCString() const
bool isThreadBSS() const
bool isThreadLocal() const
bool isBSSExtern() const
bool isText() const
static SectionKind getBSS()
static SectionKind getThreadBSS()
bool isMergeableConst32() const
bool isExecuteOnly() const
bool isThreadData() const
bool isReadOnly() const
bool isMergeableCString() const
static SectionKind getMergeableConst16()
bool isGlobalWriteableData() const
bool isMergeable4ByteCString() const
static SectionKind getMergeable4ByteCString()
bool isData() const
static SectionKind getExecuteOnly()
bool isMergeableConst16() const
static SectionKind getMergeable1ByteCString()
bool isWriteable() const
static SectionKind getReadOnly()
static SectionKind getMergeableConst32()
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)