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