1 //===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the MCSectionELF class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_MC_MCSECTIONELF_H
15 #define LLVM_MC_MCSECTIONELF_H
16 
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 
22 namespace llvm {
23 
24 class MCSymbol;
25 
26 /// This represents a section on linux, lots of unix variants and some bare
27 /// metal systems.
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;
32 
33   /// This is the sh_type field of a section, drawn from the enums below.
34   unsigned Type;
35 
36   /// This is the sh_flags field of a section, drawn from the enums below.
37   unsigned Flags;
38 
39   unsigned UniqueID;
40 
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.
44   unsigned EntrySize;
45 
46   const MCSymbolELF *Group;
47 
48   /// sh_info for SHF_LINK_ORDER (can be null).
49   const MCSymbol *AssociatedSymbol;
50 
51 private:
52   friend class MCContext;
53 
MCSectionELF(StringRef Section,unsigned type,unsigned flags,SectionKind K,unsigned entrySize,const MCSymbolELF * group,unsigned UniqueID,MCSymbol * Begin,const MCSymbolELF * AssociatedSymbol)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) {
60     if (Group)
61       Group->setIsSignature();
62   }
63 
setSectionName(StringRef Name)64   void setSectionName(StringRef Name) { SectionName = Name; }
65 
66 public:
67   ~MCSectionELF();
68 
69   /// Decides whether a '.section' directive should be printed before the
70   /// section name
71   bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
72 
getSectionName()73   StringRef getSectionName() const { return SectionName; }
getType()74   unsigned getType() const { return Type; }
getFlags()75   unsigned getFlags() const { return Flags; }
getEntrySize()76   unsigned getEntrySize() const { return EntrySize; }
setFlags(unsigned F)77   void setFlags(unsigned F) { Flags = F; }
getGroup()78   const MCSymbolELF *getGroup() const { return Group; }
79 
80   void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
81                             raw_ostream &OS,
82                             const MCExpr *Subsection) const override;
83   bool UseCodeAlign() const override;
84   bool isVirtualSection() const override;
85 
isUnique()86   bool isUnique() const { return UniqueID != ~0U; }
getUniqueID()87   unsigned getUniqueID() const { return UniqueID; }
88 
getAssociatedSection()89   const MCSection *getAssociatedSection() const { return &AssociatedSymbol->getSection(); }
getAssociatedSymbol()90   const MCSymbol *getAssociatedSymbol() const { return AssociatedSymbol; }
91 
classof(const MCSection * S)92   static bool classof(const MCSection *S) {
93     return S->getVariant() == SV_ELF;
94   }
95 };
96 
97 } // end namespace llvm
98 
99 #endif // LLVM_MC_MCSECTIONELF_H
100