SectionKind.h 8.0 KB

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