1 //===-- llvm/MC/SectionKind.h - Classification of sections ------*- 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 #ifndef LLVM_MC_SECTIONKIND_H 11 #define LLVM_MC_SECTIONKIND_H 12 13 namespace llvm { 14 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. 19 /// 20 /// The comments below describe these as if they were an inheritance hierarchy 21 /// in order to explain the predicates below. 22 /// 23 class SectionKind { 24 enum Kind { 25 /// Metadata - Debug info sections or other metadata. 26 Metadata, 27 28 /// Text - Text section, used for functions and other executable code. 29 Text, 30 31 /// ExecuteOnly, Text section that is not readable. 32 ExecuteOnly, 33 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. 37 ReadOnly, 38 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. 43 44 /// Mergeable1ByteCString - 1 byte mergable, null terminated, string. 45 Mergeable1ByteCString, 46 47 /// Mergeable2ByteCString - 2 byte mergable, null terminated, string. 48 Mergeable2ByteCString, 49 50 /// Mergeable4ByteCString - 4 byte mergable, null terminated, string. 51 Mergeable4ByteCString, 52 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. 56 57 /// MergeableConst4 - This is a section used by 4-byte constants, 58 /// for example, floats. 59 MergeableConst4, 60 61 /// MergeableConst8 - This is a section used by 8-byte constants, 62 /// for example, doubles. 63 MergeableConst8, 64 65 /// MergeableConst16 - This is a section used by 16-byte constants, 66 /// for example, vectors. 67 MergeableConst16, 68 69 /// MergeableConst32 - This is a section used by 32-byte constants, 70 /// for example, vectors. 71 MergeableConst32, 72 73 /// Writeable - This is the base of all segments that need to be written 74 /// to during program runtime. 75 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 78 /// be thread local! 79 80 /// ThreadBSS - Zero-initialized TLS data objects. 81 ThreadBSS, 82 83 /// ThreadData - Initialized TLS data objects. 84 ThreadData, 85 86 /// GlobalWriteableData - Writeable data that is global (not thread 87 /// local). 88 89 /// BSS - Zero initialized writeable data. 90 BSS, 91 92 /// BSSLocal - This is BSS (zero initialized and writable) data 93 /// which has local linkage. 94 BSSLocal, 95 96 /// BSSExtern - This is BSS data with normal external linkage. 97 BSSExtern, 98 99 /// Common - Data with common linkage. These represent tentative 100 /// definitions, which always have a zero initializer and are never 101 /// marked 'constant'. 102 Common, 103 104 /// This is writeable data that has a non-zero initializer. 105 Data, 106 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. 113 ReadOnlyWithRel 114 } K : 8; 115 public: 116 isMetadata()117 bool isMetadata() const { return K == Metadata; } 118 isText()119 bool isText() const { return K == Text || K == ExecuteOnly; } 120 isExecuteOnly()121 bool isExecuteOnly() const { return K == ExecuteOnly; } 122 isReadOnly()123 bool isReadOnly() const { 124 return K == ReadOnly || isMergeableCString() || 125 isMergeableConst(); 126 } 127 isMergeableCString()128 bool isMergeableCString() const { 129 return K == Mergeable1ByteCString || K == Mergeable2ByteCString || 130 K == Mergeable4ByteCString; 131 } isMergeable1ByteCString()132 bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; } isMergeable2ByteCString()133 bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; } isMergeable4ByteCString()134 bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; } 135 isMergeableConst()136 bool isMergeableConst() const { 137 return K == MergeableConst4 || K == MergeableConst8 || 138 K == MergeableConst16 || K == MergeableConst32; 139 } isMergeableConst4()140 bool isMergeableConst4() const { return K == MergeableConst4; } isMergeableConst8()141 bool isMergeableConst8() const { return K == MergeableConst8; } isMergeableConst16()142 bool isMergeableConst16() const { return K == MergeableConst16; } isMergeableConst32()143 bool isMergeableConst32() const { return K == MergeableConst32; } 144 isWriteable()145 bool isWriteable() const { 146 return isThreadLocal() || isGlobalWriteableData(); 147 } 148 isThreadLocal()149 bool isThreadLocal() const { 150 return K == ThreadData || K == ThreadBSS; 151 } 152 isThreadBSS()153 bool isThreadBSS() const { return K == ThreadBSS; } isThreadData()154 bool isThreadData() const { return K == ThreadData; } 155 isGlobalWriteableData()156 bool isGlobalWriteableData() const { 157 return isBSS() || isCommon() || isData() || isReadOnlyWithRel(); 158 } 159 isBSS()160 bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; } isBSSLocal()161 bool isBSSLocal() const { return K == BSSLocal; } isBSSExtern()162 bool isBSSExtern() const { return K == BSSExtern; } 163 isCommon()164 bool isCommon() const { return K == Common; } 165 isData()166 bool isData() const { return K == Data; } 167 isReadOnlyWithRel()168 bool isReadOnlyWithRel() const { 169 return K == ReadOnlyWithRel; 170 } 171 private: get(Kind K)172 static SectionKind get(Kind K) { 173 SectionKind Res; 174 Res.K = K; 175 return Res; 176 } 177 public: 178 getMetadata()179 static SectionKind getMetadata() { return get(Metadata); } getText()180 static SectionKind getText() { return get(Text); } getExecuteOnly()181 static SectionKind getExecuteOnly() { return get(ExecuteOnly); } getReadOnly()182 static SectionKind getReadOnly() { return get(ReadOnly); } getMergeable1ByteCString()183 static SectionKind getMergeable1ByteCString() { 184 return get(Mergeable1ByteCString); 185 } getMergeable2ByteCString()186 static SectionKind getMergeable2ByteCString() { 187 return get(Mergeable2ByteCString); 188 } getMergeable4ByteCString()189 static SectionKind getMergeable4ByteCString() { 190 return get(Mergeable4ByteCString); 191 } getMergeableConst4()192 static SectionKind getMergeableConst4() { return get(MergeableConst4); } getMergeableConst8()193 static SectionKind getMergeableConst8() { return get(MergeableConst8); } getMergeableConst16()194 static SectionKind getMergeableConst16() { return get(MergeableConst16); } getMergeableConst32()195 static SectionKind getMergeableConst32() { return get(MergeableConst32); } getThreadBSS()196 static SectionKind getThreadBSS() { return get(ThreadBSS); } getThreadData()197 static SectionKind getThreadData() { return get(ThreadData); } getBSS()198 static SectionKind getBSS() { return get(BSS); } getBSSLocal()199 static SectionKind getBSSLocal() { return get(BSSLocal); } getBSSExtern()200 static SectionKind getBSSExtern() { return get(BSSExtern); } getCommon()201 static SectionKind getCommon() { return get(Common); } getData()202 static SectionKind getData() { return get(Data); } getReadOnlyWithRel()203 static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); } 204 }; 205 206 } // end namespace llvm 207 208 #endif 209