MC: Allow modifiers in MCSymbolRefExpr, and eliminate X86MCTargetExpr.
[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   /// 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   /// IsExplicit - Indicates that this section comes from globals with an
36   /// explicit section specified.
37   bool IsExplicit;
38   
39 protected:
40   MCSectionELF(StringRef Section, unsigned type, unsigned flags,
41                SectionKind K, bool isExplicit)
42     : MCSection(K), SectionName(Section), Type(type), Flags(flags), 
43       IsExplicit(isExplicit) {}
44 public:
45   
46   static MCSectionELF *Create(StringRef Section, unsigned Type, 
47                               unsigned Flags, SectionKind K, bool isExplicit,
48                               MCContext &Ctx);
49
50   /// ShouldOmitSectionDirective - Decides whether a '.section' directive
51   /// should be printed before the section name
52   bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
53
54   /// ShouldPrintSectionType - Only prints the section type if supported
55   bool ShouldPrintSectionType(unsigned Ty) 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     LAST_KNOWN_SECTION_TYPE = SHT_SYMTAB_SHNDX
122   }; 
123
124   /// Valid section flags.
125   enum {
126     // The section contains data that should be writable.
127     SHF_WRITE            = 0x1U,
128
129     // The section occupies memory during execution.
130     SHF_ALLOC            = 0x2U,
131
132     // The section contains executable machine instructions.
133     SHF_EXECINSTR        = 0x4U,
134
135     // The data in the section may be merged to eliminate duplication.
136     SHF_MERGE            = 0x10U,
137
138     // Elements in the section consist of null-terminated character strings.
139     SHF_STRINGS          = 0x20U,
140
141     // A field in this section holds a section header table index.
142     SHF_INFO_LINK        = 0x40U,
143
144     // Adds special ordering requirements for link editors.
145     SHF_LINK_ORDER       = 0x80U,
146
147     // This section requires special OS-specific processing to avoid incorrect
148     // behavior.
149     SHF_OS_NONCONFORMING = 0x100U,
150
151     // This section is a member of a section group.
152     SHF_GROUP            = 0x200U,
153
154     // This section holds Thread-Local Storage.
155     SHF_TLS              = 0x400U,
156     
157     /// FIRST_TARGET_DEP_FLAG - This is the first flag that subclasses are
158     /// allowed to specify.
159     FIRST_TARGET_DEP_FLAG = 0x800U,
160
161     /// TARGET_INDEP_SHF - This is the bitmask for all the target independent
162     /// section flags.  Targets can define their own target flags above these.
163     /// If they do that, they should implement their own MCSectionELF subclasses
164     /// and implement the virtual method hooks below to handle printing needs.
165     TARGET_INDEP_SHF     = FIRST_TARGET_DEP_FLAG-1U
166   };
167
168   StringRef getSectionName() const { return SectionName; }
169   unsigned getType() const { return Type; }
170   unsigned getFlags() const { return Flags; }
171   
172   virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
173                                     raw_ostream &OS) const;
174   
175   
176   /// PrintTargetSpecificSectionFlags - Targets that define their own
177   /// MCSectionELF subclasses with target specific section flags should
178   /// implement this method if they end up adding letters to the attributes
179   /// list.
180   virtual void PrintTargetSpecificSectionFlags(const MCAsmInfo &MAI,
181                                                raw_ostream &OS) const {
182   }
183                                                
184   
185 };
186
187 } // end namespace llvm
188
189 #endif