Remove duplicated code.
[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/MC/MCSection.h"
18
19 namespace llvm {
20
21 class MCSymbol;
22
23 /// MCSectionELF - This represents a section on linux, lots of unix variants
24 /// and some bare metal systems.
25 class MCSectionELF : public MCSection {
26   /// SectionName - This is the name of the section.  The referenced memory is
27   /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
28   StringRef SectionName;
29
30   /// Type - This is the sh_type field of a section, drawn from the enums below.
31   unsigned Type;
32
33   /// Flags - This is the sh_flags field of a section, drawn from the enums.
34   /// below.
35   unsigned Flags;
36
37   /// EntrySize - The size of each entry in this section. This size only
38   /// makes sense for sections that contain fixed-sized entries. If a
39   /// section does not contain fixed-sized entries 'EntrySize' will be 0.
40   unsigned EntrySize;
41
42   const MCSymbol *Group;
43
44 private:
45   friend class MCContext;
46   MCSectionELF(StringRef Section, unsigned type, unsigned flags,
47                SectionKind K, unsigned entrySize, const MCSymbol *group)
48     : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
49       EntrySize(entrySize), Group(group) {}
50   ~MCSectionELF();
51 public:
52
53   /// ShouldOmitSectionDirective - Decides whether a '.section' directive
54   /// should be printed before the section name
55   bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
56
57   /// HasCommonSymbols - True if this section holds common symbols, this is
58   /// indicated on the ELF object file by a symbol with SHN_COMMON section
59   /// header index.
60   bool HasCommonSymbols() const;
61
62   /// Valid section flags.
63   enum {
64     // The section contains data that should be writable.
65     SHF_WRITE            = 0x1U,
66
67     // The section occupies memory during execution.
68     SHF_ALLOC            = 0x2U,
69
70     // The section contains executable machine instructions.
71     SHF_EXECINSTR        = 0x4U,
72
73     // The data in the section may be merged to eliminate duplication.
74     SHF_MERGE            = 0x10U,
75
76     // Elements in the section consist of null-terminated character strings.
77     SHF_STRINGS          = 0x20U,
78
79     // A field in this section holds a section header table index.
80     SHF_INFO_LINK        = 0x40U,
81
82     // Adds special ordering requirements for link editors.
83     SHF_LINK_ORDER       = 0x80U,
84
85     // This section requires special OS-specific processing to avoid incorrect
86     // behavior.
87     SHF_OS_NONCONFORMING = 0x100U,
88
89     // This section is a member of a section group.
90     SHF_GROUP            = 0x200U,
91
92     // This section holds Thread-Local Storage.
93     SHF_TLS              = 0x400U,
94
95
96     // Start of target-specific flags.
97
98     /// XCORE_SHF_CP_SECTION - All sections with the "c" flag are grouped
99     /// together by the linker to form the constant pool and the cp register is
100     /// set to the start of the constant pool by the boot code.
101     XCORE_SHF_CP_SECTION = 0x800U,
102
103     /// XCORE_SHF_DP_SECTION - All sections with the "d" flag are grouped
104     /// together by the linker to form the data section and the dp register is
105     /// set to the start of the section by the boot code.
106     XCORE_SHF_DP_SECTION = 0x1000U
107   };
108
109   StringRef getSectionName() const { return SectionName; }
110   unsigned getType() const { return Type; }
111   unsigned getFlags() const { return Flags; }
112   unsigned getEntrySize() const { return EntrySize; }
113   const MCSymbol *getGroup() const { return Group; }
114
115   void PrintSwitchToSection(const MCAsmInfo &MAI,
116                             raw_ostream &OS) const;
117   virtual bool UseCodeAlign() const;
118   virtual bool isVirtualSection() const;
119
120   /// isBaseAddressKnownZero - We know that non-allocatable sections (like
121   /// debug info) have a base of zero.
122   virtual bool isBaseAddressKnownZero() const {
123     return (getFlags() & SHF_ALLOC) == 0;
124   }
125
126   static bool classof(const MCSection *S) {
127     return S->getVariant() == SV_ELF;
128   }
129   static bool classof(const MCSectionELF *) { return true; }
130
131   // Return the entry size for sections with fixed-width data.
132   static unsigned DetermineEntrySize(SectionKind Kind);
133
134 };
135
136 } // end namespace llvm
137
138 #endif