SectionKind.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. //===-- llvm/MC/SectionKind.h - Classification of sections ------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_MC_SECTIONKIND_H
  9. #define LLVM_MC_SECTIONKIND_H
  10. namespace llvm {
  11. /// SectionKind - This is a simple POD value that classifies the properties of
  12. /// a section. A section is classified into the deepest possible
  13. /// classification, and then the target maps them onto their sections based on
  14. /// what capabilities they have.
  15. ///
  16. /// The comments below describe these as if they were an inheritance hierarchy
  17. /// in order to explain the predicates below.
  18. ///
  19. class SectionKind {
  20. enum Kind {
  21. /// Metadata - Debug info sections or other metadata.
  22. Metadata,
  23. /// Text - Text section, used for functions and other executable code.
  24. Text,
  25. /// ExecuteOnly, Text section that is not readable.
  26. ExecuteOnly,
  27. /// ReadOnly - Data that is never written to at program runtime by the
  28. /// program or the dynamic linker. Things in the top-level readonly
  29. /// SectionKind are not mergeable.
  30. ReadOnly,
  31. /// MergableCString - Any null-terminated string which allows merging.
  32. /// These values are known to end in a nul value of the specified size,
  33. /// not otherwise contain a nul value, and be mergable. This allows the
  34. /// linker to unique the strings if it so desires.
  35. /// Mergeable1ByteCString - 1 byte mergable, null terminated, string.
  36. Mergeable1ByteCString,
  37. /// Mergeable2ByteCString - 2 byte mergable, null terminated, string.
  38. Mergeable2ByteCString,
  39. /// Mergeable4ByteCString - 4 byte mergable, null terminated, string.
  40. Mergeable4ByteCString,
  41. /// MergeableConst - These are sections for merging fixed-length
  42. /// constants together. For example, this can be used to unique
  43. /// constant pool entries etc.
  44. /// MergeableConst4 - This is a section used by 4-byte constants,
  45. /// for example, floats.
  46. MergeableConst4,
  47. /// MergeableConst8 - This is a section used by 8-byte constants,
  48. /// for example, doubles.
  49. MergeableConst8,
  50. /// MergeableConst16 - This is a section used by 16-byte constants,
  51. /// for example, vectors.
  52. MergeableConst16,
  53. /// MergeableConst32 - This is a section used by 32-byte constants,
  54. /// for example, vectors.
  55. MergeableConst32,
  56. /// Writeable - This is the base of all segments that need to be written
  57. /// to during program runtime.
  58. /// ThreadLocal - This is the base of all TLS segments. All TLS
  59. /// objects must be writeable, otherwise there is no reason for them to
  60. /// be thread local!
  61. /// ThreadBSS - Zero-initialized TLS data objects.
  62. ThreadBSS,
  63. /// ThreadData - Initialized TLS data objects.
  64. ThreadData,
  65. /// ThreadBSSLocal - Zero-initialized TLS data objects with local linkage.
  66. ThreadBSSLocal,
  67. /// GlobalWriteableData - Writeable data that is global (not thread
  68. /// local).
  69. /// BSS - Zero initialized writeable data.
  70. BSS,
  71. /// BSSLocal - This is BSS (zero initialized and writable) data
  72. /// which has local linkage.
  73. BSSLocal,
  74. /// BSSExtern - This is BSS data with normal external linkage.
  75. BSSExtern,
  76. /// Common - Data with common linkage. These represent tentative
  77. /// definitions, which always have a zero initializer and are never
  78. /// marked 'constant'.
  79. Common,
  80. /// This is writeable data that has a non-zero initializer.
  81. Data,
  82. /// ReadOnlyWithRel - These are global variables that are never
  83. /// written to by the program, but that have relocations, so they
  84. /// must be stuck in a writeable section so that the dynamic linker
  85. /// can write to them. If it chooses to, the dynamic linker can
  86. /// mark the pages these globals end up on as read-only after it is
  87. /// done with its relocation phase.
  88. ReadOnlyWithRel
  89. } K : 8;
  90. public:
  91. bool isMetadata() const { return K == Metadata; }
  92. bool isText() const { return K == Text || K == ExecuteOnly; }
  93. bool isExecuteOnly() const { return K == ExecuteOnly; }
  94. bool isReadOnly() const {
  95. return K == ReadOnly || isMergeableCString() ||
  96. isMergeableConst();
  97. }
  98. bool isMergeableCString() const {
  99. return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
  100. K == Mergeable4ByteCString;
  101. }
  102. bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
  103. bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
  104. bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
  105. bool isMergeableConst() const {
  106. return K == MergeableConst4 || K == MergeableConst8 ||
  107. K == MergeableConst16 || K == MergeableConst32;
  108. }
  109. bool isMergeableConst4() const { return K == MergeableConst4; }
  110. bool isMergeableConst8() const { return K == MergeableConst8; }
  111. bool isMergeableConst16() const { return K == MergeableConst16; }
  112. bool isMergeableConst32() const { return K == MergeableConst32; }
  113. bool isWriteable() const {
  114. return isThreadLocal() || isGlobalWriteableData();
  115. }
  116. bool isThreadLocal() const {
  117. return K == ThreadData || K == ThreadBSS || K == ThreadBSSLocal;
  118. }
  119. bool isThreadBSS() const { return K == ThreadBSS || K == ThreadBSSLocal; }
  120. bool isThreadData() const { return K == ThreadData; }
  121. bool isThreadBSSLocal() const { return K == ThreadBSSLocal; }
  122. bool isGlobalWriteableData() const {
  123. return isBSS() || isCommon() || isData() || isReadOnlyWithRel();
  124. }
  125. bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; }
  126. bool isBSSLocal() const { return K == BSSLocal; }
  127. bool isBSSExtern() const { return K == BSSExtern; }
  128. bool isCommon() const { return K == Common; }
  129. bool isData() const { return K == Data; }
  130. bool isReadOnlyWithRel() const {
  131. return K == ReadOnlyWithRel;
  132. }
  133. private:
  134. static SectionKind get(Kind K) {
  135. SectionKind Res;
  136. Res.K = K;
  137. return Res;
  138. }
  139. public:
  140. static SectionKind getMetadata() { return get(Metadata); }
  141. static SectionKind getText() { return get(Text); }
  142. static SectionKind getExecuteOnly() { return get(ExecuteOnly); }
  143. static SectionKind getReadOnly() { return get(ReadOnly); }
  144. static SectionKind getMergeable1ByteCString() {
  145. return get(Mergeable1ByteCString);
  146. }
  147. static SectionKind getMergeable2ByteCString() {
  148. return get(Mergeable2ByteCString);
  149. }
  150. static SectionKind getMergeable4ByteCString() {
  151. return get(Mergeable4ByteCString);
  152. }
  153. static SectionKind getMergeableConst4() { return get(MergeableConst4); }
  154. static SectionKind getMergeableConst8() { return get(MergeableConst8); }
  155. static SectionKind getMergeableConst16() { return get(MergeableConst16); }
  156. static SectionKind getMergeableConst32() { return get(MergeableConst32); }
  157. static SectionKind getThreadBSS() { return get(ThreadBSS); }
  158. static SectionKind getThreadData() { return get(ThreadData); }
  159. static SectionKind getThreadBSSLocal() { return get(ThreadBSSLocal); }
  160. static SectionKind getBSS() { return get(BSS); }
  161. static SectionKind getBSSLocal() { return get(BSSLocal); }
  162. static SectionKind getBSSExtern() { return get(BSSExtern); }
  163. static SectionKind getCommon() { return get(Common); }
  164. static SectionKind getData() { return get(Data); }
  165. static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
  166. };
  167. } // end namespace llvm
  168. #endif