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