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