1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===// 2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The LLVM Compiler Infrastructure 4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source 6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details. 7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file declares the MCSectionELF class. 11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LLVM_MC_MCSECTIONELF_H 15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LLVM_MC_MCSECTIONELF_H 16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/MC/MCSection.h" 1819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#include "llvm/Support/ELF.h" 19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm { 2119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 2219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanclass MCSymbol; 2319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// MCSectionELF - This represents a section on linux, lots of unix variants 25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// and some bare metal systems. 26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MCSectionELF : public MCSection { 27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// SectionName - This is the name of the section. The referenced memory is 28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// owned by TargetLoweringObjectFileELF's ELFUniqueMap. 29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman StringRef SectionName; 3019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// Type - This is the sh_type field of a section, drawn from the enums below. 32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman unsigned Type; 3319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// Flags - This is the sh_flags field of a section, drawn from the enums. 35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// below. 36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman unsigned Flags; 37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 3819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// EntrySize - The size of each entry in this section. This size only 3919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// makes sense for sections that contain fixed-sized entries. If a 4019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// section does not contain fixed-sized entries 'EntrySize' will be 0. 4119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman unsigned EntrySize; 4219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 4319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman const MCSymbol *Group; 4419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanprivate: 46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman friend class MCContext; 47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman MCSectionELF(StringRef Section, unsigned type, unsigned flags, 4819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman SectionKind K, unsigned entrySize, const MCSymbol *group) 49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags), 5019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman EntrySize(entrySize), Group(group) {} 51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman ~MCSectionELF(); 52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic: 53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// ShouldOmitSectionDirective - Decides whether a '.section' directive 55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// should be printed before the section name 56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const; 57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman StringRef getSectionName() const { return SectionName; } 59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman unsigned getType() const { return Type; } 60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman unsigned getFlags() const { return Flags; } 6119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman unsigned getEntrySize() const { return EntrySize; } 6219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman const MCSymbol *getGroup() const { return Group; } 6319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void PrintSwitchToSection(const MCAsmInfo &MAI, 65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman raw_ostream &OS) const; 6619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman virtual bool UseCodeAlign() const; 6719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman virtual bool isVirtualSection() const; 6819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// isBaseAddressKnownZero - We know that non-allocatable sections (like 70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// debug info) have a base of zero. 71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman virtual bool isBaseAddressKnownZero() const { 7219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return (getFlags() & ELF::SHF_ALLOC) == 0; 73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 75894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static bool classof(const MCSection *S) { 76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return S->getVariant() == SV_ELF; 77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static bool classof(const MCSectionELF *) { return true; } 7919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 8019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman // Return the entry size for sections with fixed-width data. 8119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static unsigned DetermineEntrySize(SectionKind Kind); 8219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}; 84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // end namespace llvm 86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif 88