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"
23 /// MCSectionELF - This represents a section on linux, lots of unix variants
24 /// and some bare metal systems.
25 class MCSectionELF : public MCSection {
26 /// SectionName - This is the name of the section. The referenced memory is
27 /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
28 StringRef SectionName;
30 /// Type - This is the sh_type field of a section, drawn from the enums below.
33 /// Flags - This is the sh_flags field of a section, drawn from the enums.
37 /// EntrySize - The size of each entry in this section. This size only
38 /// makes sense for sections that contain fixed-sized entries. If a
39 /// section does not contain fixed-sized entries 'EntrySize' will be 0.
42 const MCSymbol *Group;
45 friend class MCContext;
46 MCSectionELF(StringRef Section, unsigned type, unsigned flags,
47 SectionKind K, unsigned entrySize, const MCSymbol *group)
48 : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
49 EntrySize(entrySize), Group(group) {}
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 /// HasCommonSymbols - True if this section holds common symbols, this is
58 /// indicated on the ELF object file by a symbol with SHN_COMMON section
60 bool HasCommonSymbols() const;
62 /// Valid section flags.
64 // The section contains data that should be writable.
67 // The section occupies memory during execution.
70 // The section contains executable machine instructions.
73 // The data in the section may be merged to eliminate duplication.
76 // Elements in the section consist of null-terminated character strings.
79 // A field in this section holds a section header table index.
80 SHF_INFO_LINK = 0x40U,
82 // Adds special ordering requirements for link editors.
83 SHF_LINK_ORDER = 0x80U,
85 // This section requires special OS-specific processing to avoid incorrect
87 SHF_OS_NONCONFORMING = 0x100U,
89 // This section is a member of a section group.
92 // This section holds Thread-Local Storage.
96 // Start of target-specific flags.
98 /// XCORE_SHF_CP_SECTION - All sections with the "c" flag are grouped
99 /// together by the linker to form the constant pool and the cp register is
100 /// set to the start of the constant pool by the boot code.
101 XCORE_SHF_CP_SECTION = 0x800U,
103 /// XCORE_SHF_DP_SECTION - All sections with the "d" flag are grouped
104 /// together by the linker to form the data section and the dp register is
105 /// set to the start of the section by the boot code.
106 XCORE_SHF_DP_SECTION = 0x1000U
109 StringRef getSectionName() const { return SectionName; }
110 unsigned getType() const { return Type; }
111 unsigned getFlags() const { return Flags; }
112 unsigned getEntrySize() const { return EntrySize; }
113 const MCSymbol *getGroup() const { return Group; }
115 void PrintSwitchToSection(const MCAsmInfo &MAI,
116 raw_ostream &OS) const;
117 virtual bool UseCodeAlign() const;
118 virtual bool isVirtualSection() const;
120 /// isBaseAddressKnownZero - We know that non-allocatable sections (like
121 /// debug info) have a base of zero.
122 virtual bool isBaseAddressKnownZero() const {
123 return (getFlags() & SHF_ALLOC) == 0;
126 static bool classof(const MCSection *S) {
127 return S->getVariant() == SV_ELF;
129 static bool classof(const MCSectionELF *) { return true; }
131 // Return the entry size for sections with fixed-width data.
132 static unsigned DetermineEntrySize(SectionKind Kind);
136 } // end namespace llvm