• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- 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 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_MC_SECTIONKIND_H
16 #define LLVM_MC_SECTIONKIND_H
17 
18 namespace llvm {
19 
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.
24 ///
25 /// The comments below describe these as if they were an inheritance hierarchy
26 /// in order to explain the predicates below.
27 ///
28 class SectionKind {
29   enum Kind {
30     /// Metadata - Debug info sections or other metadata.
31     Metadata,
32 
33     /// Text - Text section, used for functions and other executable code.
34     Text,
35 
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.
39     ReadOnly,
40 
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.
45 
46            /// Mergeable1ByteCString - 1 byte mergable, null terminated, string.
47            Mergeable1ByteCString,
48 
49            /// Mergeable2ByteCString - 2 byte mergable, null terminated, string.
50            Mergeable2ByteCString,
51 
52            /// Mergeable4ByteCString - 4 byte mergable, null terminated, string.
53            Mergeable4ByteCString,
54 
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.
58         MergeableConst,
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     /// Writeable - This is the base of all segments that need to be written
73     /// to during program runtime.
74 
75        /// ThreadLocal - This is the base of all TLS segments.  All TLS
76        /// objects must be writeable, otherwise there is no reason for them to
77        /// be thread local!
78 
79            /// ThreadBSS - Zero-initialized TLS data objects.
80            ThreadBSS,
81 
82            /// ThreadData - Initialized TLS data objects.
83            ThreadData,
84 
85        /// GlobalWriteableData - Writeable data that is global (not thread
86        /// local).
87 
88            /// BSS - Zero initialized writeable data.
89            BSS,
90 
91                /// BSSLocal - This is BSS (zero initialized and writable) data
92                /// which has local linkage.
93                BSSLocal,
94 
95                /// BSSExtern - This is BSS data with normal external linkage.
96                BSSExtern,
97 
98            /// Common - Data with common linkage.  These represent tentative
99            /// definitions, which always have a zero initializer and are never
100            /// marked 'constant'.
101            Common,
102 
103            /// DataRel - This is the most general form of data that is written
104            /// to by the program, it can have random relocations to arbitrary
105            /// globals.
106            DataRel,
107 
108                /// DataRelLocal - This is writeable data that has a non-zero
109                /// initializer and has relocations in it, but all of the
110                /// relocations are known to be within the final linked image
111                /// the global is linked into.
112                DataRelLocal,
113 
114                    /// DataNoRel - This is writeable data that has a non-zero
115                    /// initializer, but whose initializer is known to have no
116                    /// relocations.
117                    DataNoRel,
118 
119            /// ReadOnlyWithRel - These are global variables that are never
120            /// written to by the program, but that have relocations, so they
121            /// must be stuck in a writeable section so that the dynamic linker
122            /// can write to them.  If it chooses to, the dynamic linker can
123            /// mark the pages these globals end up on as read-only after it is
124            /// done with its relocation phase.
125            ReadOnlyWithRel,
126 
127                /// ReadOnlyWithRelLocal - This is data that is readonly by the
128                /// program, but must be writeable so that the dynamic linker
129                /// can perform relocations in it.  This is used when we know
130                /// that all the relocations are to globals in this final
131                /// linked image.
132                ReadOnlyWithRelLocal
133 
134   } K : 8;
135 public:
136 
isMetadata()137   bool isMetadata() const { return K == Metadata; }
isText()138   bool isText() const { return K == Text; }
139 
isReadOnly()140   bool isReadOnly() const {
141     return K == ReadOnly || isMergeableCString() ||
142            isMergeableConst();
143   }
144 
isMergeableCString()145   bool isMergeableCString() const {
146     return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
147            K == Mergeable4ByteCString;
148   }
isMergeable1ByteCString()149   bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
isMergeable2ByteCString()150   bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
isMergeable4ByteCString()151   bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
152 
isMergeableConst()153   bool isMergeableConst() const {
154     return K == MergeableConst || K == MergeableConst4 ||
155            K == MergeableConst8 || K == MergeableConst16;
156   }
isMergeableConst4()157   bool isMergeableConst4() const { return K == MergeableConst4; }
isMergeableConst8()158   bool isMergeableConst8() const { return K == MergeableConst8; }
isMergeableConst16()159   bool isMergeableConst16() const { return K == MergeableConst16; }
160 
isWriteable()161   bool isWriteable() const {
162     return isThreadLocal() || isGlobalWriteableData();
163   }
164 
isThreadLocal()165   bool isThreadLocal() const {
166     return K == ThreadData || K == ThreadBSS;
167   }
168 
isThreadBSS()169   bool isThreadBSS() const { return K == ThreadBSS; }
isThreadData()170   bool isThreadData() const { return K == ThreadData; }
171 
isGlobalWriteableData()172   bool isGlobalWriteableData() const {
173     return isBSS() || isCommon() || isDataRel() || isReadOnlyWithRel();
174   }
175 
isBSS()176   bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; }
isBSSLocal()177   bool isBSSLocal() const { return K == BSSLocal; }
isBSSExtern()178   bool isBSSExtern() const { return K == BSSExtern; }
179 
isCommon()180   bool isCommon() const { return K == Common; }
181 
isDataRel()182   bool isDataRel() const {
183     return K == DataRel || K == DataRelLocal || K == DataNoRel;
184   }
185 
isDataRelLocal()186   bool isDataRelLocal() const {
187     return K == DataRelLocal || K == DataNoRel;
188   }
189 
isDataNoRel()190   bool isDataNoRel() const { return K == DataNoRel; }
191 
isReadOnlyWithRel()192   bool isReadOnlyWithRel() const {
193     return K == ReadOnlyWithRel || K == ReadOnlyWithRelLocal;
194   }
195 
isReadOnlyWithRelLocal()196   bool isReadOnlyWithRelLocal() const {
197     return K == ReadOnlyWithRelLocal;
198   }
199 private:
get(Kind K)200   static SectionKind get(Kind K) {
201     SectionKind Res;
202     Res.K = K;
203     return Res;
204   }
205 public:
206 
getMetadata()207   static SectionKind getMetadata() { return get(Metadata); }
getText()208   static SectionKind getText() { return get(Text); }
getReadOnly()209   static SectionKind getReadOnly() { return get(ReadOnly); }
getMergeable1ByteCString()210   static SectionKind getMergeable1ByteCString() {
211     return get(Mergeable1ByteCString);
212   }
getMergeable2ByteCString()213   static SectionKind getMergeable2ByteCString() {
214     return get(Mergeable2ByteCString);
215   }
getMergeable4ByteCString()216   static SectionKind getMergeable4ByteCString() {
217     return get(Mergeable4ByteCString);
218   }
getMergeableConst()219   static SectionKind getMergeableConst() { return get(MergeableConst); }
getMergeableConst4()220   static SectionKind getMergeableConst4() { return get(MergeableConst4); }
getMergeableConst8()221   static SectionKind getMergeableConst8() { return get(MergeableConst8); }
getMergeableConst16()222   static SectionKind getMergeableConst16() { return get(MergeableConst16); }
getThreadBSS()223   static SectionKind getThreadBSS() { return get(ThreadBSS); }
getThreadData()224   static SectionKind getThreadData() { return get(ThreadData); }
getBSS()225   static SectionKind getBSS() { return get(BSS); }
getBSSLocal()226   static SectionKind getBSSLocal() { return get(BSSLocal); }
getBSSExtern()227   static SectionKind getBSSExtern() { return get(BSSExtern); }
getCommon()228   static SectionKind getCommon() { return get(Common); }
getDataRel()229   static SectionKind getDataRel() { return get(DataRel); }
getDataRelLocal()230   static SectionKind getDataRelLocal() { return get(DataRelLocal); }
getDataNoRel()231   static SectionKind getDataNoRel() { return get(DataNoRel); }
getReadOnlyWithRel()232   static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
getReadOnlyWithRelLocal()233   static SectionKind getReadOnlyWithRelLocal(){
234     return get(ReadOnlyWithRelLocal);
235   }
236 };
237 
238 } // end namespace llvm
239 
240 #endif
241