MCSectionELF.h revision 2ff9e83a826c1c2ee0f1c6072d3d97d5b10678ee
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
19namespace llvm {
20
21class MCSymbol;
22
23/// MCSectionELF - This represents a section on linux, lots of unix variants
24/// and some bare metal systems.
25class 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
44private:
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();
51public:
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  /// These are the section type and flags fields.  An ELF section can have
63  /// only one Type, but can have more than one of the flags specified.
64  ///
65  /// Valid section types.
66  enum {
67    // This value marks the section header as inactive.
68    SHT_NULL             = 0x00U,
69
70    // Holds information defined by the program, with custom format and meaning.
71    SHT_PROGBITS         = 0x01U,
72
73    // This section holds a symbol table.
74    SHT_SYMTAB           = 0x02U,
75
76    // The section holds a string table.
77    SHT_STRTAB           = 0x03U,
78
79    // The section holds relocation entries with explicit addends.
80    SHT_RELA             = 0x04U,
81
82    // The section holds a symbol hash table.
83    SHT_HASH             = 0x05U,
84
85    // Information for dynamic linking.
86    SHT_DYNAMIC          = 0x06U,
87
88    // The section holds information that marks the file in some way.
89    SHT_NOTE             = 0x07U,
90
91    // A section of this type occupies no space in the file.
92    SHT_NOBITS           = 0x08U,
93
94    // The section holds relocation entries without explicit addends.
95    SHT_REL              = 0x09U,
96
97    // This section type is reserved but has unspecified semantics.
98    SHT_SHLIB            = 0x0AU,
99
100    // This section holds a symbol table.
101    SHT_DYNSYM           = 0x0BU,
102
103    // This section contains an array of pointers to initialization functions.
104    SHT_INIT_ARRAY       = 0x0EU,
105
106    // This section contains an array of pointers to termination functions.
107    SHT_FINI_ARRAY       = 0x0FU,
108
109    // This section contains an array of pointers to functions that are invoked
110    // before all other initialization functions.
111    SHT_PREINIT_ARRAY    = 0x10U,
112
113    // A section group is a set of sections that are related and that must be
114    // treated specially by the linker.
115    SHT_GROUP            = 0x11U,
116
117    // This section is associated with a section of type SHT_SYMTAB, when the
118    // referenced symbol table contain the escape value SHN_XINDEX
119    SHT_SYMTAB_SHNDX     = 0x12U,
120
121    // Start of target-specific flags.
122
123    // Exception Index table
124    SHT_ARM_EXIDX           = 0x70000001U,
125    // BPABI DLL dynamic linking pre-emption map
126    SHT_ARM_PREEMPTMAP      = 0x70000002U,
127    //  Object file compatibility attributes
128    SHT_ARM_ATTRIBUTES      = 0x70000003U,
129    SHT_ARM_DEBUGOVERLAY    = 0x70000004U,
130    SHT_ARM_OVERLAYSECTION  = 0x70000005U,
131
132    LAST_KNOWN_SECTION_TYPE = SHT_ARM_OVERLAYSECTION
133  };
134
135  /// Valid section flags.
136  enum {
137    // The section contains data that should be writable.
138    SHF_WRITE            = 0x1U,
139
140    // The section occupies memory during execution.
141    SHF_ALLOC            = 0x2U,
142
143    // The section contains executable machine instructions.
144    SHF_EXECINSTR        = 0x4U,
145
146    // The data in the section may be merged to eliminate duplication.
147    SHF_MERGE            = 0x10U,
148
149    // Elements in the section consist of null-terminated character strings.
150    SHF_STRINGS          = 0x20U,
151
152    // A field in this section holds a section header table index.
153    SHF_INFO_LINK        = 0x40U,
154
155    // Adds special ordering requirements for link editors.
156    SHF_LINK_ORDER       = 0x80U,
157
158    // This section requires special OS-specific processing to avoid incorrect
159    // behavior.
160    SHF_OS_NONCONFORMING = 0x100U,
161
162    // This section is a member of a section group.
163    SHF_GROUP            = 0x200U,
164
165    // This section holds Thread-Local Storage.
166    SHF_TLS              = 0x400U,
167
168
169    // Start of target-specific flags.
170
171    /// XCORE_SHF_CP_SECTION - All sections with the "c" flag are grouped
172    /// together by the linker to form the constant pool and the cp register is
173    /// set to the start of the constant pool by the boot code.
174    XCORE_SHF_CP_SECTION = 0x800U,
175
176    /// XCORE_SHF_DP_SECTION - All sections with the "d" flag are grouped
177    /// together by the linker to form the data section and the dp register is
178    /// set to the start of the section by the boot code.
179    XCORE_SHF_DP_SECTION = 0x1000U
180  };
181
182  StringRef getSectionName() const { return SectionName; }
183  unsigned getType() const { return Type; }
184  unsigned getFlags() const { return Flags; }
185  unsigned getEntrySize() const { return EntrySize; }
186  const MCSymbol *getGroup() const { return Group; }
187
188  void PrintSwitchToSection(const MCAsmInfo &MAI,
189                            raw_ostream &OS) const;
190  virtual bool UseCodeAlign() const;
191
192  /// isBaseAddressKnownZero - We know that non-allocatable sections (like
193  /// debug info) have a base of zero.
194  virtual bool isBaseAddressKnownZero() const {
195    return (getFlags() & SHF_ALLOC) == 0;
196  }
197
198  static bool classof(const MCSection *S) {
199    return S->getVariant() == SV_ELF;
200  }
201  static bool classof(const MCSectionELF *) { return true; }
202
203  // Return the entry size for sections with fixed-width data.
204  static unsigned DetermineEntrySize(SectionKind Kind);
205
206};
207
208} // end namespace llvm
209
210#endif
211