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