MCSectionELF.h revision 083cf1574facc9ce468fba1735c794bd7e520108
1f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project//===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
2f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project//
3f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project//                     The LLVM Compiler Infrastructure
4f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project//
5f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project// This file is distributed under the University of Illinois Open Source
6f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project// License. See LICENSE.TXT for details.
7f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project//
8f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project//===----------------------------------------------------------------------===//
9f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project//
10f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project// This file declares the MCSectionELF class.
11f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project//
12f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project//===----------------------------------------------------------------------===//
13f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
14f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#ifndef LLVM_MC_MCSECTIONELF_H
15f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define LLVM_MC_MCSECTIONELF_H
16f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
17f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#include "llvm/MC/MCSection.h"
18f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
19f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectnamespace llvm {
20f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
21f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/// MCSectionELF - This represents a section on linux, lots of unix variants
2259a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden/// and some bare metal systems.
2359a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFaddenclass MCSectionELF : public MCSection {
2459a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  /// SectionName - This is the name of the section.  The referenced memory is
2559a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
2659a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  StringRef SectionName;
27f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
28f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  /// Type - This is the sh_type field of a section, drawn from the enums below.
29f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  unsigned Type;
30f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
31f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  /// Flags - This is the sh_flags field of a section, drawn from the enums.
32f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  /// below.
33f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  unsigned Flags;
34f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
35f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  /// IsExplicit - Indicates that this section comes from globals with an
36f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  /// explicit section specified.
37f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  bool IsExplicit;
38f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
39f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  /// EntrySize - The size of each entry in this section. This size only
40f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  /// makes sense for sections that contain fixed-sized entries. If a
41f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  /// section does not contain fixed-sized entries 'EntrySize' will be 0.
42f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  unsigned EntrySize;
43f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
44f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectprivate:
45f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  friend class MCContext;
46f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  MCSectionELF(StringRef Section, unsigned type, unsigned flags,
47f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project               SectionKind K, bool isExplicit, unsigned entrySize)
48f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
49f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project      IsExplicit(isExplicit), EntrySize(entrySize) {}
50f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  ~MCSectionELF();
51f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectpublic:
52f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
53f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  /// ShouldOmitSectionDirective - Decides whether a '.section' directive
54f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  /// should be printed before the section name
55f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project  bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
56f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
5759a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  /// ShouldPrintSectionType - Only prints the section type if supported
5859a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  bool ShouldPrintSectionType(unsigned Ty) const;
5959a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden
6059a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  /// HasCommonSymbols - True if this section holds common symbols, this is
6159a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  /// indicated on the ELF object file by a symbol with SHN_COMMON section
6259a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  /// header index.
6359a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  bool HasCommonSymbols() const;
6459a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden
6559a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  /// These are the section type and flags fields.  An ELF section can have
6659a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  /// only one Type, but can have more than one of the flags specified.
6759a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  ///
6859a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  /// Valid section types.
6959a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden  enum {
7059a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden    // This value marks the section header as inactive.
7159a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden    SHT_NULL             = 0x00U,
7259a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden
7359a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden    // Holds information defined by the program, with custom format and meaning.
7459a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden    SHT_PROGBITS         = 0x01U,
7559a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden
7659a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden    // This section holds a symbol table.
7759a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden    SHT_SYMTAB           = 0x02U,
7859a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden
7959a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden    // The section holds a string table.
8059a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden    SHT_STRTAB           = 0x03U,
8159a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden
8259a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden    // The section holds relocation entries with explicit addends.
8359a434629ba06d4decf7bc88a62ae370a1935f0eAndy McFadden    SHT_RELA             = 0x04U,
84f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
85    // The section holds a symbol hash table.
86    SHT_HASH             = 0x05U,
87
88    // Information for dynamic linking.
89    SHT_DYNAMIC          = 0x06U,
90
91    // The section holds information that marks the file in some way.
92    SHT_NOTE             = 0x07U,
93
94    // A section of this type occupies no space in the file.
95    SHT_NOBITS           = 0x08U,
96
97    // The section holds relocation entries without explicit addends.
98    SHT_REL              = 0x09U,
99
100    // This section type is reserved but has unspecified semantics.
101    SHT_SHLIB            = 0x0AU,
102
103    // This section holds a symbol table.
104    SHT_DYNSYM           = 0x0BU,
105
106    // This section contains an array of pointers to initialization functions.
107    SHT_INIT_ARRAY       = 0x0EU,
108
109    // This section contains an array of pointers to termination functions.
110    SHT_FINI_ARRAY       = 0x0FU,
111
112    // This section contains an array of pointers to functions that are invoked
113    // before all other initialization functions.
114    SHT_PREINIT_ARRAY    = 0x10U,
115
116    // A section group is a set of sections that are related and that must be
117    // treated specially by the linker.
118    SHT_GROUP            = 0x11U,
119
120    // This section is associated with a section of type SHT_SYMTAB, when the
121    // referenced symbol table contain the escape value SHN_XINDEX
122    SHT_SYMTAB_SHNDX     = 0x12U,
123
124    LAST_KNOWN_SECTION_TYPE = SHT_SYMTAB_SHNDX
125  };
126
127  /// Valid section flags.
128  enum {
129    // The section contains data that should be writable.
130    SHF_WRITE            = 0x1U,
131
132    // The section occupies memory during execution.
133    SHF_ALLOC            = 0x2U,
134
135    // The section contains executable machine instructions.
136    SHF_EXECINSTR        = 0x4U,
137
138    // The data in the section may be merged to eliminate duplication.
139    SHF_MERGE            = 0x10U,
140
141    // Elements in the section consist of null-terminated character strings.
142    SHF_STRINGS          = 0x20U,
143
144    // A field in this section holds a section header table index.
145    SHF_INFO_LINK        = 0x40U,
146
147    // Adds special ordering requirements for link editors.
148    SHF_LINK_ORDER       = 0x80U,
149
150    // This section requires special OS-specific processing to avoid incorrect
151    // behavior.
152    SHF_OS_NONCONFORMING = 0x100U,
153
154    // This section is a member of a section group.
155    SHF_GROUP            = 0x200U,
156
157    // This section holds Thread-Local Storage.
158    SHF_TLS              = 0x400U,
159
160
161    // Start of target-specific flags.
162
163    /// XCORE_SHF_CP_SECTION - All sections with the "c" flag are grouped
164    /// together by the linker to form the constant pool and the cp register is
165    /// set to the start of the constant pool by the boot code.
166    XCORE_SHF_CP_SECTION = 0x800U,
167
168    /// XCORE_SHF_DP_SECTION - All sections with the "d" flag are grouped
169    /// together by the linker to form the data section and the dp register is
170    /// set to the start of the section by the boot code.
171    XCORE_SHF_DP_SECTION = 0x1000U
172  };
173
174  StringRef getSectionName() const { return SectionName; }
175  unsigned getType() const { return Type; }
176  unsigned getFlags() const { return Flags; }
177  unsigned getEntrySize() const { return EntrySize; }
178
179  void PrintSwitchToSection(const MCAsmInfo &MAI,
180                            raw_ostream &OS) const;
181  virtual bool UseCodeAlign() const;
182
183  /// isBaseAddressKnownZero - We know that non-allocatable sections (like
184  /// debug info) have a base of zero.
185  virtual bool isBaseAddressKnownZero() const {
186    return (getFlags() & SHF_ALLOC) == 0;
187  }
188
189  static bool classof(const MCSection *S) {
190    return S->getVariant() == SV_ELF;
191  }
192  static bool classof(const MCSectionELF *) { return true; }
193
194  // Return the entry size for sections with fixed-width data.
195  static unsigned DetermineEntrySize(SectionKind Kind);
196
197};
198
199} // end namespace llvm
200
201#endif
202