LLVM API Documentation

MCSectionELF.h
Go to the documentation of this file.
00001 //===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the MCSectionELF class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_MC_MCSECTIONELF_H
00015 #define LLVM_MC_MCSECTIONELF_H
00016 
00017 #include "llvm/ADT/Twine.h"
00018 #include "llvm/MC/MCSection.h"
00019 #include "llvm/MC/MCSymbol.h"
00020 #include "llvm/Support/Debug.h"
00021 #include "llvm/Support/ELF.h"
00022 #include "llvm/Support/raw_ostream.h"
00023 
00024 namespace llvm {
00025 
00026 class MCSymbol;
00027 
00028 /// MCSectionELF - This represents a section on linux, lots of unix variants
00029 /// and some bare metal systems.
00030 class MCSectionELF : public MCSection {
00031   /// SectionName - This is the name of the section.  The referenced memory is
00032   /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
00033   StringRef SectionName;
00034 
00035   /// Type - This is the sh_type field of a section, drawn from the enums below.
00036   unsigned Type;
00037 
00038   /// Flags - This is the sh_flags field of a section, drawn from the enums.
00039   /// below.
00040   unsigned Flags;
00041 
00042   /// EntrySize - The size of each entry in this section. This size only
00043   /// makes sense for sections that contain fixed-sized entries. If a
00044   /// section does not contain fixed-sized entries 'EntrySize' will be 0.
00045   unsigned EntrySize;
00046 
00047   const MCSymbol *Group;
00048 
00049 private:
00050   friend class MCContext;
00051   MCSectionELF(StringRef Section, unsigned type, unsigned flags,
00052                SectionKind K, unsigned entrySize, const MCSymbol *group)
00053     : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
00054       EntrySize(entrySize), Group(group) {}
00055   ~MCSectionELF();
00056 
00057   void setSectionName(StringRef Name) { SectionName = Name; }
00058 
00059 public:
00060 
00061   /// ShouldOmitSectionDirective - Decides whether a '.section' directive
00062   /// should be printed before the section name
00063   bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
00064 
00065   StringRef getSectionName() const { return SectionName; }
00066   std::string getLabelBeginName() const override {
00067     if (Group)
00068       return (SectionName.str() + '_' + Group->getName() + "_begin").str();
00069     return SectionName.str() + "_begin";
00070   }
00071   std::string getLabelEndName() const override {
00072     if (Group)
00073       return (SectionName.str() + '_' + Group->getName() + "_end").str();
00074     return SectionName.str() + "_end";
00075   }
00076   unsigned getType() const { return Type; }
00077   unsigned getFlags() const { return Flags; }
00078   unsigned getEntrySize() const { return EntrySize; }
00079   const MCSymbol *getGroup() const { return Group; }
00080 
00081   void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
00082                             const MCExpr *Subsection) const override;
00083   bool UseCodeAlign() const override;
00084   bool isVirtualSection() const override;
00085 
00086   /// isBaseAddressKnownZero - We know that non-allocatable sections (like
00087   /// debug info) have a base of zero.
00088   bool isBaseAddressKnownZero() const override {
00089     return (getFlags() & ELF::SHF_ALLOC) == 0;
00090   }
00091 
00092   static bool classof(const MCSection *S) {
00093     return S->getVariant() == SV_ELF;
00094   }
00095 
00096   // Return the entry size for sections with fixed-width data.
00097   static unsigned DetermineEntrySize(SectionKind Kind);
00098 
00099 };
00100 
00101 } // end namespace llvm
00102 
00103 #endif