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 59 /// MergeableConst4 - This is a section used by 4-byte constants, 60 /// for example, floats. 61 MergeableConst4, 62 63 /// MergeableConst8 - This is a section used by 8-byte constants, 64 /// for example, doubles. 65 MergeableConst8, 66 67 /// MergeableConst16 - This is a section used by 16-byte constants, 68 /// for example, vectors. 69 MergeableConst16, 70 71 /// Writeable - This is the base of all segments that need to be written 72 /// to during program runtime. 73 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 76 /// be thread local! 77 78 /// ThreadBSS - Zero-initialized TLS data objects. 79 ThreadBSS, 80 81 /// ThreadData - Initialized TLS data objects. 82 ThreadData, 83 84 /// GlobalWriteableData - Writeable data that is global (not thread 85 /// local). 86 87 /// BSS - Zero initialized writeable data. 88 BSS, 89 90 /// BSSLocal - This is BSS (zero initialized and writable) data 91 /// which has local linkage. 92 BSSLocal, 93 94 /// BSSExtern - This is BSS data with normal external linkage. 95 BSSExtern, 96 97 /// Common - Data with common linkage. These represent tentative 98 /// definitions, which always have a zero initializer and are never 99 /// marked 'constant'. 100 Common, 101 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 104 /// globals. 105 DataRel, 106 107 /// DataRelLocal - This is writeable data that has a non-zero 108 /// initializer and has relocations in it, but all of the 109 /// relocations are known to be within the final linked image 110 /// the global is linked into. 111 DataRelLocal, 112 113 /// DataNoRel - This is writeable data that has a non-zero 114 /// initializer, but whose initializer is known to have no 115 /// relocations. 116 DataNoRel, 117 118 /// ReadOnlyWithRel - These are global variables that are never 119 /// written to by the program, but that have relocations, so they 120 /// must be stuck in a writeable section so that the dynamic linker 121 /// can write to them. If it chooses to, the dynamic linker can 122 /// mark the pages these globals end up on as read-only after it is 123 /// done with its relocation phase. 124 ReadOnlyWithRel, 125 126 /// ReadOnlyWithRelLocal - This is data that is readonly by the 127 /// program, but must be writeable so that the dynamic linker 128 /// can perform relocations in it. This is used when we know 129 /// that all the relocations are to globals in this final 130 /// linked image. 131 ReadOnlyWithRelLocal 132 133 } K : 8; 134 public: 135 isMetadata()136 bool isMetadata() const { return K == Metadata; } isText()137 bool isText() const { return K == Text; } 138 isReadOnly()139 bool isReadOnly() const { 140 return K == ReadOnly || isMergeableCString() || 141 isMergeableConst(); 142 } 143 isMergeableCString()144 bool isMergeableCString() const { 145 return K == Mergeable1ByteCString || K == Mergeable2ByteCString || 146 K == Mergeable4ByteCString; 147 } isMergeable1ByteCString()148 bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; } isMergeable2ByteCString()149 bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; } isMergeable4ByteCString()150 bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; } 151 isMergeableConst()152 bool isMergeableConst() const { 153 return K == MergeableConst4 || K == MergeableConst8 || 154 K == MergeableConst16; 155 } isMergeableConst4()156 bool isMergeableConst4() const { return K == MergeableConst4; } isMergeableConst8()157 bool isMergeableConst8() const { return K == MergeableConst8; } isMergeableConst16()158 bool isMergeableConst16() const { return K == MergeableConst16; } 159 isWriteable()160 bool isWriteable() const { 161 return isThreadLocal() || isGlobalWriteableData(); 162 } 163 isThreadLocal()164 bool isThreadLocal() const { 165 return K == ThreadData || K == ThreadBSS; 166 } 167 isThreadBSS()168 bool isThreadBSS() const { return K == ThreadBSS; } isThreadData()169 bool isThreadData() const { return K == ThreadData; } 170 isGlobalWriteableData()171 bool isGlobalWriteableData() const { 172 return isBSS() || isCommon() || isDataRel() || isReadOnlyWithRel(); 173 } 174 isBSS()175 bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; } isBSSLocal()176 bool isBSSLocal() const { return K == BSSLocal; } isBSSExtern()177 bool isBSSExtern() const { return K == BSSExtern; } 178 isCommon()179 bool isCommon() const { return K == Common; } 180 isDataRel()181 bool isDataRel() const { 182 return K == DataRel || K == DataRelLocal || K == DataNoRel; 183 } 184 isDataRelLocal()185 bool isDataRelLocal() const { 186 return K == DataRelLocal || K == DataNoRel; 187 } 188 isDataNoRel()189 bool isDataNoRel() const { return K == DataNoRel; } 190 isReadOnlyWithRel()191 bool isReadOnlyWithRel() const { 192 return K == ReadOnlyWithRel || K == ReadOnlyWithRelLocal; 193 } 194 isReadOnlyWithRelLocal()195 bool isReadOnlyWithRelLocal() const { 196 return K == ReadOnlyWithRelLocal; 197 } 198 private: get(Kind K)199 static SectionKind get(Kind K) { 200 SectionKind Res; 201 Res.K = K; 202 return Res; 203 } 204 public: 205 getMetadata()206 static SectionKind getMetadata() { return get(Metadata); } getText()207 static SectionKind getText() { return get(Text); } getReadOnly()208 static SectionKind getReadOnly() { return get(ReadOnly); } getMergeable1ByteCString()209 static SectionKind getMergeable1ByteCString() { 210 return get(Mergeable1ByteCString); 211 } getMergeable2ByteCString()212 static SectionKind getMergeable2ByteCString() { 213 return get(Mergeable2ByteCString); 214 } getMergeable4ByteCString()215 static SectionKind getMergeable4ByteCString() { 216 return get(Mergeable4ByteCString); 217 } getMergeableConst4()218 static SectionKind getMergeableConst4() { return get(MergeableConst4); } getMergeableConst8()219 static SectionKind getMergeableConst8() { return get(MergeableConst8); } getMergeableConst16()220 static SectionKind getMergeableConst16() { return get(MergeableConst16); } getThreadBSS()221 static SectionKind getThreadBSS() { return get(ThreadBSS); } getThreadData()222 static SectionKind getThreadData() { return get(ThreadData); } getBSS()223 static SectionKind getBSS() { return get(BSS); } getBSSLocal()224 static SectionKind getBSSLocal() { return get(BSSLocal); } getBSSExtern()225 static SectionKind getBSSExtern() { return get(BSSExtern); } getCommon()226 static SectionKind getCommon() { return get(Common); } getDataRel()227 static SectionKind getDataRel() { return get(DataRel); } getDataRelLocal()228 static SectionKind getDataRelLocal() { return get(DataRelLocal); } getDataNoRel()229 static SectionKind getDataNoRel() { return get(DataNoRel); } getReadOnlyWithRel()230 static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); } getReadOnlyWithRelLocal()231 static SectionKind getReadOnlyWithRelLocal(){ 232 return get(ReadOnlyWithRelLocal); 233 } 234 }; 235 236 } // end namespace llvm 237 238 #endif 239