6d864b4a45be310f6d0a8c55faa71dd51cbd06ef
[oota-llvm.git] / include / llvm / MC / MCSectionELF.h
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/Twine.h"
18 #include "llvm/MC/MCSection.h"
19 #include "llvm/MC/MCSymbol.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Support/ELF.h"
22 #include "llvm/Support/raw_ostream.h"
23
24 namespace llvm {
25
26 class MCSymbol;
27
28 /// MCSectionELF - This represents a section on linux, lots of unix variants
29 /// and some bare metal systems.
30 class MCSectionELF : public MCSection {
31   /// SectionName - This is the name of the section.  The referenced memory is
32   /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
33   StringRef SectionName;
34
35   /// Type - This is the sh_type field of a section, drawn from the enums below.
36   unsigned Type;
37
38   /// Flags - This is the sh_flags field of a section, drawn from the enums.
39   /// below.
40   unsigned Flags;
41
42   bool Unique;
43
44   /// EntrySize - The size of each entry in this section. This size only
45   /// makes sense for sections that contain fixed-sized entries. If a
46   /// section does not contain fixed-sized entries 'EntrySize' will be 0.
47   unsigned EntrySize;
48
49   const MCSymbol *Group;
50
51 private:
52   friend class MCContext;
53   MCSectionELF(StringRef Section, unsigned type, unsigned flags, SectionKind K,
54                unsigned entrySize, const MCSymbol *group, bool Unique)
55       : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
56         Unique(Unique), EntrySize(entrySize), Group(group) {}
57   ~MCSectionELF();
58
59   void setSectionName(StringRef Name) { SectionName = Name; }
60
61 public:
62
63   /// ShouldOmitSectionDirective - Decides whether a '.section' directive
64   /// should be printed before the section name
65   bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
66
67   StringRef getSectionName() const { return SectionName; }
68   std::string getLabelBeginName() const override {
69     if (Group)
70       return (SectionName.str() + '_' + Group->getName() + "_begin").str();
71     return SectionName.str() + "_begin";
72   }
73   std::string getLabelEndName() const override {
74     if (Group)
75       return (SectionName.str() + '_' + Group->getName() + "_end").str();
76     return SectionName.str() + "_end";
77   }
78   unsigned getType() const { return Type; }
79   unsigned getFlags() const { return Flags; }
80   unsigned getEntrySize() const { return EntrySize; }
81   const MCSymbol *getGroup() const { return Group; }
82
83   void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
84                             const MCExpr *Subsection) const override;
85   bool UseCodeAlign() const override;
86   bool isVirtualSection() const override;
87
88   /// isBaseAddressKnownZero - We know that non-allocatable sections (like
89   /// debug info) have a base of zero.
90   bool isBaseAddressKnownZero() const override {
91     return (getFlags() & ELF::SHF_ALLOC) == 0;
92   }
93
94   static bool classof(const MCSection *S) {
95     return S->getVariant() == SV_ELF;
96   }
97 };
98
99 } // end namespace llvm
100
101 #endif