MCSectionELF.h revision 207618
1198090Srdivacky//===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
2198090Srdivacky//
3198090Srdivacky//                     The LLVM Compiler Infrastructure
4198090Srdivacky//
5198090Srdivacky// This file is distributed under the University of Illinois Open Source
6198090Srdivacky// License. See LICENSE.TXT for details.
7198090Srdivacky//
8198090Srdivacky//===----------------------------------------------------------------------===//
9198090Srdivacky//
10198090Srdivacky// This file declares the MCSectionELF class.
11198090Srdivacky//
12198090Srdivacky//===----------------------------------------------------------------------===//
13198090Srdivacky
14198090Srdivacky#ifndef LLVM_MC_MCSECTIONELF_H
15198090Srdivacky#define LLVM_MC_MCSECTIONELF_H
16198090Srdivacky
17198090Srdivacky#include "llvm/MC/MCSection.h"
18198090Srdivacky
19198090Srdivackynamespace llvm {
20198090Srdivacky
21198090Srdivacky/// MCSectionELF - This represents a section on linux, lots of unix variants
22198090Srdivacky/// and some bare metal systems.
23198090Srdivackyclass MCSectionELF : public MCSection {
24205218Srdivacky  /// SectionName - This is the name of the section.  The referenced memory is
25205218Srdivacky  /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
26205218Srdivacky  StringRef SectionName;
27198090Srdivacky
28198090Srdivacky  /// Type - This is the sh_type field of a section, drawn from the enums below.
29198090Srdivacky  unsigned Type;
30198090Srdivacky
31198090Srdivacky  /// Flags - This is the sh_flags field of a section, drawn from the enums.
32198090Srdivacky  /// below.
33198090Srdivacky  unsigned Flags;
34198090Srdivacky
35198090Srdivacky  /// IsExplicit - Indicates that this section comes from globals with an
36202878Srdivacky  /// explicit section specified.
37198090Srdivacky  bool IsExplicit;
38198090Srdivacky
39207618Srdivackyprivate:
40207618Srdivacky  friend class MCContext;
41199481Srdivacky  MCSectionELF(StringRef Section, unsigned type, unsigned flags,
42198090Srdivacky               SectionKind K, bool isExplicit)
43205218Srdivacky    : MCSection(K), SectionName(Section), Type(type), Flags(flags),
44198090Srdivacky      IsExplicit(isExplicit) {}
45207618Srdivacky  ~MCSectionELF();
46198090Srdivackypublic:
47198090Srdivacky
48198090Srdivacky  /// ShouldOmitSectionDirective - Decides whether a '.section' directive
49198090Srdivacky  /// should be printed before the section name
50202878Srdivacky  bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
51198090Srdivacky
52198090Srdivacky  /// ShouldPrintSectionType - Only prints the section type if supported
53198090Srdivacky  bool ShouldPrintSectionType(unsigned Ty) const;
54198090Srdivacky
55198090Srdivacky  /// HasCommonSymbols - True if this section holds common symbols, this is
56198090Srdivacky  /// indicated on the ELF object file by a symbol with SHN_COMMON section
57198090Srdivacky  /// header index.
58198090Srdivacky  bool HasCommonSymbols() const;
59198090Srdivacky
60198090Srdivacky  /// These are the section type and flags fields.  An ELF section can have
61198090Srdivacky  /// only one Type, but can have more than one of the flags specified.
62198090Srdivacky  ///
63198090Srdivacky  /// Valid section types.
64198090Srdivacky  enum {
65198090Srdivacky    // This value marks the section header as inactive.
66198090Srdivacky    SHT_NULL             = 0x00U,
67198090Srdivacky
68198090Srdivacky    // Holds information defined by the program, with custom format and meaning.
69198090Srdivacky    SHT_PROGBITS         = 0x01U,
70198090Srdivacky
71198090Srdivacky    // This section holds a symbol table.
72198090Srdivacky    SHT_SYMTAB           = 0x02U,
73198090Srdivacky
74198090Srdivacky    // The section holds a string table.
75198090Srdivacky    SHT_STRTAB           = 0x03U,
76198090Srdivacky
77198090Srdivacky    // The section holds relocation entries with explicit addends.
78198090Srdivacky    SHT_RELA             = 0x04U,
79198090Srdivacky
80198090Srdivacky    // The section holds a symbol hash table.
81198090Srdivacky    SHT_HASH             = 0x05U,
82198090Srdivacky
83198090Srdivacky    // Information for dynamic linking.
84198090Srdivacky    SHT_DYNAMIC          = 0x06U,
85198090Srdivacky
86198090Srdivacky    // The section holds information that marks the file in some way.
87198090Srdivacky    SHT_NOTE             = 0x07U,
88198090Srdivacky
89198090Srdivacky    // A section of this type occupies no space in the file.
90198090Srdivacky    SHT_NOBITS           = 0x08U,
91198090Srdivacky
92198090Srdivacky    // The section holds relocation entries without explicit addends.
93198090Srdivacky    SHT_REL              = 0x09U,
94198090Srdivacky
95198090Srdivacky    // This section type is reserved but has unspecified semantics.
96198090Srdivacky    SHT_SHLIB            = 0x0AU,
97198090Srdivacky
98198090Srdivacky    // This section holds a symbol table.
99198090Srdivacky    SHT_DYNSYM           = 0x0BU,
100198090Srdivacky
101198090Srdivacky    // This section contains an array of pointers to initialization functions.
102198090Srdivacky    SHT_INIT_ARRAY       = 0x0EU,
103198090Srdivacky
104198090Srdivacky    // This section contains an array of pointers to termination functions.
105198090Srdivacky    SHT_FINI_ARRAY       = 0x0FU,
106198090Srdivacky
107198090Srdivacky    // This section contains an array of pointers to functions that are invoked
108198090Srdivacky    // before all other initialization functions.
109198090Srdivacky    SHT_PREINIT_ARRAY    = 0x10U,
110198090Srdivacky
111198090Srdivacky    // A section group is a set of sections that are related and that must be
112198090Srdivacky    // treated specially by the linker.
113198090Srdivacky    SHT_GROUP            = 0x11U,
114198090Srdivacky
115198090Srdivacky    // This section is associated with a section of type SHT_SYMTAB, when the
116198090Srdivacky    // referenced symbol table contain the escape value SHN_XINDEX
117198090Srdivacky    SHT_SYMTAB_SHNDX     = 0x12U,
118198090Srdivacky
119198090Srdivacky    LAST_KNOWN_SECTION_TYPE = SHT_SYMTAB_SHNDX
120198090Srdivacky  };
121198090Srdivacky
122198090Srdivacky  /// Valid section flags.
123198090Srdivacky  enum {
124198090Srdivacky    // The section contains data that should be writable.
125198090Srdivacky    SHF_WRITE            = 0x1U,
126198090Srdivacky
127198090Srdivacky    // The section occupies memory during execution.
128198090Srdivacky    SHF_ALLOC            = 0x2U,
129198090Srdivacky
130198090Srdivacky    // The section contains executable machine instructions.
131198090Srdivacky    SHF_EXECINSTR        = 0x4U,
132198090Srdivacky
133198090Srdivacky    // The data in the section may be merged to eliminate duplication.
134198090Srdivacky    SHF_MERGE            = 0x10U,
135198090Srdivacky
136198090Srdivacky    // Elements in the section consist of null-terminated character strings.
137198090Srdivacky    SHF_STRINGS          = 0x20U,
138198090Srdivacky
139198090Srdivacky    // A field in this section holds a section header table index.
140198090Srdivacky    SHF_INFO_LINK        = 0x40U,
141198090Srdivacky
142198090Srdivacky    // Adds special ordering requirements for link editors.
143198090Srdivacky    SHF_LINK_ORDER       = 0x80U,
144198090Srdivacky
145198090Srdivacky    // This section requires special OS-specific processing to avoid incorrect
146198090Srdivacky    // behavior.
147198090Srdivacky    SHF_OS_NONCONFORMING = 0x100U,
148198090Srdivacky
149198090Srdivacky    // This section is a member of a section group.
150198090Srdivacky    SHF_GROUP            = 0x200U,
151198090Srdivacky
152198090Srdivacky    // This section holds Thread-Local Storage.
153198090Srdivacky    SHF_TLS              = 0x400U,
154207618Srdivacky
155198090Srdivacky
156207618Srdivacky    // Start of target-specific flags.
157198090Srdivacky
158207618Srdivacky    /// XCORE_SHF_CP_SECTION - All sections with the "c" flag are grouped
159207618Srdivacky    /// together by the linker to form the constant pool and the cp register is
160207618Srdivacky    /// set to the start of the constant pool by the boot code.
161207618Srdivacky    XCORE_SHF_CP_SECTION = 0x800U,
162207618Srdivacky
163207618Srdivacky    /// XCORE_SHF_DP_SECTION - All sections with the "d" flag are grouped
164207618Srdivacky    /// together by the linker to form the data section and the dp register is
165207618Srdivacky    /// set to the start of the section by the boot code.
166207618Srdivacky    XCORE_SHF_DP_SECTION = 0x1000U
167198090Srdivacky  };
168198090Srdivacky
169205218Srdivacky  StringRef getSectionName() const { return SectionName; }
170198090Srdivacky  unsigned getType() const { return Type; }
171198090Srdivacky  unsigned getFlags() const { return Flags; }
172198090Srdivacky
173207618Srdivacky  void PrintSwitchToSection(const MCAsmInfo &MAI,
174207618Srdivacky                            raw_ostream &OS) const;
175198090Srdivacky
176206274Srdivacky  /// isBaseAddressKnownZero - We know that non-allocatable sections (like
177206274Srdivacky  /// debug info) have a base of zero.
178206274Srdivacky  virtual bool isBaseAddressKnownZero() const {
179206274Srdivacky    return (getFlags() & SHF_ALLOC) == 0;
180206274Srdivacky  }
181198090Srdivacky};
182198090Srdivacky
183198090Srdivacky} // end namespace llvm
184198090Srdivacky
185198090Srdivacky#endif
186