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/ADT/StringRef.h"
18 #include "llvm/MC/MCSection.h"
19 #include "llvm/MC/MCSymbol.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Support/ELF.h"
22 #include "llvm/Support/raw_ostream.h"
28 /// MCSectionELF - This represents a section on linux, lots of unix variants
29 /// and some bare metal systems.
30 class MCSectionELF : public MCSection {
31 /// SectionName - This is the name of the section. The referenced memory is
32 /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
33 StringRef SectionName;
35 /// Type - This is the sh_type field of a section, drawn from the enums below.
38 /// Flags - This is the sh_flags field of a section, drawn from the enums.
42 /// EntrySize - The size of each entry in this section. This size only
43 /// makes sense for sections that contain fixed-sized entries. If a
44 /// section does not contain fixed-sized entries 'EntrySize' will be 0.
47 const MCSymbol *Group;
50 friend class MCContext;
51 MCSectionELF(StringRef Section, unsigned type, unsigned flags,
52 SectionKind K, unsigned entrySize, const MCSymbol *group)
53 : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
54 EntrySize(entrySize), Group(group) {}
58 /// ShouldOmitSectionDirective - Decides whether a '.section' directive
59 /// should be printed before the section name
60 bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
62 StringRef getSectionName() const { return SectionName; }
63 virtual std::string getLabelBeginName() const {
65 return (SectionName.str() + '_' + Group->getName() + "_begin").str();
66 return SectionName.str() + "_begin";
68 virtual std::string getLabelEndName() const {
70 return (SectionName.str() + '_' + Group->getName() + "_end").str();
71 return SectionName.str() + "_end";
73 unsigned getType() const { return Type; }
74 unsigned getFlags() const { return Flags; }
75 unsigned getEntrySize() const { return EntrySize; }
76 const MCSymbol *getGroup() const { return Group; }
78 void PrintSwitchToSection(const MCAsmInfo &MAI,
80 const MCExpr *Subsection) const;
81 virtual bool UseCodeAlign() const;
82 virtual bool isVirtualSection() const;
84 /// isBaseAddressKnownZero - We know that non-allocatable sections (like
85 /// debug info) have a base of zero.
86 virtual bool isBaseAddressKnownZero() const {
87 return (getFlags() & ELF::SHF_ALLOC) == 0;
90 static bool classof(const MCSection *S) {
91 return S->getVariant() == SV_ELF;
94 // Return the entry size for sections with fixed-width data.
95 static unsigned DetermineEntrySize(SectionKind Kind);
99 } // end namespace llvm