SectionKind.h revision a3839bc3714e6a84222f45cf4c0f1a20a88b10cd
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 18namespace 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/// 28class 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 /// Common - Data with common linkage. These represent tentative 92 /// definitions, which always have a zero initializer and are never 93 /// marked 'constant'. 94 Common, 95 96 /// DataRel - This is the most general form of data that is written 97 /// to by the program, it can have random relocations to arbitrary 98 /// globals. 99 DataRel, 100 101 /// DataRelLocal - This is writeable data that has a non-zero 102 /// initializer and has relocations in it, but all of the 103 /// relocations are known to be within the final linked image 104 /// the global is linked into. 105 DataRelLocal, 106 107 /// DataNoRel - This is writeable data that has a non-zero 108 /// initializer, but whose initializer is known to have no 109 /// relocations. 110 DataNoRel, 111 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. 118 ReadOnlyWithRel, 119 120 /// ReadOnlyWithRelLocal - This is data that is readonly by the 121 /// program, but must be writeable so that the dynamic linker 122 /// can perform relocations in it. This is used when we know 123 /// that all the relocations are to globals in this final 124 /// linked image. 125 ReadOnlyWithRelLocal 126 127 } K : 8; 128public: 129 130 bool isMetadata() const { return K == Metadata; } 131 bool isText() const { return K == Text; } 132 133 bool isReadOnly() const { 134 return K == ReadOnly || isMergeableCString() || 135 isMergeableConst(); 136 } 137 138 bool isMergeableCString() const { 139 return K == Mergeable1ByteCString || K == Mergeable2ByteCString || 140 K == Mergeable4ByteCString; 141 } 142 bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; } 143 bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; } 144 bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; } 145 146 bool isMergeableConst() const { 147 return K == MergeableConst || K == MergeableConst4 || 148 K == MergeableConst8 || K == MergeableConst16; 149 } 150 bool isMergeableConst4() const { return K == MergeableConst4; } 151 bool isMergeableConst8() const { return K == MergeableConst8; } 152 bool isMergeableConst16() const { return K == MergeableConst16; } 153 154 bool isWriteable() const { 155 return isThreadLocal() || isGlobalWriteableData(); 156 } 157 158 bool isThreadLocal() const { 159 return K == ThreadData || K == ThreadBSS; 160 } 161 162 bool isThreadBSS() const { return K == ThreadBSS; } 163 bool isThreadData() const { return K == ThreadData; } 164 165 bool isGlobalWriteableData() const { 166 return isBSS() || isCommon() || isDataRel() || isReadOnlyWithRel(); 167 } 168 169 bool isBSS() const { return K == BSS; } 170 bool isCommon() const { return K == Common; } 171 172 bool isDataRel() const { 173 return K == DataRel || K == DataRelLocal || K == DataNoRel; 174 } 175 176 bool isDataRelLocal() const { 177 return K == DataRelLocal || K == DataNoRel; 178 } 179 180 bool isDataNoRel() const { return K == DataNoRel; } 181 182 bool isReadOnlyWithRel() const { 183 return K == ReadOnlyWithRel || K == ReadOnlyWithRelLocal; 184 } 185 186 bool isReadOnlyWithRelLocal() const { 187 return K == ReadOnlyWithRelLocal; 188 } 189private: 190 static SectionKind get(Kind K) { 191 SectionKind Res; 192 Res.K = K; 193 return Res; 194 } 195public: 196 197 static SectionKind getMetadata() { return get(Metadata); } 198 static SectionKind getText() { return get(Text); } 199 static SectionKind getReadOnly() { return get(ReadOnly); } 200 static SectionKind getMergeable1ByteCString() { 201 return get(Mergeable1ByteCString); 202 } 203 static SectionKind getMergeable2ByteCString() { 204 return get(Mergeable2ByteCString); 205 } 206 static SectionKind getMergeable4ByteCString() { 207 return get(Mergeable4ByteCString); 208 } 209 static SectionKind getMergeableConst() { return get(MergeableConst); } 210 static SectionKind getMergeableConst4() { return get(MergeableConst4); } 211 static SectionKind getMergeableConst8() { return get(MergeableConst8); } 212 static SectionKind getMergeableConst16() { return get(MergeableConst16); } 213 static SectionKind getThreadBSS() { return get(ThreadBSS); } 214 static SectionKind getThreadData() { return get(ThreadData); } 215 static SectionKind getBSS() { return get(BSS); } 216 static SectionKind getCommon() { return get(Common); } 217 static SectionKind getDataRel() { return get(DataRel); } 218 static SectionKind getDataRelLocal() { return get(DataRelLocal); } 219 static SectionKind getDataNoRel() { return get(DataNoRel); } 220 static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); } 221 static SectionKind getReadOnlyWithRelLocal(){ 222 return get(ReadOnlyWithRelLocal); 223 } 224}; 225 226} // end namespace llvm 227 228#endif 229