Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:16

0001 //===-- llvm/MC/SectionKind.h - Classification of sections ------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_MC_SECTIONKIND_H
0010 #define LLVM_MC_SECTIONKIND_H
0011 
0012 namespace llvm {
0013 
0014 /// SectionKind - This is a simple POD value that classifies the properties of
0015 /// a section.  A section is classified into the deepest possible
0016 /// classification, and then the target maps them onto their sections based on
0017 /// what capabilities they have.
0018 ///
0019 /// The comments below describe these as if they were an inheritance hierarchy
0020 /// in order to explain the predicates below.
0021 ///
0022 class SectionKind {
0023   enum Kind {
0024     /// Metadata - Debug info sections or other metadata.
0025     Metadata,
0026 
0027     /// Exclude - This section will be excluded from the final executable or
0028     /// shared library. Only valid for ELF / COFF targets.
0029     Exclude,
0030 
0031     /// Text - Text section, used for functions and other executable code.
0032     Text,
0033 
0034            /// ExecuteOnly, Text section that is not readable.
0035            ExecuteOnly,
0036 
0037     /// ReadOnly - Data that is never written to at program runtime by the
0038     /// program or the dynamic linker.  Things in the top-level readonly
0039     /// SectionKind are not mergeable.
0040     ReadOnly,
0041 
0042         /// MergableCString - Any null-terminated string which allows merging.
0043         /// These values are known to end in a nul value of the specified size,
0044         /// not otherwise contain a nul value, and be mergable.  This allows the
0045         /// linker to unique the strings if it so desires.
0046 
0047            /// Mergeable1ByteCString - 1 byte mergable, null terminated, string.
0048            Mergeable1ByteCString,
0049 
0050            /// Mergeable2ByteCString - 2 byte mergable, null terminated, string.
0051            Mergeable2ByteCString,
0052 
0053            /// Mergeable4ByteCString - 4 byte mergable, null terminated, string.
0054            Mergeable4ByteCString,
0055 
0056         /// MergeableConst - These are sections for merging fixed-length
0057         /// constants together.  For example, this can be used to unique
0058         /// constant pool entries etc.
0059 
0060             /// MergeableConst4 - This is a section used by 4-byte constants,
0061             /// for example, floats.
0062             MergeableConst4,
0063 
0064             /// MergeableConst8 - This is a section used by 8-byte constants,
0065             /// for example, doubles.
0066             MergeableConst8,
0067 
0068             /// MergeableConst16 - This is a section used by 16-byte constants,
0069             /// for example, vectors.
0070             MergeableConst16,
0071 
0072             /// MergeableConst32 - This is a section used by 32-byte constants,
0073             /// for example, vectors.
0074             MergeableConst32,
0075 
0076     /// Writeable - This is the base of all segments that need to be written
0077     /// to during program runtime.
0078 
0079        /// ThreadLocal - This is the base of all TLS segments.  All TLS
0080        /// objects must be writeable, otherwise there is no reason for them to
0081        /// be thread local!
0082 
0083            /// ThreadBSS - Zero-initialized TLS data objects.
0084            ThreadBSS,
0085 
0086            /// ThreadData - Initialized TLS data objects.
0087            ThreadData,
0088 
0089            /// ThreadBSSLocal - Zero-initialized TLS data objects with local linkage.
0090            ThreadBSSLocal,
0091 
0092        /// GlobalWriteableData - Writeable data that is global (not thread
0093        /// local).
0094 
0095            /// BSS - Zero initialized writeable data.
0096            BSS,
0097 
0098                /// BSSLocal - This is BSS (zero initialized and writable) data
0099                /// which has local linkage.
0100                BSSLocal,
0101 
0102                /// BSSExtern - This is BSS data with normal external linkage.
0103                BSSExtern,
0104 
0105            /// Common - Data with common linkage.  These represent tentative
0106            /// definitions, which always have a zero initializer and are never
0107            /// marked 'constant'.
0108            Common,
0109 
0110            /// This is writeable data that has a non-zero initializer.
0111            Data,
0112 
0113            /// ReadOnlyWithRel - These are global variables that are never
0114            /// written to by the program, but that have relocations, so they
0115            /// must be stuck in a writeable section so that the dynamic linker
0116            /// can write to them.  If it chooses to, the dynamic linker can
0117            /// mark the pages these globals end up on as read-only after it is
0118            /// done with its relocation phase.
0119            ReadOnlyWithRel
0120   } K : 8;
0121 public:
0122 
0123   bool isMetadata() const { return K == Metadata; }
0124 
0125   bool isExclude() const { return K == Exclude; }
0126 
0127   bool isText() const { return K == Text || K == ExecuteOnly; }
0128 
0129   bool isExecuteOnly() const { return K == ExecuteOnly; }
0130 
0131   bool isReadOnly() const {
0132     return K == ReadOnly || isMergeableCString() ||
0133            isMergeableConst();
0134   }
0135 
0136   bool isMergeableCString() const {
0137     return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
0138            K == Mergeable4ByteCString;
0139   }
0140   bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
0141   bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
0142   bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
0143 
0144   bool isMergeableConst() const {
0145     return K == MergeableConst4 || K == MergeableConst8 ||
0146            K == MergeableConst16 || K == MergeableConst32;
0147   }
0148   bool isMergeableConst4() const { return K == MergeableConst4; }
0149   bool isMergeableConst8() const { return K == MergeableConst8; }
0150   bool isMergeableConst16() const { return K == MergeableConst16; }
0151   bool isMergeableConst32() const { return K == MergeableConst32; }
0152 
0153   bool isWriteable() const {
0154     return isThreadLocal() || isGlobalWriteableData();
0155   }
0156 
0157   bool isThreadLocal() const {
0158     return K == ThreadData || K == ThreadBSS || K == ThreadBSSLocal;
0159   }
0160 
0161   bool isThreadBSS() const { return K == ThreadBSS || K == ThreadBSSLocal; }
0162   bool isThreadData() const { return K == ThreadData; }
0163   bool isThreadBSSLocal() const { return K == ThreadBSSLocal; }
0164 
0165   bool isGlobalWriteableData() const {
0166     return isBSS() || isCommon() || isData() || isReadOnlyWithRel();
0167   }
0168 
0169   bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; }
0170   bool isBSSLocal() const { return K == BSSLocal; }
0171   bool isBSSExtern() const { return K == BSSExtern; }
0172 
0173   bool isCommon() const { return K == Common; }
0174 
0175   bool isData() const { return K == Data; }
0176 
0177   bool isReadOnlyWithRel() const {
0178     return K == ReadOnlyWithRel;
0179   }
0180 private:
0181   static SectionKind get(Kind K) {
0182     SectionKind Res;
0183     Res.K = K;
0184     return Res;
0185   }
0186 public:
0187 
0188   static SectionKind getMetadata() { return get(Metadata); }
0189   static SectionKind getExclude() { return get(Exclude); }
0190   static SectionKind getText() { return get(Text); }
0191   static SectionKind getExecuteOnly() { return get(ExecuteOnly); }
0192   static SectionKind getReadOnly() { return get(ReadOnly); }
0193   static SectionKind getMergeable1ByteCString() {
0194     return get(Mergeable1ByteCString);
0195   }
0196   static SectionKind getMergeable2ByteCString() {
0197     return get(Mergeable2ByteCString);
0198   }
0199   static SectionKind getMergeable4ByteCString() {
0200     return get(Mergeable4ByteCString);
0201   }
0202   static SectionKind getMergeableConst4() { return get(MergeableConst4); }
0203   static SectionKind getMergeableConst8() { return get(MergeableConst8); }
0204   static SectionKind getMergeableConst16() { return get(MergeableConst16); }
0205   static SectionKind getMergeableConst32() { return get(MergeableConst32); }
0206   static SectionKind getThreadBSS() { return get(ThreadBSS); }
0207   static SectionKind getThreadData() { return get(ThreadData); }
0208   static SectionKind getThreadBSSLocal() { return get(ThreadBSSLocal); }
0209   static SectionKind getBSS() { return get(BSS); }
0210   static SectionKind getBSSLocal() { return get(BSSLocal); }
0211   static SectionKind getBSSExtern() { return get(BSSExtern); }
0212   static SectionKind getCommon() { return get(Common); }
0213   static SectionKind getData() { return get(Data); }
0214   static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
0215 };
0216 
0217 } // end namespace llvm
0218 
0219 #endif