MCSectionELF.h revision 206274
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 17198090Srdivacky#include "llvm/MC/MCSection.h" 18198090Srdivacky 19198090Srdivackynamespace llvm { 20198090Srdivacky 21198090Srdivacky/// MCSectionELF - This represents a section on linux, lots of unix variants 22198090Srdivacky/// and some bare metal systems. 23198090Srdivackyclass MCSectionELF : public MCSection { 24205218Srdivacky /// SectionName - This is the name of the section. The referenced memory is 25205218Srdivacky /// owned by TargetLoweringObjectFileELF's ELFUniqueMap. 26205218Srdivacky StringRef SectionName; 27198090Srdivacky 28198090Srdivacky /// Type - This is the sh_type field of a section, drawn from the enums below. 29198090Srdivacky unsigned Type; 30198090Srdivacky 31198090Srdivacky /// Flags - This is the sh_flags field of a section, drawn from the enums. 32198090Srdivacky /// below. 33198090Srdivacky unsigned Flags; 34198090Srdivacky 35198090Srdivacky /// IsExplicit - Indicates that this section comes from globals with an 36202878Srdivacky /// explicit section specified. 37198090Srdivacky bool IsExplicit; 38198090Srdivacky 39198090Srdivackyprotected: 40199481Srdivacky MCSectionELF(StringRef Section, unsigned type, unsigned flags, 41198090Srdivacky SectionKind K, bool isExplicit) 42205218Srdivacky : MCSection(K), SectionName(Section), Type(type), Flags(flags), 43198090Srdivacky IsExplicit(isExplicit) {} 44198090Srdivackypublic: 45198090Srdivacky 46199481Srdivacky static MCSectionELF *Create(StringRef Section, unsigned Type, 47198090Srdivacky unsigned Flags, SectionKind K, bool isExplicit, 48198090Srdivacky MCContext &Ctx); 49198090Srdivacky 50198090Srdivacky /// ShouldOmitSectionDirective - Decides whether a '.section' directive 51198090Srdivacky /// should be printed before the section name 52202878Srdivacky bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const; 53198090Srdivacky 54198090Srdivacky /// ShouldPrintSectionType - Only prints the section type if supported 55198090Srdivacky bool ShouldPrintSectionType(unsigned Ty) const; 56198090Srdivacky 57198090Srdivacky /// HasCommonSymbols - True if this section holds common symbols, this is 58198090Srdivacky /// indicated on the ELF object file by a symbol with SHN_COMMON section 59198090Srdivacky /// header index. 60198090Srdivacky bool HasCommonSymbols() const; 61198090Srdivacky 62198090Srdivacky /// These are the section type and flags fields. An ELF section can have 63198090Srdivacky /// only one Type, but can have more than one of the flags specified. 64198090Srdivacky /// 65198090Srdivacky /// Valid section types. 66198090Srdivacky enum { 67198090Srdivacky // This value marks the section header as inactive. 68198090Srdivacky SHT_NULL = 0x00U, 69198090Srdivacky 70198090Srdivacky // Holds information defined by the program, with custom format and meaning. 71198090Srdivacky SHT_PROGBITS = 0x01U, 72198090Srdivacky 73198090Srdivacky // This section holds a symbol table. 74198090Srdivacky SHT_SYMTAB = 0x02U, 75198090Srdivacky 76198090Srdivacky // The section holds a string table. 77198090Srdivacky SHT_STRTAB = 0x03U, 78198090Srdivacky 79198090Srdivacky // The section holds relocation entries with explicit addends. 80198090Srdivacky SHT_RELA = 0x04U, 81198090Srdivacky 82198090Srdivacky // The section holds a symbol hash table. 83198090Srdivacky SHT_HASH = 0x05U, 84198090Srdivacky 85198090Srdivacky // Information for dynamic linking. 86198090Srdivacky SHT_DYNAMIC = 0x06U, 87198090Srdivacky 88198090Srdivacky // The section holds information that marks the file in some way. 89198090Srdivacky SHT_NOTE = 0x07U, 90198090Srdivacky 91198090Srdivacky // A section of this type occupies no space in the file. 92198090Srdivacky SHT_NOBITS = 0x08U, 93198090Srdivacky 94198090Srdivacky // The section holds relocation entries without explicit addends. 95198090Srdivacky SHT_REL = 0x09U, 96198090Srdivacky 97198090Srdivacky // This section type is reserved but has unspecified semantics. 98198090Srdivacky SHT_SHLIB = 0x0AU, 99198090Srdivacky 100198090Srdivacky // This section holds a symbol table. 101198090Srdivacky SHT_DYNSYM = 0x0BU, 102198090Srdivacky 103198090Srdivacky // This section contains an array of pointers to initialization functions. 104198090Srdivacky SHT_INIT_ARRAY = 0x0EU, 105198090Srdivacky 106198090Srdivacky // This section contains an array of pointers to termination functions. 107198090Srdivacky SHT_FINI_ARRAY = 0x0FU, 108198090Srdivacky 109198090Srdivacky // This section contains an array of pointers to functions that are invoked 110198090Srdivacky // before all other initialization functions. 111198090Srdivacky SHT_PREINIT_ARRAY = 0x10U, 112198090Srdivacky 113198090Srdivacky // A section group is a set of sections that are related and that must be 114198090Srdivacky // treated specially by the linker. 115198090Srdivacky SHT_GROUP = 0x11U, 116198090Srdivacky 117198090Srdivacky // This section is associated with a section of type SHT_SYMTAB, when the 118198090Srdivacky // referenced symbol table contain the escape value SHN_XINDEX 119198090Srdivacky SHT_SYMTAB_SHNDX = 0x12U, 120198090Srdivacky 121198090Srdivacky LAST_KNOWN_SECTION_TYPE = SHT_SYMTAB_SHNDX 122198090Srdivacky }; 123198090Srdivacky 124198090Srdivacky /// Valid section flags. 125198090Srdivacky enum { 126198090Srdivacky // The section contains data that should be writable. 127198090Srdivacky SHF_WRITE = 0x1U, 128198090Srdivacky 129198090Srdivacky // The section occupies memory during execution. 130198090Srdivacky SHF_ALLOC = 0x2U, 131198090Srdivacky 132198090Srdivacky // The section contains executable machine instructions. 133198090Srdivacky SHF_EXECINSTR = 0x4U, 134198090Srdivacky 135198090Srdivacky // The data in the section may be merged to eliminate duplication. 136198090Srdivacky SHF_MERGE = 0x10U, 137198090Srdivacky 138198090Srdivacky // Elements in the section consist of null-terminated character strings. 139198090Srdivacky SHF_STRINGS = 0x20U, 140198090Srdivacky 141198090Srdivacky // A field in this section holds a section header table index. 142198090Srdivacky SHF_INFO_LINK = 0x40U, 143198090Srdivacky 144198090Srdivacky // Adds special ordering requirements for link editors. 145198090Srdivacky SHF_LINK_ORDER = 0x80U, 146198090Srdivacky 147198090Srdivacky // This section requires special OS-specific processing to avoid incorrect 148198090Srdivacky // behavior. 149198090Srdivacky SHF_OS_NONCONFORMING = 0x100U, 150198090Srdivacky 151198090Srdivacky // This section is a member of a section group. 152198090Srdivacky SHF_GROUP = 0x200U, 153198090Srdivacky 154198090Srdivacky // This section holds Thread-Local Storage. 155198090Srdivacky SHF_TLS = 0x400U, 156198090Srdivacky 157198090Srdivacky /// FIRST_TARGET_DEP_FLAG - This is the first flag that subclasses are 158198090Srdivacky /// allowed to specify. 159198090Srdivacky FIRST_TARGET_DEP_FLAG = 0x800U, 160198090Srdivacky 161198090Srdivacky /// TARGET_INDEP_SHF - This is the bitmask for all the target independent 162198090Srdivacky /// section flags. Targets can define their own target flags above these. 163198090Srdivacky /// If they do that, they should implement their own MCSectionELF subclasses 164198090Srdivacky /// and implement the virtual method hooks below to handle printing needs. 165198090Srdivacky TARGET_INDEP_SHF = FIRST_TARGET_DEP_FLAG-1U 166198090Srdivacky }; 167198090Srdivacky 168205218Srdivacky StringRef getSectionName() const { return SectionName; } 169198090Srdivacky unsigned getType() const { return Type; } 170198090Srdivacky unsigned getFlags() const { return Flags; } 171198090Srdivacky 172198090Srdivacky virtual void PrintSwitchToSection(const MCAsmInfo &MAI, 173198090Srdivacky raw_ostream &OS) const; 174198090Srdivacky 175206274Srdivacky /// isBaseAddressKnownZero - We know that non-allocatable sections (like 176206274Srdivacky /// debug info) have a base of zero. 177206274Srdivacky virtual bool isBaseAddressKnownZero() const { 178206274Srdivacky return (getFlags() & SHF_ALLOC) == 0; 179206274Srdivacky } 180198090Srdivacky 181198090Srdivacky /// PrintTargetSpecificSectionFlags - Targets that define their own 182198090Srdivacky /// MCSectionELF subclasses with target specific section flags should 183198090Srdivacky /// implement this method if they end up adding letters to the attributes 184198090Srdivacky /// list. 185198090Srdivacky virtual void PrintTargetSpecificSectionFlags(const MCAsmInfo &MAI, 186198090Srdivacky raw_ostream &OS) const { 187198090Srdivacky } 188198090Srdivacky 189198090Srdivacky 190198090Srdivacky}; 191198090Srdivacky 192198090Srdivacky} // end namespace llvm 193198090Srdivacky 194198090Srdivacky#endif 195