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