SectionKind.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. #ifndef LLVM_MC_SECTIONKIND_H
  15. #define LLVM_MC_SECTIONKIND_H
  16. namespace llvm {
  17. /// SectionKind - This is a simple POD value that classifies the properties of
  18. /// a section. A section is classified into the deepest possible
  19. /// classification, and then the target maps them onto their sections based on
  20. /// what capabilities they have.
  21. ///
  22. /// The comments below describe these as if they were an inheritance hierarchy
  23. /// in order to explain the predicates below.
  24. ///
  25. class SectionKind {
  26. enum Kind {
  27. /// Metadata - Debug info sections or other metadata.
  28. Metadata,
  29. /// Text - Text section, used for functions and other executable code.
  30. Text,
  31. /// ReadOnly - Data that is never written to at program runtime by the
  32. /// program or the dynamic linker. Things in the top-level readonly
  33. /// SectionKind are not mergeable.
  34. ReadOnly,
  35. /// MergableCString - Any null-terminated string which allows merging.
  36. /// These values are known to end in a nul value of the specified size,
  37. /// not otherwise contain a nul value, and be mergable. This allows the
  38. /// linker to unique the strings if it so desires.
  39. /// Mergeable1ByteCString - 1 byte mergable, null terminated, string.
  40. Mergeable1ByteCString,
  41. /// Mergeable2ByteCString - 2 byte mergable, null terminated, string.
  42. Mergeable2ByteCString,
  43. /// Mergeable4ByteCString - 4 byte mergable, null terminated, string.
  44. Mergeable4ByteCString,
  45. /// MergeableConst - These are sections for merging fixed-length
  46. /// constants together. For example, this can be used to unique
  47. /// constant pool entries etc.
  48. /// MergeableConst4 - This is a section used by 4-byte constants,
  49. /// for example, floats.
  50. MergeableConst4,
  51. /// MergeableConst8 - This is a section used by 8-byte constants,
  52. /// for example, doubles.
  53. MergeableConst8,
  54. /// MergeableConst16 - This is a section used by 16-byte constants,
  55. /// for example, vectors.
  56. MergeableConst16,
  57. /// Writeable - This is the base of all segments that need to be written
  58. /// to during program runtime.
  59. /// ThreadLocal - This is the base of all TLS segments. All TLS
  60. /// objects must be writeable, otherwise there is no reason for them to
  61. /// be thread local!
  62. /// ThreadBSS - Zero-initialized TLS data objects.
  63. ThreadBSS,
  64. /// ThreadData - Initialized TLS data objects.
  65. ThreadData,
  66. /// GlobalWriteableData - Writeable data that is global (not thread
  67. /// local).
  68. /// BSS - Zero initialized writeable data.
  69. BSS,
  70. /// BSSLocal - This is BSS (zero initialized and writable) data
  71. /// which has local linkage.
  72. BSSLocal,
  73. /// BSSExtern - This is BSS data with normal external linkage.
  74. BSSExtern,
  75. /// Common - Data with common linkage. These represent tentative
  76. /// definitions, which always have a zero initializer and are never
  77. /// marked 'constant'.
  78. Common,
  79. /// DataRel - This is the most general form of data that is written
  80. /// to by the program, it can have random relocations to arbitrary
  81. /// globals.
  82. DataRel,
  83. /// DataRelLocal - This is writeable data that has a non-zero
  84. /// initializer and has relocations in it, but all of the
  85. /// relocations are known to be within the final linked image
  86. /// the global is linked into.
  87. DataRelLocal,
  88. /// DataNoRel - This is writeable data that has a non-zero
  89. /// initializer, but whose initializer is known to have no
  90. /// relocations.
  91. DataNoRel,
  92. /// ReadOnlyWithRel - These are global variables that are never
  93. /// written to by the program, but that have relocations, so they
  94. /// must be stuck in a writeable section so that the dynamic linker
  95. /// can write to them. If it chooses to, the dynamic linker can
  96. /// mark the pages these globals end up on as read-only after it is
  97. /// done with its relocation phase.
  98. ReadOnlyWithRel,
  99. /// ReadOnlyWithRelLocal - This is data that is readonly by the
  100. /// program, but must be writeable so that the dynamic linker
  101. /// can perform relocations in it. This is used when we know
  102. /// that all the relocations are to globals in this final
  103. /// linked image.
  104. ReadOnlyWithRelLocal
  105. } K : 8;
  106. public:
  107. bool isMetadata() const { return K == Metadata; }
  108. bool isText() const { return K == Text; }
  109. bool isReadOnly() const {
  110. return K == ReadOnly || isMergeableCString() ||
  111. isMergeableConst();
  112. }
  113. bool isMergeableCString() const {
  114. return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
  115. K == Mergeable4ByteCString;
  116. }
  117. bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
  118. bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
  119. bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
  120. bool isMergeableConst() const {
  121. return K == MergeableConst4 || K == MergeableConst8 ||
  122. K == MergeableConst16;
  123. }
  124. bool isMergeableConst4() const { return K == MergeableConst4; }
  125. bool isMergeableConst8() const { return K == MergeableConst8; }
  126. bool isMergeableConst16() const { return K == MergeableConst16; }
  127. bool isWriteable() const {
  128. return isThreadLocal() || isGlobalWriteableData();
  129. }
  130. bool isThreadLocal() const {
  131. return K == ThreadData || K == ThreadBSS;
  132. }
  133. bool isThreadBSS() const { return K == ThreadBSS; }
  134. bool isThreadData() const { return K == ThreadData; }
  135. bool isGlobalWriteableData() const {
  136. return isBSS() || isCommon() || isDataRel() || isReadOnlyWithRel();
  137. }
  138. bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; }
  139. bool isBSSLocal() const { return K == BSSLocal; }
  140. bool isBSSExtern() const { return K == BSSExtern; }
  141. bool isCommon() const { return K == Common; }
  142. bool isDataRel() const {
  143. return K == DataRel || K == DataRelLocal || K == DataNoRel;
  144. }
  145. bool isDataRelLocal() const {
  146. return K == DataRelLocal || K == DataNoRel;
  147. }
  148. bool isDataNoRel() const { return K == DataNoRel; }
  149. bool isReadOnlyWithRel() const {
  150. return K == ReadOnlyWithRel || K == ReadOnlyWithRelLocal;
  151. }
  152. bool isReadOnlyWithRelLocal() const {
  153. return K == ReadOnlyWithRelLocal;
  154. }
  155. private:
  156. static SectionKind get(Kind K) {
  157. SectionKind Res;
  158. Res.K = K;
  159. return Res;
  160. }
  161. public:
  162. static SectionKind getMetadata() { return get(Metadata); }
  163. static SectionKind getText() { return get(Text); }
  164. static SectionKind getReadOnly() { return get(ReadOnly); }
  165. static SectionKind getMergeable1ByteCString() {
  166. return get(Mergeable1ByteCString);
  167. }
  168. static SectionKind getMergeable2ByteCString() {
  169. return get(Mergeable2ByteCString);
  170. }
  171. static SectionKind getMergeable4ByteCString() {
  172. return get(Mergeable4ByteCString);
  173. }
  174. static SectionKind getMergeableConst4() { return get(MergeableConst4); }
  175. static SectionKind getMergeableConst8() { return get(MergeableConst8); }
  176. static SectionKind getMergeableConst16() { return get(MergeableConst16); }
  177. static SectionKind getThreadBSS() { return get(ThreadBSS); }
  178. static SectionKind getThreadData() { return get(ThreadData); }
  179. static SectionKind getBSS() { return get(BSS); }
  180. static SectionKind getBSSLocal() { return get(BSSLocal); }
  181. static SectionKind getBSSExtern() { return get(BSSExtern); }
  182. static SectionKind getCommon() { return get(Common); }
  183. static SectionKind getDataRel() { return get(DataRel); }
  184. static SectionKind getDataRelLocal() { return get(DataRelLocal); }
  185. static SectionKind getDataNoRel() { return get(DataNoRel); }
  186. static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
  187. static SectionKind getReadOnlyWithRelLocal(){
  188. return get(ReadOnlyWithRelLocal);
  189. }
  190. };
  191. } // end namespace llvm
  192. #endif