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 /// SectionName - This is the name of the section. The referenced memory is
25 /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
26 StringRef SectionName;
28 /// Type - This is the sh_type field of a section, drawn from the enums below.
31 /// Flags - This is the sh_flags field of a section, drawn from the enums.
35 /// IsExplicit - Indicates that this section comes from globals with an
36 /// explicit section specified.
40 friend class MCContext;
41 MCSectionELF(StringRef Section, unsigned type, unsigned flags,
42 SectionKind K, bool isExplicit)
43 : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
44 IsExplicit(isExplicit) {}
48 /// ShouldOmitSectionDirective - Decides whether a '.section' directive
49 /// should be printed before the section name
50 bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
52 /// ShouldPrintSectionType - Only prints the section type if supported
53 bool ShouldPrintSectionType(unsigned Ty) const;
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
58 bool HasCommonSymbols() const;
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.
63 /// Valid section types.
65 // This value marks the section header as inactive.
68 // Holds information defined by the program, with custom format and meaning.
71 // This section holds a symbol table.
74 // The section holds a string table.
77 // The section holds relocation entries with explicit addends.
80 // The section holds a symbol hash table.
83 // Information for dynamic linking.
86 // The section holds information that marks the file in some way.
89 // A section of this type occupies no space in the file.
92 // The section holds relocation entries without explicit addends.
95 // This section type is reserved but has unspecified semantics.
98 // This section holds a symbol table.
101 // This section contains an array of pointers to initialization functions.
102 SHT_INIT_ARRAY = 0x0EU,
104 // This section contains an array of pointers to termination functions.
105 SHT_FINI_ARRAY = 0x0FU,
107 // This section contains an array of pointers to functions that are invoked
108 // before all other initialization functions.
109 SHT_PREINIT_ARRAY = 0x10U,
111 // A section group is a set of sections that are related and that must be
112 // treated specially by the linker.
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,
119 LAST_KNOWN_SECTION_TYPE = SHT_SYMTAB_SHNDX
122 /// Valid section flags.
124 // The section contains data that should be writable.
127 // The section occupies memory during execution.
130 // The section contains executable machine instructions.
131 SHF_EXECINSTR = 0x4U,
133 // The data in the section may be merged to eliminate duplication.
136 // Elements in the section consist of null-terminated character strings.
139 // A field in this section holds a section header table index.
140 SHF_INFO_LINK = 0x40U,
142 // Adds special ordering requirements for link editors.
143 SHF_LINK_ORDER = 0x80U,
145 // This section requires special OS-specific processing to avoid incorrect
147 SHF_OS_NONCONFORMING = 0x100U,
149 // This section is a member of a section group.
152 // This section holds Thread-Local Storage.
156 // Start of target-specific flags.
158 /// XCORE_SHF_CP_SECTION - All sections with the "c" flag are grouped
159 /// together by the linker to form the constant pool and the cp register is
160 /// set to the start of the constant pool by the boot code.
161 XCORE_SHF_CP_SECTION = 0x800U,
163 /// XCORE_SHF_DP_SECTION - All sections with the "d" flag are grouped
164 /// together by the linker to form the data section and the dp register is
165 /// set to the start of the section by the boot code.
166 XCORE_SHF_DP_SECTION = 0x1000U
169 StringRef getSectionName() const { return SectionName; }
170 unsigned getType() const { return Type; }
171 unsigned getFlags() const { return Flags; }
173 void PrintSwitchToSection(const MCAsmInfo &MAI,
174 raw_ostream &OS) const;
176 /// isBaseAddressKnownZero - We know that non-allocatable sections (like
177 /// debug info) have a base of zero.
178 virtual bool isBaseAddressKnownZero() const {
179 return (getFlags() & SHF_ALLOC) == 0;
182 static bool classof(const MCSection *S) {
183 return S->getVariant() == SV_ELF;
185 static bool classof(const MCSectionELF *) { return true; }
188 } // end namespace llvm