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.
39 /// EntrySize - The size of each entry in this section. This size only
40 /// makes sense for sections that contain fixed-sized entries. If a
41 /// section does not contain fixed-sized entries 'EntrySize' will be 0.
45 friend class MCContext;
46 MCSectionELF(StringRef Section, unsigned type, unsigned flags,
47 SectionKind K, bool isExplicit, unsigned entrySize)
48 : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
49 IsExplicit(isExplicit), EntrySize(entrySize) {}
53 /// ShouldOmitSectionDirective - Decides whether a '.section' directive
54 /// should be printed before the section name
55 bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
57 /// ShouldPrintSectionType - Only prints the section type if supported
58 bool ShouldPrintSectionType(unsigned Ty) const;
60 /// HasCommonSymbols - True if this section holds common symbols, this is
61 /// indicated on the ELF object file by a symbol with SHN_COMMON section
63 bool HasCommonSymbols() const;
65 /// These are the section type and flags fields. An ELF section can have
66 /// only one Type, but can have more than one of the flags specified.
68 /// Valid section types.
70 // This value marks the section header as inactive.
73 // Holds information defined by the program, with custom format and meaning.
76 // This section holds a symbol table.
79 // The section holds a string table.
82 // The section holds relocation entries with explicit addends.
85 // The section holds a symbol hash table.
88 // Information for dynamic linking.
91 // The section holds information that marks the file in some way.
94 // A section of this type occupies no space in the file.
97 // The section holds relocation entries without explicit addends.
100 // This section type is reserved but has unspecified semantics.
103 // This section holds a symbol table.
106 // This section contains an array of pointers to initialization functions.
107 SHT_INIT_ARRAY = 0x0EU,
109 // This section contains an array of pointers to termination functions.
110 SHT_FINI_ARRAY = 0x0FU,
112 // This section contains an array of pointers to functions that are invoked
113 // before all other initialization functions.
114 SHT_PREINIT_ARRAY = 0x10U,
116 // A section group is a set of sections that are related and that must be
117 // treated specially by the linker.
120 // This section is associated with a section of type SHT_SYMTAB, when the
121 // referenced symbol table contain the escape value SHN_XINDEX
122 SHT_SYMTAB_SHNDX = 0x12U,
124 // Start of target-specific flags.
126 // Exception Index table
127 SHT_ARM_EXIDX = 0x70000001U,
128 // BPABI DLL dynamic linking pre-emption map
129 SHT_ARM_PREEMPTMAP = 0x70000002U,
130 // Object file compatibility attributes
131 SHT_ARM_ATTRIBUTES = 0x70000003U,
132 SHT_ARM_DEBUGOVERLAY = 0x70000004U,
133 SHT_ARM_OVERLAYSECTION = 0x70000005U,
135 LAST_KNOWN_SECTION_TYPE = SHT_ARM_OVERLAYSECTION
138 /// Valid section flags.
140 // The section contains data that should be writable.
143 // The section occupies memory during execution.
146 // The section contains executable machine instructions.
147 SHF_EXECINSTR = 0x4U,
149 // The data in the section may be merged to eliminate duplication.
152 // Elements in the section consist of null-terminated character strings.
155 // A field in this section holds a section header table index.
156 SHF_INFO_LINK = 0x40U,
158 // Adds special ordering requirements for link editors.
159 SHF_LINK_ORDER = 0x80U,
161 // This section requires special OS-specific processing to avoid incorrect
163 SHF_OS_NONCONFORMING = 0x100U,
165 // This section is a member of a section group.
168 // This section holds Thread-Local Storage.
172 // Start of target-specific flags.
174 /// XCORE_SHF_CP_SECTION - All sections with the "c" flag are grouped
175 /// together by the linker to form the constant pool and the cp register is
176 /// set to the start of the constant pool by the boot code.
177 XCORE_SHF_CP_SECTION = 0x800U,
179 /// XCORE_SHF_DP_SECTION - All sections with the "d" flag are grouped
180 /// together by the linker to form the data section and the dp register is
181 /// set to the start of the section by the boot code.
182 XCORE_SHF_DP_SECTION = 0x1000U
185 StringRef getSectionName() const { return SectionName; }
186 unsigned getType() const { return Type; }
187 unsigned getFlags() const { return Flags; }
188 unsigned getEntrySize() const { return EntrySize; }
190 void PrintSwitchToSection(const MCAsmInfo &MAI,
191 raw_ostream &OS) const;
192 virtual bool UseCodeAlign() const;
194 /// isBaseAddressKnownZero - We know that non-allocatable sections (like
195 /// debug info) have a base of zero.
196 virtual bool isBaseAddressKnownZero() const {
197 return (getFlags() & SHF_ALLOC) == 0;
200 static bool classof(const MCSection *S) {
201 return S->getVariant() == SV_ELF;
203 static bool classof(const MCSectionELF *) { return true; }
205 // Return the entry size for sections with fixed-width data.
206 static unsigned DetermineEntrySize(SectionKind Kind);
210 } // end namespace llvm