1 //===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the MCSectionELF class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_MC_MCSECTIONELF_H
15 #define LLVM_MC_MCSECTIONELF_H
17 #include "llvm/MC/MCSection.h"
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;
26 /// Type - This is the sh_type field of a section, drawn from the enums below.
29 /// Flags - This is the sh_flags field of a section, drawn from the enums.
33 /// IsExplicit - Indicates that this section comes from globals with an
34 /// explicit section specfied.
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) {}
43 static MCSectionELF *Create(const StringRef &Section, unsigned Type,
44 unsigned Flags, SectionKind K, bool isExplicit,
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;
52 /// ShouldPrintSectionType - Only prints the section type if supported
53 bool ShouldPrintSectionType(unsigned Ty) const;
55 /// IsCommon - True if this section contains only common symbols
56 bool IsCommon() const;
58 /// These are the section type and flags fields. An ELF section can have
59 /// only one Type, but can have more than one of the flags specified.
61 /// Valid section types.
63 // This value marks the section header as inactive.
66 // Holds information defined by the program, with custom format and meaning.
69 // This section holds a symbol table.
72 // The section holds a string table.
75 // The section holds relocation entries with explicit addends.
78 // The section holds a symbol hash table.
81 // Information for dynamic linking.
84 // The section holds information that marks the file in some way.
87 // A section of this type occupies no space in the file.
90 // The section holds relocation entries without explicit addends.
93 // This section type is reserved but has unspecified semantics.
96 // This section holds a symbol table.
99 // This section contains an array of pointers to initialization functions.
100 SHT_INIT_ARRAY = 0x0eU,
102 // This section contains an array of pointers to termination functions.
103 SHT_FINI_ARRAY = 0x0fU,
105 // This section contains an array of pointers to functions that are invoked
106 // before all other initialization functions.
107 SHT_PREINIT_ARRAY = 0x10U,
109 // A section group is a set of sections that are related and that must be
110 // treated specially by the linker.
113 // This section is associated with a section of type SHT_SYMTAB, when the
114 // referenced symbol table contain the escape value SHN_XINDEX
115 SHT_SYMTAB_SHNDX = 0x12U,
117 LAST_KNOWN_SECTION_TYPE = SHT_SYMTAB_SHNDX
120 /// Valid section flags.
122 // The section contains data that should be writable.
125 // The section occupies memory during execution.
128 // The section contains executable machine instructions.
129 SHF_EXECINSTR = 0x4U,
131 // The data in the section may be merged to eliminate duplication.
134 // Elements in the section consist of null-terminated character strings.
137 // A field in this section holds a section header table index.
138 SHF_INFO_LINK = 0x40U,
140 // Adds special ordering requirements for link editors.
141 SHF_LINK_ORDER = 0x80U,
143 // This section requires special OS-specific processing to avoid incorrect
145 SHF_OS_NONCONFORMING = 0x100U,
147 // This section is a member of a section group.
150 // This section holds Thread-Local Storage.
154 StringRef getSectionName() const {
155 return StringRef(SectionName);
158 unsigned getType() const { return Type; }
159 unsigned getFlags() const { return Flags; }
161 virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
162 raw_ostream &OS) const;
165 } // end namespace llvm