xref: /openbsd/gnu/llvm/llvm/include/llvm/MC/SectionKind.h (revision d415bd75)
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 
isMetadata()123   bool isMetadata() const { return K == Metadata; }
124 
isExclude()125   bool isExclude() const { return K == Exclude; }
126 
isText()127   bool isText() const { return K == Text || K == ExecuteOnly; }
128 
isExecuteOnly()129   bool isExecuteOnly() const { return K == ExecuteOnly; }
130 
isReadOnly()131   bool isReadOnly() const {
132     return K == ReadOnly || isMergeableCString() ||
133            isMergeableConst();
134   }
135 
isMergeableCString()136   bool isMergeableCString() const {
137     return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
138            K == Mergeable4ByteCString;
139   }
isMergeable1ByteCString()140   bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
isMergeable2ByteCString()141   bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
isMergeable4ByteCString()142   bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
143 
isMergeableConst()144   bool isMergeableConst() const {
145     return K == MergeableConst4 || K == MergeableConst8 ||
146            K == MergeableConst16 || K == MergeableConst32;
147   }
isMergeableConst4()148   bool isMergeableConst4() const { return K == MergeableConst4; }
isMergeableConst8()149   bool isMergeableConst8() const { return K == MergeableConst8; }
isMergeableConst16()150   bool isMergeableConst16() const { return K == MergeableConst16; }
isMergeableConst32()151   bool isMergeableConst32() const { return K == MergeableConst32; }
152 
isWriteable()153   bool isWriteable() const {
154     return isThreadLocal() || isGlobalWriteableData();
155   }
156 
isThreadLocal()157   bool isThreadLocal() const {
158     return K == ThreadData || K == ThreadBSS || K == ThreadBSSLocal;
159   }
160 
isThreadBSS()161   bool isThreadBSS() const { return K == ThreadBSS || K == ThreadBSSLocal; }
isThreadData()162   bool isThreadData() const { return K == ThreadData; }
isThreadBSSLocal()163   bool isThreadBSSLocal() const { return K == ThreadBSSLocal; }
164 
isGlobalWriteableData()165   bool isGlobalWriteableData() const {
166     return isBSS() || isCommon() || isData() || isReadOnlyWithRel();
167   }
168 
isBSS()169   bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; }
isBSSLocal()170   bool isBSSLocal() const { return K == BSSLocal; }
isBSSExtern()171   bool isBSSExtern() const { return K == BSSExtern; }
172 
isCommon()173   bool isCommon() const { return K == Common; }
174 
isData()175   bool isData() const { return K == Data; }
176 
isReadOnlyWithRel()177   bool isReadOnlyWithRel() const {
178     return K == ReadOnlyWithRel;
179   }
180 private:
get(Kind K)181   static SectionKind get(Kind K) {
182     SectionKind Res;
183     Res.K = K;
184     return Res;
185   }
186 public:
187 
getMetadata()188   static SectionKind getMetadata() { return get(Metadata); }
getExclude()189   static SectionKind getExclude() { return get(Exclude); }
getText()190   static SectionKind getText() { return get(Text); }
getExecuteOnly()191   static SectionKind getExecuteOnly() { return get(ExecuteOnly); }
getReadOnly()192   static SectionKind getReadOnly() { return get(ReadOnly); }
getMergeable1ByteCString()193   static SectionKind getMergeable1ByteCString() {
194     return get(Mergeable1ByteCString);
195   }
getMergeable2ByteCString()196   static SectionKind getMergeable2ByteCString() {
197     return get(Mergeable2ByteCString);
198   }
getMergeable4ByteCString()199   static SectionKind getMergeable4ByteCString() {
200     return get(Mergeable4ByteCString);
201   }
getMergeableConst4()202   static SectionKind getMergeableConst4() { return get(MergeableConst4); }
getMergeableConst8()203   static SectionKind getMergeableConst8() { return get(MergeableConst8); }
getMergeableConst16()204   static SectionKind getMergeableConst16() { return get(MergeableConst16); }
getMergeableConst32()205   static SectionKind getMergeableConst32() { return get(MergeableConst32); }
getThreadBSS()206   static SectionKind getThreadBSS() { return get(ThreadBSS); }
getThreadData()207   static SectionKind getThreadData() { return get(ThreadData); }
getThreadBSSLocal()208   static SectionKind getThreadBSSLocal() { return get(ThreadBSSLocal); }
getBSS()209   static SectionKind getBSS() { return get(BSS); }
getBSSLocal()210   static SectionKind getBSSLocal() { return get(BSSLocal); }
getBSSExtern()211   static SectionKind getBSSExtern() { return get(BSSExtern); }
getCommon()212   static SectionKind getCommon() { return get(Common); }
getData()213   static SectionKind getData() { return get(Data); }
getReadOnlyWithRel()214   static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
215 };
216 
217 } // end namespace llvm
218 
219 #endif
220