1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- 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 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_MC_SECTIONKIND_H
16 #define LLVM_MC_SECTIONKIND_H
20 /// SectionKind - This is a simple POD value that classifies the properties of
21 /// a section. A section is classified into the deepest possible
22 /// classification, and then the target maps them onto their sections based on
23 /// what capabilities they have.
25 /// The comments below describe these as if they were an inheritance hierarchy
26 /// in order to explain the predicates below.
30 /// Metadata - Debug info sections or other metadata.
33 /// Text - Text section, used for functions and other executable code.
36 /// ReadOnly - Data that is never written to at program runtime by the
37 /// program or the dynamic linker. Things in the top-level readonly
38 /// SectionKind are not mergeable.
41 /// MergableCString - Any null-terminated string which allows merging.
42 /// These values are known to end in a nul value of the specified size,
43 /// not otherwise contain a nul value, and be mergable. This allows the
44 /// linker to unique the strings if it so desires.
46 /// Mergeable1ByteCString - 1 byte mergable, null terminated, string.
47 Mergeable1ByteCString,
49 /// Mergeable2ByteCString - 2 byte mergable, null terminated, string.
50 Mergeable2ByteCString,
52 /// Mergeable4ByteCString - 4 byte mergable, null terminated, string.
53 Mergeable4ByteCString,
55 /// MergeableConst - These are sections for merging fixed-length
56 /// constants together. For example, this can be used to unique
57 /// constant pool entries etc.
59 /// MergeableConst4 - This is a section used by 4-byte constants,
60 /// for example, floats.
63 /// MergeableConst8 - This is a section used by 8-byte constants,
64 /// for example, doubles.
67 /// MergeableConst16 - This is a section used by 16-byte constants,
68 /// for example, vectors.
71 /// Writeable - This is the base of all segments that need to be written
72 /// to during program runtime.
74 /// ThreadLocal - This is the base of all TLS segments. All TLS
75 /// objects must be writeable, otherwise there is no reason for them to
78 /// ThreadBSS - Zero-initialized TLS data objects.
81 /// ThreadData - Initialized TLS data objects.
84 /// GlobalWriteableData - Writeable data that is global (not thread
87 /// BSS - Zero initialized writeable data.
90 /// BSSLocal - This is BSS (zero initialized and writable) data
91 /// which has local linkage.
94 /// BSSExtern - This is BSS data with normal external linkage.
97 /// Common - Data with common linkage. These represent tentative
98 /// definitions, which always have a zero initializer and are never
99 /// marked 'constant'.
102 /// DataRel - This is the most general form of data that is written
103 /// to by the program, it can have random relocations to arbitrary
107 /// DataNoRel - This is writeable data that has a non-zero
108 /// initializer, but whose initializer is known to have no
112 /// ReadOnlyWithRel - These are global variables that are never
113 /// written to by the program, but that have relocations, so they
114 /// must be stuck in a writeable section so that the dynamic linker
115 /// can write to them. If it chooses to, the dynamic linker can
116 /// mark the pages these globals end up on as read-only after it is
117 /// done with its relocation phase.
122 bool isMetadata() const { return K == Metadata; }
123 bool isText() const { return K == Text; }
125 bool isReadOnly() const {
126 return K == ReadOnly || isMergeableCString() ||
130 bool isMergeableCString() const {
131 return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
132 K == Mergeable4ByteCString;
134 bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
135 bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
136 bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
138 bool isMergeableConst() const {
139 return K == MergeableConst4 || K == MergeableConst8 ||
140 K == MergeableConst16;
142 bool isMergeableConst4() const { return K == MergeableConst4; }
143 bool isMergeableConst8() const { return K == MergeableConst8; }
144 bool isMergeableConst16() const { return K == MergeableConst16; }
146 bool isWriteable() const {
147 return isThreadLocal() || isGlobalWriteableData();
150 bool isThreadLocal() const {
151 return K == ThreadData || K == ThreadBSS;
154 bool isThreadBSS() const { return K == ThreadBSS; }
155 bool isThreadData() const { return K == ThreadData; }
157 bool isGlobalWriteableData() const {
158 return isBSS() || isCommon() || isDataRel() || isReadOnlyWithRel();
161 bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; }
162 bool isBSSLocal() const { return K == BSSLocal; }
163 bool isBSSExtern() const { return K == BSSExtern; }
165 bool isCommon() const { return K == Common; }
167 bool isDataRel() const {
168 return K == DataRel || K == DataNoRel;
171 bool isDataNoRel() const { return K == DataNoRel; }
173 bool isReadOnlyWithRel() const {
174 return K == ReadOnlyWithRel;
177 static SectionKind get(Kind K) {
184 static SectionKind getMetadata() { return get(Metadata); }
185 static SectionKind getText() { return get(Text); }
186 static SectionKind getReadOnly() { return get(ReadOnly); }
187 static SectionKind getMergeable1ByteCString() {
188 return get(Mergeable1ByteCString);
190 static SectionKind getMergeable2ByteCString() {
191 return get(Mergeable2ByteCString);
193 static SectionKind getMergeable4ByteCString() {
194 return get(Mergeable4ByteCString);
196 static SectionKind getMergeableConst4() { return get(MergeableConst4); }
197 static SectionKind getMergeableConst8() { return get(MergeableConst8); }
198 static SectionKind getMergeableConst16() { return get(MergeableConst16); }
199 static SectionKind getThreadBSS() { return get(ThreadBSS); }
200 static SectionKind getThreadData() { return get(ThreadData); }
201 static SectionKind getBSS() { return get(BSS); }
202 static SectionKind getBSSLocal() { return get(BSSLocal); }
203 static SectionKind getBSSExtern() { return get(BSSExtern); }
204 static SectionKind getCommon() { return get(Common); }
205 static SectionKind getDataRel() { return get(DataRel); }
206 static SectionKind getDataNoRel() { return get(DataNoRel); }
207 static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
210 } // end namespace llvm