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