SectionKind.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. /// Exclude - This section will be excluded from the final executable or
  29. /// shared library. Only valid for ELF / COFF targets.
  30. Exclude,
  31. /// Text - Text section, used for functions and other executable code.
  32. Text,
  33. /// ExecuteOnly, Text section that is not readable.
  34. ExecuteOnly,
  35. /// ReadOnly - Data that is never written to at program runtime by the
  36. /// program or the dynamic linker. Things in the top-level readonly
  37. /// SectionKind are not mergeable.
  38. ReadOnly,
  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. /// Mergeable1ByteCString - 1 byte mergable, null terminated, string.
  44. Mergeable1ByteCString,
  45. /// Mergeable2ByteCString - 2 byte mergable, null terminated, string.
  46. Mergeable2ByteCString,
  47. /// Mergeable4ByteCString - 4 byte mergable, null terminated, string.
  48. Mergeable4ByteCString,
  49. /// MergeableConst - These are sections for merging fixed-length
  50. /// constants together. For example, this can be used to unique
  51. /// constant pool entries etc.
  52. /// MergeableConst4 - This is a section used by 4-byte constants,
  53. /// for example, floats.
  54. MergeableConst4,
  55. /// MergeableConst8 - This is a section used by 8-byte constants,
  56. /// for example, doubles.
  57. MergeableConst8,
  58. /// MergeableConst16 - This is a section used by 16-byte constants,
  59. /// for example, vectors.
  60. MergeableConst16,
  61. /// MergeableConst32 - This is a section used by 32-byte constants,
  62. /// for example, vectors.
  63. MergeableConst32,
  64. /// Writeable - This is the base of all segments that need to be written
  65. /// to during program runtime.
  66. /// ThreadLocal - This is the base of all TLS segments. All TLS
  67. /// objects must be writeable, otherwise there is no reason for them to
  68. /// be thread local!
  69. /// ThreadBSS - Zero-initialized TLS data objects.
  70. ThreadBSS,
  71. /// ThreadData - Initialized TLS data objects.
  72. ThreadData,
  73. /// ThreadBSSLocal - Zero-initialized TLS data objects with local linkage.
  74. ThreadBSSLocal,
  75. /// GlobalWriteableData - Writeable data that is global (not thread
  76. /// local).
  77. /// BSS - Zero initialized writeable data.
  78. BSS,
  79. /// BSSLocal - This is BSS (zero initialized and writable) data
  80. /// which has local linkage.
  81. BSSLocal,
  82. /// BSSExtern - This is BSS data with normal external linkage.
  83. BSSExtern,
  84. /// Common - Data with common linkage. These represent tentative
  85. /// definitions, which always have a zero initializer and are never
  86. /// marked 'constant'.
  87. Common,
  88. /// This is writeable data that has a non-zero initializer.
  89. Data,
  90. /// ReadOnlyWithRel - These are global variables that are never
  91. /// written to by the program, but that have relocations, so they
  92. /// must be stuck in a writeable section so that the dynamic linker
  93. /// can write to them. If it chooses to, the dynamic linker can
  94. /// mark the pages these globals end up on as read-only after it is
  95. /// done with its relocation phase.
  96. ReadOnlyWithRel
  97. } K : 8;
  98. public:
  99. bool isMetadata() const { return K == Metadata; }
  100. bool isExclude() const { return K == Exclude; }
  101. bool isText() const { return K == Text || K == ExecuteOnly; }
  102. bool isExecuteOnly() const { return K == ExecuteOnly; }
  103. bool isReadOnly() const {
  104. return K == ReadOnly || isMergeableCString() ||
  105. isMergeableConst();
  106. }
  107. bool isMergeableCString() const {
  108. return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
  109. K == Mergeable4ByteCString;
  110. }
  111. bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
  112. bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
  113. bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
  114. bool isMergeableConst() const {
  115. return K == MergeableConst4 || K == MergeableConst8 ||
  116. K == MergeableConst16 || K == MergeableConst32;
  117. }
  118. bool isMergeableConst4() const { return K == MergeableConst4; }
  119. bool isMergeableConst8() const { return K == MergeableConst8; }
  120. bool isMergeableConst16() const { return K == MergeableConst16; }
  121. bool isMergeableConst32() const { return K == MergeableConst32; }
  122. bool isWriteable() const {
  123. return isThreadLocal() || isGlobalWriteableData();
  124. }
  125. bool isThreadLocal() const {
  126. return K == ThreadData || K == ThreadBSS || K == ThreadBSSLocal;
  127. }
  128. bool isThreadBSS() const { return K == ThreadBSS || K == ThreadBSSLocal; }
  129. bool isThreadData() const { return K == ThreadData; }
  130. bool isThreadBSSLocal() const { return K == ThreadBSSLocal; }
  131. bool isGlobalWriteableData() const {
  132. return isBSS() || isCommon() || isData() || isReadOnlyWithRel();
  133. }
  134. bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; }
  135. bool isBSSLocal() const { return K == BSSLocal; }
  136. bool isBSSExtern() const { return K == BSSExtern; }
  137. bool isCommon() const { return K == Common; }
  138. bool isData() const { return K == Data; }
  139. bool isReadOnlyWithRel() const {
  140. return K == ReadOnlyWithRel;
  141. }
  142. private:
  143. static SectionKind get(Kind K) {
  144. SectionKind Res;
  145. Res.K = K;
  146. return Res;
  147. }
  148. public:
  149. static SectionKind getMetadata() { return get(Metadata); }
  150. static SectionKind getExclude() { return get(Exclude); }
  151. static SectionKind getText() { return get(Text); }
  152. static SectionKind getExecuteOnly() { return get(ExecuteOnly); }
  153. static SectionKind getReadOnly() { return get(ReadOnly); }
  154. static SectionKind getMergeable1ByteCString() {
  155. return get(Mergeable1ByteCString);
  156. }
  157. static SectionKind getMergeable2ByteCString() {
  158. return get(Mergeable2ByteCString);
  159. }
  160. static SectionKind getMergeable4ByteCString() {
  161. return get(Mergeable4ByteCString);
  162. }
  163. static SectionKind getMergeableConst4() { return get(MergeableConst4); }
  164. static SectionKind getMergeableConst8() { return get(MergeableConst8); }
  165. static SectionKind getMergeableConst16() { return get(MergeableConst16); }
  166. static SectionKind getMergeableConst32() { return get(MergeableConst32); }
  167. static SectionKind getThreadBSS() { return get(ThreadBSS); }
  168. static SectionKind getThreadData() { return get(ThreadData); }
  169. static SectionKind getThreadBSSLocal() { return get(ThreadBSSLocal); }
  170. static SectionKind getBSS() { return get(BSS); }
  171. static SectionKind getBSSLocal() { return get(BSSLocal); }
  172. static SectionKind getBSSExtern() { return get(BSSExtern); }
  173. static SectionKind getCommon() { return get(Common); }
  174. static SectionKind getData() { return get(Data); }
  175. static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
  176. };
  177. } // end namespace llvm
  178. #endif
  179. #ifdef __GNUC__
  180. #pragma GCC diagnostic pop
  181. #endif