1//===- MCSectionELF.h - ELF Machine Code 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// This file declares the MCSectionELF class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_MC_MCSECTIONELF_H
14#define LLVM_MC_MCSECTIONELF_H
15
16#include "llvm/ADT/PointerIntPair.h"
17#include "llvm/ADT/StringRef.h"
18#include "llvm/MC/MCSection.h"
19#include "llvm/MC/MCSymbolELF.h"
20#include "llvm/MC/SectionKind.h"
21
22namespace llvm {
23
24/// This represents a section on linux, lots of unix variants and some bare
25/// metal systems.
26class MCSectionELF final : public MCSection {
27 /// This is the sh_type field of a section, drawn from the enums below.
28 unsigned Type;
29
30 /// This is the sh_flags field of a section, drawn from the enums below.
31 unsigned Flags;
32
33 unsigned UniqueID;
34
35 /// The size of each entry in this section. This size only makes sense for
36 /// sections that contain fixed-sized entries. If a section does not contain
37 /// fixed-sized entries 'EntrySize' will be 0.
38 unsigned EntrySize;
39
40 /// The section group signature symbol (if not null) and a bool indicating
41 /// whether this is a GRP_COMDAT group.
42 const PointerIntPair<const MCSymbolELF *, 1, bool> Group;
43
44 /// Used by SHF_LINK_ORDER. If non-null, the sh_link field will be set to the
45 /// section header index of the section where LinkedToSym is defined.
46 const MCSymbol *LinkedToSym;
47
48private:
49 friend class MCContext;
50
51 // The storage of Name is owned by MCContext's ELFUniquingMap.
52 MCSectionELF(StringRef Name, unsigned type, unsigned flags, SectionKind K,
53 unsigned entrySize, const MCSymbolELF *group, bool IsComdat,
54 unsigned UniqueID, MCSymbol *Begin,
55 const MCSymbolELF *LinkedToSym)
56 : MCSection(SV_ELF, Name, K, Begin), Type(type), Flags(flags),
57 UniqueID(UniqueID), EntrySize(entrySize), Group(group, IsComdat),
58 LinkedToSym(LinkedToSym) {
59 if (Group.getPointer())
60 Group.getPointer()->setIsSignature();
61 }
62
63 // TODO Delete after we stop supporting generation of GNU-style .zdebug_*
64 // sections.
65 void setSectionName(StringRef Name) { this->Name = Name; }
66
67public:
68 /// Decides whether a '.section' directive should be printed before the
69 /// section name
70 bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
71
72 unsigned getType() const { return Type; }
73 unsigned getFlags() const { return Flags; }
74 unsigned getEntrySize() const { return EntrySize; }
75 void setFlags(unsigned F) { Flags = F; }
76 const MCSymbolELF *getGroup() const { return Group.getPointer(); }
77 bool isComdat() const { return Group.getInt(); }
78
79 void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
80 raw_ostream &OS,
81 const MCExpr *Subsection) const override;
82 bool useCodeAlign() const override;
83 bool isVirtualSection() const override;
84 StringRef getVirtualSectionKind() const override;
85
86 bool isUnique() const { return UniqueID != NonUniqueID; }
87 unsigned getUniqueID() const { return UniqueID; }
88
89 const MCSection *getLinkedToSection() const {
90 return &LinkedToSym->getSection();
91 }
92 const MCSymbol *getLinkedToSymbol() const { return LinkedToSym; }
93
94 static bool classof(const MCSection *S) {
95 return S->getVariant() == SV_ELF;
96 }
97};
98
99} // end namespace llvm
100
101#endif // LLVM_MC_MCSECTIONELF_H
102

source code of llvm/include/llvm/MC/MCSectionELF.h