1296417Sdim//===-- llvm/MC/SectionKind.h - Classification of sections ------*- C++ -*-===// 2198090Srdivacky// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6198090Srdivacky// 7198090Srdivacky//===----------------------------------------------------------------------===// 8198090Srdivacky 9198090Srdivacky#ifndef LLVM_MC_SECTIONKIND_H 10198090Srdivacky#define LLVM_MC_SECTIONKIND_H 11198090Srdivacky 12198090Srdivackynamespace llvm { 13198090Srdivacky 14198090Srdivacky/// SectionKind - This is a simple POD value that classifies the properties of 15198090Srdivacky/// a section. A section is classified into the deepest possible 16198090Srdivacky/// classification, and then the target maps them onto their sections based on 17198090Srdivacky/// what capabilities they have. 18198090Srdivacky/// 19198090Srdivacky/// The comments below describe these as if they were an inheritance hierarchy 20198090Srdivacky/// in order to explain the predicates below. 21198090Srdivacky/// 22198090Srdivackyclass SectionKind { 23198090Srdivacky enum Kind { 24198090Srdivacky /// Metadata - Debug info sections or other metadata. 25198090Srdivacky Metadata, 26210299Sed 27198090Srdivacky /// Text - Text section, used for functions and other executable code. 28198090Srdivacky Text, 29210299Sed 30314564Sdim /// ExecuteOnly, Text section that is not readable. 31314564Sdim ExecuteOnly, 32314564Sdim 33198090Srdivacky /// ReadOnly - Data that is never written to at program runtime by the 34198090Srdivacky /// program or the dynamic linker. Things in the top-level readonly 35198090Srdivacky /// SectionKind are not mergeable. 36198090Srdivacky ReadOnly, 37198090Srdivacky 38198090Srdivacky /// MergableCString - Any null-terminated string which allows merging. 39198090Srdivacky /// These values are known to end in a nul value of the specified size, 40198090Srdivacky /// not otherwise contain a nul value, and be mergable. This allows the 41198090Srdivacky /// linker to unique the strings if it so desires. 42198090Srdivacky 43198090Srdivacky /// Mergeable1ByteCString - 1 byte mergable, null terminated, string. 44198090Srdivacky Mergeable1ByteCString, 45210299Sed 46198090Srdivacky /// Mergeable2ByteCString - 2 byte mergable, null terminated, string. 47198090Srdivacky Mergeable2ByteCString, 48198090Srdivacky 49198090Srdivacky /// Mergeable4ByteCString - 4 byte mergable, null terminated, string. 50198090Srdivacky Mergeable4ByteCString, 51198090Srdivacky 52198090Srdivacky /// MergeableConst - These are sections for merging fixed-length 53198090Srdivacky /// constants together. For example, this can be used to unique 54198090Srdivacky /// constant pool entries etc. 55210299Sed 56198090Srdivacky /// MergeableConst4 - This is a section used by 4-byte constants, 57198090Srdivacky /// for example, floats. 58198090Srdivacky MergeableConst4, 59210299Sed 60198090Srdivacky /// MergeableConst8 - This is a section used by 8-byte constants, 61198090Srdivacky /// for example, doubles. 62198090Srdivacky MergeableConst8, 63198090Srdivacky 64198090Srdivacky /// MergeableConst16 - This is a section used by 16-byte constants, 65198090Srdivacky /// for example, vectors. 66198090Srdivacky MergeableConst16, 67210299Sed 68309124Sdim /// MergeableConst32 - This is a section used by 32-byte constants, 69309124Sdim /// for example, vectors. 70309124Sdim MergeableConst32, 71309124Sdim 72198090Srdivacky /// Writeable - This is the base of all segments that need to be written 73198090Srdivacky /// to during program runtime. 74210299Sed 75198090Srdivacky /// ThreadLocal - This is the base of all TLS segments. All TLS 76198090Srdivacky /// objects must be writeable, otherwise there is no reason for them to 77198090Srdivacky /// be thread local! 78210299Sed 79198090Srdivacky /// ThreadBSS - Zero-initialized TLS data objects. 80198090Srdivacky ThreadBSS, 81210299Sed 82198090Srdivacky /// ThreadData - Initialized TLS data objects. 83198090Srdivacky ThreadData, 84210299Sed 85198090Srdivacky /// GlobalWriteableData - Writeable data that is global (not thread 86198090Srdivacky /// local). 87210299Sed 88198090Srdivacky /// BSS - Zero initialized writeable data. 89198090Srdivacky BSS, 90210299Sed 91202878Srdivacky /// BSSLocal - This is BSS (zero initialized and writable) data 92202878Srdivacky /// which has local linkage. 93202878Srdivacky BSSLocal, 94210299Sed 95202878Srdivacky /// BSSExtern - This is BSS data with normal external linkage. 96202878Srdivacky BSSExtern, 97210299Sed 98202878Srdivacky /// Common - Data with common linkage. These represent tentative 99202878Srdivacky /// definitions, which always have a zero initializer and are never 100202878Srdivacky /// marked 'constant'. 101202878Srdivacky Common, 102198090Srdivacky 103296417Sdim /// This is writeable data that has a non-zero initializer. 104296417Sdim Data, 105198090Srdivacky 106198090Srdivacky /// ReadOnlyWithRel - These are global variables that are never 107198090Srdivacky /// written to by the program, but that have relocations, so they 108198090Srdivacky /// must be stuck in a writeable section so that the dynamic linker 109198090Srdivacky /// can write to them. If it chooses to, the dynamic linker can 110198090Srdivacky /// mark the pages these globals end up on as read-only after it is 111198090Srdivacky /// done with its relocation phase. 112296417Sdim ReadOnlyWithRel 113198090Srdivacky } K : 8; 114198090Srdivackypublic: 115210299Sed 116198090Srdivacky bool isMetadata() const { return K == Metadata; } 117210299Sed 118314564Sdim bool isText() const { return K == Text || K == ExecuteOnly; } 119314564Sdim 120314564Sdim bool isExecuteOnly() const { return K == ExecuteOnly; } 121314564Sdim 122198090Srdivacky bool isReadOnly() const { 123198090Srdivacky return K == ReadOnly || isMergeableCString() || 124198090Srdivacky isMergeableConst(); 125198090Srdivacky } 126198090Srdivacky 127198090Srdivacky bool isMergeableCString() const { 128198090Srdivacky return K == Mergeable1ByteCString || K == Mergeable2ByteCString || 129198090Srdivacky K == Mergeable4ByteCString; 130198090Srdivacky } 131198090Srdivacky bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; } 132198090Srdivacky bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; } 133198090Srdivacky bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; } 134210299Sed 135198090Srdivacky bool isMergeableConst() const { 136288943Sdim return K == MergeableConst4 || K == MergeableConst8 || 137309124Sdim K == MergeableConst16 || K == MergeableConst32; 138198090Srdivacky } 139198090Srdivacky bool isMergeableConst4() const { return K == MergeableConst4; } 140198090Srdivacky bool isMergeableConst8() const { return K == MergeableConst8; } 141198090Srdivacky bool isMergeableConst16() const { return K == MergeableConst16; } 142309124Sdim bool isMergeableConst32() const { return K == MergeableConst32; } 143210299Sed 144198090Srdivacky bool isWriteable() const { 145198090Srdivacky return isThreadLocal() || isGlobalWriteableData(); 146198090Srdivacky } 147210299Sed 148198090Srdivacky bool isThreadLocal() const { 149198090Srdivacky return K == ThreadData || K == ThreadBSS; 150198090Srdivacky } 151198090Srdivacky 152210299Sed bool isThreadBSS() const { return K == ThreadBSS; } 153210299Sed bool isThreadData() const { return K == ThreadData; } 154210299Sed 155198090Srdivacky bool isGlobalWriteableData() const { 156296417Sdim return isBSS() || isCommon() || isData() || isReadOnlyWithRel(); 157198090Srdivacky } 158210299Sed 159202878Srdivacky bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; } 160202878Srdivacky bool isBSSLocal() const { return K == BSSLocal; } 161202878Srdivacky bool isBSSExtern() const { return K == BSSExtern; } 162210299Sed 163202878Srdivacky bool isCommon() const { return K == Common; } 164210299Sed 165296417Sdim bool isData() const { return K == Data; } 166210299Sed 167198090Srdivacky bool isReadOnlyWithRel() const { 168296417Sdim return K == ReadOnlyWithRel; 169198090Srdivacky } 170210299Sedprivate: 171198090Srdivacky static SectionKind get(Kind K) { 172198090Srdivacky SectionKind Res; 173198090Srdivacky Res.K = K; 174198090Srdivacky return Res; 175198090Srdivacky } 176198090Srdivackypublic: 177210299Sed 178198090Srdivacky static SectionKind getMetadata() { return get(Metadata); } 179198090Srdivacky static SectionKind getText() { return get(Text); } 180314564Sdim static SectionKind getExecuteOnly() { return get(ExecuteOnly); } 181198090Srdivacky static SectionKind getReadOnly() { return get(ReadOnly); } 182198090Srdivacky static SectionKind getMergeable1ByteCString() { 183198090Srdivacky return get(Mergeable1ByteCString); 184198090Srdivacky } 185198090Srdivacky static SectionKind getMergeable2ByteCString() { 186198090Srdivacky return get(Mergeable2ByteCString); 187198090Srdivacky } 188198090Srdivacky static SectionKind getMergeable4ByteCString() { 189198090Srdivacky return get(Mergeable4ByteCString); 190198090Srdivacky } 191198090Srdivacky static SectionKind getMergeableConst4() { return get(MergeableConst4); } 192198090Srdivacky static SectionKind getMergeableConst8() { return get(MergeableConst8); } 193198090Srdivacky static SectionKind getMergeableConst16() { return get(MergeableConst16); } 194309124Sdim static SectionKind getMergeableConst32() { return get(MergeableConst32); } 195198090Srdivacky static SectionKind getThreadBSS() { return get(ThreadBSS); } 196198090Srdivacky static SectionKind getThreadData() { return get(ThreadData); } 197198090Srdivacky static SectionKind getBSS() { return get(BSS); } 198202878Srdivacky static SectionKind getBSSLocal() { return get(BSSLocal); } 199202878Srdivacky static SectionKind getBSSExtern() { return get(BSSExtern); } 200202878Srdivacky static SectionKind getCommon() { return get(Common); } 201296417Sdim static SectionKind getData() { return get(Data); } 202198090Srdivacky static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); } 203198090Srdivacky}; 204210299Sed 205198090Srdivacky} // end namespace llvm 206198090Srdivacky 207198090Srdivacky#endif 208