rename TAI -> MAI, being careful not to make MAILJMP instructions :)
[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 /// MCSectionELF - This represents a section on linux, lots of unix variants
22 /// and some bare metal systems.
23 class MCSectionELF : public MCSection {
24   std::string SectionName;
25   
26   /// Type - This is the sh_type field of a section, drawn from the enums below.
27   unsigned Type;
28   
29   /// Flags - This is the sh_flags field of a section, drawn from the enums.
30   /// below.
31   unsigned Flags;
32
33   /// IsExplicit - Indicates that this section comes from globals with an
34   /// explicit section specfied.
35   bool IsExplicit;
36   
37 protected:
38   MCSectionELF(const StringRef &Section, unsigned type, unsigned flags,
39                SectionKind K, bool isExplicit)
40     : MCSection(K), SectionName(Section.str()), Type(type), Flags(flags), 
41       IsExplicit(isExplicit) {}
42 public:
43   
44   static MCSectionELF *Create(const StringRef &Section, unsigned Type, 
45                               unsigned Flags, SectionKind K, bool isExplicit,
46                               MCContext &Ctx);
47
48   /// ShouldOmitSectionDirective - Decides whether a '.section' directive
49   /// should be printed before the section name
50   bool ShouldOmitSectionDirective(const char *Name, 
51                                   const MCAsmInfo &MAI) const;
52
53   /// ShouldPrintSectionType - Only prints the section type if supported
54   bool ShouldPrintSectionType(unsigned Ty) const;
55
56   /// HasCommonSymbols - True if this section holds common symbols, this is
57   /// indicated on the ELF object file by a symbol with SHN_COMMON section 
58   /// header index.
59   bool HasCommonSymbols() const;
60   
61   /// These are the section type and flags fields.  An ELF section can have
62   /// only one Type, but can have more than one of the flags specified.
63   ///
64   /// Valid section types.
65   enum {
66     // This value marks the section header as inactive.
67     SHT_NULL             = 0x00U,
68
69     // Holds information defined by the program, with custom format and meaning.
70     SHT_PROGBITS         = 0x01U,
71
72     // This section holds a symbol table.
73     SHT_SYMTAB           = 0x02U,
74
75     // The section holds a string table.
76     SHT_STRTAB           = 0x03U,
77
78     // The section holds relocation entries with explicit addends.
79     SHT_RELA             = 0x04U,
80
81     // The section holds a symbol hash table.
82     SHT_HASH             = 0x05U,
83     
84     // Information for dynamic linking.
85     SHT_DYNAMIC          = 0x06U,
86
87     // The section holds information that marks the file in some way.
88     SHT_NOTE             = 0x07U,
89
90     // A section of this type occupies no space in the file.
91     SHT_NOBITS           = 0x08U,
92
93     // The section holds relocation entries without explicit addends.
94     SHT_REL              = 0x09U,
95
96     // This section type is reserved but has unspecified semantics. 
97     SHT_SHLIB            = 0x0AU,
98
99     // This section holds a symbol table.
100     SHT_DYNSYM           = 0x0BU,
101
102     // This section contains an array of pointers to initialization functions.
103     SHT_INIT_ARRAY       = 0x0EU,
104
105     // This section contains an array of pointers to termination functions.
106     SHT_FINI_ARRAY       = 0x0FU,
107
108     // This section contains an array of pointers to functions that are invoked
109     // before all other initialization functions.
110     SHT_PREINIT_ARRAY    = 0x10U,
111
112     // A section group is a set of sections that are related and that must be
113     // treated specially by the linker.
114     SHT_GROUP            = 0x11U,
115
116     // This section is associated with a section of type SHT_SYMTAB, when the
117     // referenced symbol table contain the escape value SHN_XINDEX
118     SHT_SYMTAB_SHNDX     = 0x12U,
119
120     LAST_KNOWN_SECTION_TYPE = SHT_SYMTAB_SHNDX
121   }; 
122
123   /// Valid section flags.
124   enum {
125     // The section contains data that should be writable.
126     SHF_WRITE            = 0x1U,
127
128     // The section occupies memory during execution.
129     SHF_ALLOC            = 0x2U,
130
131     // The section contains executable machine instructions.
132     SHF_EXECINSTR        = 0x4U,
133
134     // The data in the section may be merged to eliminate duplication.
135     SHF_MERGE            = 0x10U,
136
137     // Elements in the section consist of null-terminated character strings.
138     SHF_STRINGS          = 0x20U,
139
140     // A field in this section holds a section header table index.
141     SHF_INFO_LINK        = 0x40U,
142
143     // Adds special ordering requirements for link editors.
144     SHF_LINK_ORDER       = 0x80U,
145
146     // This section requires special OS-specific processing to avoid incorrect
147     // behavior.
148     SHF_OS_NONCONFORMING = 0x100U,
149
150     // This section is a member of a section group.
151     SHF_GROUP            = 0x200U,
152
153     // This section holds Thread-Local Storage.
154     SHF_TLS              = 0x400U,
155     
156     /// FIRST_TARGET_DEP_FLAG - This is the first flag that subclasses are
157     /// allowed to specify.
158     FIRST_TARGET_DEP_FLAG = 0x800U,
159
160     /// TARGET_INDEP_SHF - This is the bitmask for all the target independent
161     /// section flags.  Targets can define their own target flags above these.
162     /// If they do that, they should implement their own MCSectionELF subclasses
163     /// and implement the virtual method hooks below to handle printing needs.
164     TARGET_INDEP_SHF     = FIRST_TARGET_DEP_FLAG-1U
165   };
166
167   StringRef getSectionName() const {
168     return StringRef(SectionName);
169   }
170   
171   unsigned getType() const { return Type; }
172   unsigned getFlags() const { return Flags; }
173   
174   virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
175                                     raw_ostream &OS) const;
176   
177   
178   /// PrintTargetSpecificSectionFlags - Targets that define their own
179   /// MCSectionELF subclasses with target specific section flags should
180   /// implement this method if they end up adding letters to the attributes
181   /// list.
182   virtual void PrintTargetSpecificSectionFlags(const MCAsmInfo &MAI,
183                                                raw_ostream &OS) const {
184   }
185                                                
186   
187 };
188
189 } // end namespace llvm
190
191 #endif