LLVM API Documentation
00001 //===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file declares the MCSectionELF class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_MC_MCSECTIONELF_H 00015 #define LLVM_MC_MCSECTIONELF_H 00016 00017 #include "llvm/MC/MCSection.h" 00018 00019 namespace llvm { 00020 00021 /// MCSectionELF - This represents a section on linux, lots of unix variants 00022 /// and some bare metal systems. 00023 class MCSectionELF : public MCSection { 00024 std::string SectionName; 00025 00026 /// Type - This is the sh_type field of a section, drawn from the enums below. 00027 unsigned Type; 00028 00029 /// Flags - This is the sh_flags field of a section, drawn from the enums. 00030 /// below. 00031 unsigned Flags; 00032 00033 /// IsExplicit - Indicates that this section comes from globals with an 00034 /// explicit section specfied. 00035 bool IsExplicit; 00036 00037 protected: 00038 MCSectionELF(const StringRef &Section, unsigned type, unsigned flags, 00039 SectionKind K, bool isExplicit) 00040 : MCSection(K), SectionName(Section.str()), Type(type), Flags(flags), 00041 IsExplicit(isExplicit) {} 00042 public: 00043 00044 static MCSectionELF *Create(const StringRef &Section, unsigned Type, 00045 unsigned Flags, SectionKind K, bool isExplicit, 00046 MCContext &Ctx); 00047 00048 /// ShouldOmitSectionDirective - Decides whether a '.section' directive 00049 /// should be printed before the section name 00050 bool ShouldOmitSectionDirective(const char *Name, 00051 const TargetAsmInfo &TAI) const; 00052 00053 /// ShouldPrintSectionType - Only prints the section type if supported 00054 bool ShouldPrintSectionType(unsigned Ty) const; 00055 00056 /// HasCommonSymbols - True if this section holds common symbols, this is 00057 /// indicated on the ELF object file by a symbol with SHN_COMMON section 00058 /// header index. 00059 bool HasCommonSymbols() const; 00060 00061 /// These are the section type and flags fields. An ELF section can have 00062 /// only one Type, but can have more than one of the flags specified. 00063 /// 00064 /// Valid section types. 00065 enum { 00066 // This value marks the section header as inactive. 00067 SHT_NULL = 0x00U, 00068 00069 // Holds information defined by the program, with custom format and meaning. 00070 SHT_PROGBITS = 0x01U, 00071 00072 // This section holds a symbol table. 00073 SHT_SYMTAB = 0x02U, 00074 00075 // The section holds a string table. 00076 SHT_STRTAB = 0x03U, 00077 00078 // The section holds relocation entries with explicit addends. 00079 SHT_RELA = 0x04U, 00080 00081 // The section holds a symbol hash table. 00082 SHT_HASH = 0x05U, 00083 00084 // Information for dynamic linking. 00085 SHT_DYNAMIC = 0x06U, 00086 00087 // The section holds information that marks the file in some way. 00088 SHT_NOTE = 0x07U, 00089 00090 // A section of this type occupies no space in the file. 00091 SHT_NOBITS = 0x08U, 00092 00093 // The section holds relocation entries without explicit addends. 00094 SHT_REL = 0x09U, 00095 00096 // This section type is reserved but has unspecified semantics. 00097 SHT_SHLIB = 0x0AU, 00098 00099 // This section holds a symbol table. 00100 SHT_DYNSYM = 0x0BU, 00101 00102 // This section contains an array of pointers to initialization functions. 00103 SHT_INIT_ARRAY = 0x0EU, 00104 00105 // This section contains an array of pointers to termination functions. 00106 SHT_FINI_ARRAY = 0x0FU, 00107 00108 // This section contains an array of pointers to functions that are invoked 00109 // before all other initialization functions. 00110 SHT_PREINIT_ARRAY = 0x10U, 00111 00112 // A section group is a set of sections that are related and that must be 00113 // treated specially by the linker. 00114 SHT_GROUP = 0x11U, 00115 00116 // This section is associated with a section of type SHT_SYMTAB, when the 00117 // referenced symbol table contain the escape value SHN_XINDEX 00118 SHT_SYMTAB_SHNDX = 0x12U, 00119 00120 LAST_KNOWN_SECTION_TYPE = SHT_SYMTAB_SHNDX 00121 }; 00122 00123 /// Valid section flags. 00124 enum { 00125 // The section contains data that should be writable. 00126 SHF_WRITE = 0x1U, 00127 00128 // The section occupies memory during execution. 00129 SHF_ALLOC = 0x2U, 00130 00131 // The section contains executable machine instructions. 00132 SHF_EXECINSTR = 0x4U, 00133 00134 // The data in the section may be merged to eliminate duplication. 00135 SHF_MERGE = 0x10U, 00136 00137 // Elements in the section consist of null-terminated character strings. 00138 SHF_STRINGS = 0x20U, 00139 00140 // A field in this section holds a section header table index. 00141 SHF_INFO_LINK = 0x40U, 00142 00143 // Adds special ordering requirements for link editors. 00144 SHF_LINK_ORDER = 0x80U, 00145 00146 // This section requires special OS-specific processing to avoid incorrect 00147 // behavior. 00148 SHF_OS_NONCONFORMING = 0x100U, 00149 00150 // This section is a member of a section group. 00151 SHF_GROUP = 0x200U, 00152 00153 // This section holds Thread-Local Storage. 00154 SHF_TLS = 0x400U, 00155 00156 /// FIRST_TARGET_DEP_FLAG - This is the first flag that subclasses are 00157 /// allowed to specify. 00158 FIRST_TARGET_DEP_FLAG = 0x800U, 00159 00160 /// TARGET_INDEP_SHF - This is the bitmask for all the target independent 00161 /// section flags. Targets can define their own target flags above these. 00162 /// If they do that, they should implement their own MCSectionELF subclasses 00163 /// and implement the virtual method hooks below to handle printing needs. 00164 TARGET_INDEP_SHF = FIRST_TARGET_DEP_FLAG-1U 00165 }; 00166 00167 StringRef getSectionName() const { 00168 return StringRef(SectionName); 00169 } 00170 00171 unsigned getType() const { return Type; } 00172 unsigned getFlags() const { return Flags; } 00173 00174 virtual void PrintSwitchToSection(const TargetAsmInfo &TAI, 00175 raw_ostream &OS) const; 00176 00177 00178 /// PrintTargetSpecificSectionFlags - Targets that define their own 00179 /// MCSectionELF subclasses with target specific section flags should 00180 /// implement this method if they end up adding letters to the attributes 00181 /// list. 00182 virtual void PrintTargetSpecificSectionFlags(const TargetAsmInfo &TAI, 00183 raw_ostream &OS) const { 00184 } 00185 00186 00187 }; 00188 00189 } // end namespace llvm 00190 00191 #endif