1198090Srdivacky//===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===// 2198090Srdivacky// 3198090Srdivacky// The LLVM Compiler Infrastructure 4198090Srdivacky// 5198090Srdivacky// This file is distributed under the University of Illinois Open Source 6198090Srdivacky// License. See LICENSE.TXT for details. 7198090Srdivacky// 8198090Srdivacky//===----------------------------------------------------------------------===// 9198090Srdivacky// 10198090Srdivacky// This file declares the MCSectionELF class. 11198090Srdivacky// 12198090Srdivacky//===----------------------------------------------------------------------===// 13198090Srdivacky 14198090Srdivacky#ifndef LLVM_MC_MCSECTIONELF_H 15198090Srdivacky#define LLVM_MC_MCSECTIONELF_H 16198090Srdivacky 17249423Sdim#include "llvm/ADT/StringRef.h" 18198090Srdivacky#include "llvm/MC/MCSection.h" 19249423Sdim#include "llvm/Support/Debug.h" 20218893Sdim#include "llvm/Support/ELF.h" 21249423Sdim#include "llvm/Support/raw_ostream.h" 22198090Srdivacky 23198090Srdivackynamespace llvm { 24218893Sdim 25218893Sdimclass MCSymbol; 26218893Sdim 27198090Srdivacky/// MCSectionELF - This represents a section on linux, lots of unix variants 28198090Srdivacky/// and some bare metal systems. 29198090Srdivackyclass MCSectionELF : public MCSection { 30205218Srdivacky /// SectionName - This is the name of the section. The referenced memory is 31205218Srdivacky /// owned by TargetLoweringObjectFileELF's ELFUniqueMap. 32205218Srdivacky StringRef SectionName; 33218893Sdim 34198090Srdivacky /// Type - This is the sh_type field of a section, drawn from the enums below. 35198090Srdivacky unsigned Type; 36218893Sdim 37198090Srdivacky /// Flags - This is the sh_flags field of a section, drawn from the enums. 38198090Srdivacky /// below. 39198090Srdivacky unsigned Flags; 40198090Srdivacky 41212904Sdim /// EntrySize - The size of each entry in this section. This size only 42212904Sdim /// makes sense for sections that contain fixed-sized entries. If a 43212904Sdim /// section does not contain fixed-sized entries 'EntrySize' will be 0. 44212904Sdim unsigned EntrySize; 45218893Sdim 46218893Sdim const MCSymbol *Group; 47218893Sdim 48207618Srdivackyprivate: 49207618Srdivacky friend class MCContext; 50199481Srdivacky MCSectionELF(StringRef Section, unsigned type, unsigned flags, 51218893Sdim SectionKind K, unsigned entrySize, const MCSymbol *group) 52208599Srdivacky : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags), 53218893Sdim EntrySize(entrySize), Group(group) {} 54207618Srdivacky ~MCSectionELF(); 55198090Srdivackypublic: 56198090Srdivacky 57198090Srdivacky /// ShouldOmitSectionDirective - Decides whether a '.section' directive 58198090Srdivacky /// should be printed before the section name 59202878Srdivacky bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const; 60198090Srdivacky 61205218Srdivacky StringRef getSectionName() const { return SectionName; } 62249423Sdim virtual std::string getLabelBeginName() const { 63249423Sdim return SectionName.str() + "_begin"; } 64249423Sdim virtual std::string getLabelEndName() const { 65249423Sdim return SectionName.str() + "_end"; 66249423Sdim } 67198090Srdivacky unsigned getType() const { return Type; } 68198090Srdivacky unsigned getFlags() const { return Flags; } 69212904Sdim unsigned getEntrySize() const { return EntrySize; } 70218893Sdim const MCSymbol *getGroup() const { return Group; } 71218893Sdim 72207618Srdivacky void PrintSwitchToSection(const MCAsmInfo &MAI, 73251662Sdim raw_ostream &OS, 74251662Sdim const MCExpr *Subsection) const; 75218893Sdim virtual bool UseCodeAlign() const; 76218893Sdim virtual bool isVirtualSection() const; 77218893Sdim 78206274Srdivacky /// isBaseAddressKnownZero - We know that non-allocatable sections (like 79206274Srdivacky /// debug info) have a base of zero. 80206274Srdivacky virtual bool isBaseAddressKnownZero() const { 81218893Sdim return (getFlags() & ELF::SHF_ALLOC) == 0; 82206274Srdivacky } 83208599Srdivacky 84208599Srdivacky static bool classof(const MCSection *S) { 85208599Srdivacky return S->getVariant() == SV_ELF; 86208599Srdivacky } 87218893Sdim 88218893Sdim // Return the entry size for sections with fixed-width data. 89218893Sdim static unsigned DetermineEntrySize(SectionKind Kind); 90218893Sdim 91198090Srdivacky}; 92198090Srdivacky 93198090Srdivacky} // end namespace llvm 94198090Srdivacky 95198090Srdivacky#endif 96