1//===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file declares the MCSectionELF class. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_MC_MCSECTIONELF_H 15#define LLVM_MC_MCSECTIONELF_H 16 17#include "llvm/MC/MCSection.h" 18#include "llvm/Support/ELF.h" 19#include "llvm/ADT/StringRef.h" 20 21namespace llvm { 22 23class MCSymbol; 24 25/// MCSectionELF - This represents a section on linux, lots of unix variants 26/// and some bare metal systems. 27class MCSectionELF : public MCSection { 28 /// SectionName - This is the name of the section. The referenced memory is 29 /// owned by TargetLoweringObjectFileELF's ELFUniqueMap. 30 StringRef SectionName; 31 32 /// Type - This is the sh_type field of a section, drawn from the enums below. 33 unsigned Type; 34 35 /// Flags - This is the sh_flags field of a section, drawn from the enums. 36 /// below. 37 unsigned Flags; 38 39 /// EntrySize - The size of each entry in this section. This size only 40 /// makes sense for sections that contain fixed-sized entries. If a 41 /// section does not contain fixed-sized entries 'EntrySize' will be 0. 42 unsigned EntrySize; 43 44 const MCSymbol *Group; 45 46private: 47 friend class MCContext; 48 MCSectionELF(StringRef Section, unsigned type, unsigned flags, 49 SectionKind K, unsigned entrySize, const MCSymbol *group) 50 : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags), 51 EntrySize(entrySize), Group(group) {} 52 ~MCSectionELF(); 53public: 54 55 /// ShouldOmitSectionDirective - Decides whether a '.section' directive 56 /// should be printed before the section name 57 bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const; 58 59 StringRef getSectionName() const { return SectionName; } 60 unsigned getType() const { return Type; } 61 unsigned getFlags() const { return Flags; } 62 unsigned getEntrySize() const { return EntrySize; } 63 const MCSymbol *getGroup() const { return Group; } 64 65 void PrintSwitchToSection(const MCAsmInfo &MAI, 66 raw_ostream &OS) const; 67 virtual bool UseCodeAlign() const; 68 virtual bool isVirtualSection() const; 69 70 /// isBaseAddressKnownZero - We know that non-allocatable sections (like 71 /// debug info) have a base of zero. 72 virtual bool isBaseAddressKnownZero() const { 73 return (getFlags() & ELF::SHF_ALLOC) == 0; 74 } 75 76 static bool classof(const MCSection *S) { 77 return S->getVariant() == SV_ELF; 78 } 79 static bool classof(const MCSectionELF *) { return true; } 80 81 // Return the entry size for sections with fixed-width data. 82 static unsigned DetermineEntrySize(SectionKind Kind); 83 84}; 85 86} // end namespace llvm 87 88#endif 89