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