1 //===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the MCSectionELF class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_MC_MCSECTIONELF_H
15 #define LLVM_MC_MCSECTIONELF_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"
26 /// This represents a section on linux, lots of unix variants and some bare
28 class MCSectionELF final : public MCSection {
29 /// This is the name of the section. The referenced memory is owned by
30 /// TargetLoweringObjectFileELF's ELFUniqueMap.
31 StringRef SectionName;
33 /// This is the sh_type field of a section, drawn from the enums below.
36 /// This is the sh_flags field of a section, drawn from the enums below.
41 /// The size of each entry in this section. This size only makes sense for
42 /// sections that contain fixed-sized entries. If a section does not contain
43 /// fixed-sized entries 'EntrySize' will be 0.
46 const MCSymbolELF *Group;
48 /// sh_info for SHF_LINK_ORDER (can be null).
49 const MCSymbol *AssociatedSymbol;
52 friend class MCContext;
54 MCSectionELF(StringRef Section, unsigned type, unsigned flags, SectionKind K,
55 unsigned entrySize, const MCSymbolELF *group, unsigned UniqueID,
56 MCSymbol *Begin, const MCSymbolELF *AssociatedSymbol)
57 : MCSection(SV_ELF, K, Begin), SectionName(Section), Type(type),
58 Flags(flags), UniqueID(UniqueID), EntrySize(entrySize), Group(group),
59 AssociatedSymbol(AssociatedSymbol) {
61 Group->setIsSignature();
64 void setSectionName(StringRef Name) { SectionName = Name; }
69 /// Decides whether a '.section' directive should be printed before the
71 bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
73 StringRef getSectionName() const { return SectionName; }
74 unsigned getType() const { return Type; }
75 unsigned getFlags() const { return Flags; }
76 unsigned getEntrySize() const { return EntrySize; }
77 void setFlags(unsigned F) { Flags = F; }
78 const MCSymbolELF *getGroup() const { return Group; }
80 void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
82 const MCExpr *Subsection) const override;
83 bool UseCodeAlign() const override;
84 bool isVirtualSection() const override;
86 bool isUnique() const { return UniqueID != ~0U; }
87 unsigned getUniqueID() const { return UniqueID; }
89 const MCSection *getAssociatedSection() const { return &AssociatedSymbol->getSection(); }
90 const MCSymbol *getAssociatedSymbol() const { return AssociatedSymbol; }
92 static bool classof(const MCSection *S) {
93 return S->getVariant() == SV_ELF;
97 } // end namespace llvm
99 #endif // LLVM_MC_MCSECTIONELF_H