1 //===-- llvm/MC/SectionKind.h - Classification of sections ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_SECTIONKIND_H
11 #define LLVM_MC_SECTIONKIND_H
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.
20 /// The comments below describe these as if they were an inheritance hierarchy
21 /// in order to explain the predicates below.
25 /// Metadata - Debug info sections or other metadata.
28 /// Text - Text section, used for functions and other executable code.
31 /// ExecuteOnly, Text section that is not readable.
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.
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.
44 /// Mergeable1ByteCString - 1 byte mergable, null terminated, string.
45 Mergeable1ByteCString,
47 /// Mergeable2ByteCString - 2 byte mergable, null terminated, string.
48 Mergeable2ByteCString,
50 /// Mergeable4ByteCString - 4 byte mergable, null terminated, string.
51 Mergeable4ByteCString,
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.
57 /// MergeableConst4 - This is a section used by 4-byte constants,
58 /// for example, floats.
61 /// MergeableConst8 - This is a section used by 8-byte constants,
62 /// for example, doubles.
65 /// MergeableConst16 - This is a section used by 16-byte constants,
66 /// for example, vectors.
69 /// MergeableConst32 - This is a section used by 32-byte constants,
70 /// for example, vectors.
73 /// Writeable - This is the base of all segments that need to be written
74 /// to during program runtime.
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
80 /// ThreadBSS - Zero-initialized TLS data objects.
83 /// ThreadData - Initialized TLS data objects.
86 /// GlobalWriteableData - Writeable data that is global (not thread
89 /// BSS - Zero initialized writeable data.
92 /// BSSLocal - This is BSS (zero initialized and writable) data
93 /// which has local linkage.
96 /// BSSExtern - This is BSS data with normal external linkage.
99 /// Common - Data with common linkage. These represent tentative
100 /// definitions, which always have a zero initializer and are never
101 /// marked 'constant'.
104 /// This is writeable data that has a non-zero initializer.
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.
117 bool isMetadata() const { return K == Metadata; }
119 bool isText() const { return K == Text || K == ExecuteOnly; }
121 bool isExecuteOnly() const { return K == ExecuteOnly; }
123 bool isReadOnly() const {
124 return K == ReadOnly || isMergeableCString() ||
128 bool isMergeableCString() const {
129 return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
130 K == Mergeable4ByteCString;
132 bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
133 bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
134 bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
136 bool isMergeableConst() const {
137 return K == MergeableConst4 || K == MergeableConst8 ||
138 K == MergeableConst16 || K == MergeableConst32;
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; }
145 bool isWriteable() const {
146 return isThreadLocal() || isGlobalWriteableData();
149 bool isThreadLocal() const {
150 return K == ThreadData || K == ThreadBSS;
153 bool isThreadBSS() const { return K == ThreadBSS; }
154 bool isThreadData() const { return K == ThreadData; }
156 bool isGlobalWriteableData() const {
157 return isBSS() || isCommon() || isData() || isReadOnlyWithRel();
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; }
164 bool isCommon() const { return K == Common; }
166 bool isData() const { return K == Data; }
168 bool isReadOnlyWithRel() const {
169 return K == ReadOnlyWithRel;
172 static SectionKind get(Kind K) {
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);
186 static SectionKind getMergeable2ByteCString() {
187 return get(Mergeable2ByteCString);
189 static SectionKind getMergeable4ByteCString() {
190 return get(Mergeable4ByteCString);
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); }
206 } // end namespace llvm