Change MCSectionELF to represent a section semantically instead of
[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   /// HasCrazyBSS - PPC/Linux doesn't support the .bss directive, it 
34   /// needs .section .bss. TODO: replace this with a TAI method.
35   bool HasCrazyBSS;
36
37   /// IsExplicit - Indicates that this section comes from globals with an
38   /// explicit section specfied.
39   bool IsExplicit;
40   
41   MCSectionELF(const StringRef &Section, unsigned T, unsigned F, 
42                SectionKind K, bool hasCrazyBSS, bool isExplicit)
43     : MCSection(K), SectionName(Section.str()), Type(T), Flags(F), 
44       HasCrazyBSS(hasCrazyBSS), IsExplicit(isExplicit) {}
45 public:
46   
47   static MCSectionELF *Create(const StringRef &Section, unsigned Type, 
48                               unsigned Flags, SectionKind K, 
49                               bool hasCrazyBSS, bool isExplicit, 
50                               MCContext &Ctx);
51
52   /// ShouldOmitSectionDirective - Decides whether a '.section' directive
53   /// should be printed before the section name
54   bool ShouldOmitSectionDirective(const char *Name) const;
55
56   /// ShouldPrintSectionType - Only prints the section type if supported
57   bool ShouldPrintSectionType(unsigned Ty) const;
58   
59   /// These are the section type and flags fields.  An ELF section can have
60   /// only one Type, but can have more than one of the flags specified.
61   ///
62   /// Valid section types.
63   enum {
64     // This value marks the section header as inactive.
65     SHT_NULL             = 0x00U,
66
67     // Holds information defined by the program, with custom format and meaning.
68     SHT_PROGBITS         = 0x01U,
69
70     // This section holds a symbol table.
71     SHT_SYMTAB           = 0x02U,
72
73     // The section holds a string table.
74     SHT_STRTAB           = 0x03U,
75
76     // The section holds relocation entries with explicit addends.
77     SHT_RELA             = 0x04U,
78
79     // The section holds a symbol hash table.
80     SHT_HASH             = 0x05U,
81     
82     // Information for dynamic linking.
83     SHT_DYNAMIC          = 0x06U,
84
85     // The section holds information that marks the file in some way.
86     SHT_NOTE             = 0x07U,
87
88     // A section of this type occupies no space in the file.
89     SHT_NOBITS           = 0x08U,
90
91     // The section holds relocation entries without explicit addends.
92     SHT_REL              = 0x09U,
93
94     // This section type is reserved but has unspecified semantics. 
95     SHT_SHLIB            = 0x0aU,
96
97     // This section holds a symbol table.
98     SHT_DYNSYM           = 0x0bU,
99
100     // This section contains an array of pointers to initialization functions.
101     SHT_INIT_ARRAY       = 0x0eU,
102
103     // This section contains an array of pointers to termination functions.
104     SHT_FINI_ARRAY       = 0x0fU,
105
106     // This section contains an array of pointers to functions that are invoked
107     // before all other initialization functions.
108     SHT_PREINIT_ARRAY    = 0x10U,
109
110     // A section group is a set of sections that are related and that must be
111     // treated specially by the linker.
112     SHT_GROUP            = 0x11U,
113
114     // This section is associated with a section of type SHT_SYMTAB, when the
115     // referenced symbol table contain the escape value SHN_XINDEX
116     SHT_SYMTAB_SHNDX     = 0x12U,
117
118     LAST_KNOWN_SECTION_TYPE = SHT_SYMTAB_SHNDX
119   }; 
120
121   /// Valid section flags.
122   enum {
123     // The section contains data that should be writable.
124     SHF_WRITE            = 0x1U,
125
126     // The section occupies memory during execution.
127     SHF_ALLOC            = 0x2U,
128
129     // The section contains executable machine instructions.
130     SHF_EXECINSTR        = 0x4U,
131
132     // The data in the section may be merged to eliminate duplication.
133     SHF_MERGE            = 0x10U,
134
135     // Elements in the section consist of null-terminated character strings.
136     SHF_STRINGS          = 0x20U,
137
138     // A field in this section holds a section header table index.
139     SHF_INFO_LINK        = 0x40U,
140
141     // Adds special ordering requirements for link editors.
142     SHF_LINK_ORDER       = 0x80U,
143
144     // This section requires special OS-specific processing to avoid incorrect
145     // behavior.
146     SHF_OS_NONCONFORMING = 0x100U,
147
148     // This section is a member of a section group.
149     SHF_GROUP            = 0x200U,
150
151     // This section holds Thread-Local Storage.
152     SHF_TLS              = 0x400U
153   };
154
155   StringRef getSectionName() const {
156     return StringRef(SectionName);
157   }
158   
159   unsigned getType() const { return Type; }
160   unsigned getFlags() const { return Flags; }
161   
162   virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
163                                     raw_ostream &OS) const;
164 };
165
166 } // end namespace llvm
167
168 #endif