MCSectionMachO.h revision ed84062812c7b8a82d0e8128a22aa1aa07a14d79
15d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner//===- MCSectionMachO.h - MachO Machine Code Sections -----------*- C++ -*-===// 25d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner// 35d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner// The LLVM Compiler Infrastructure 45d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner// 55d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner// This file is distributed under the University of Illinois Open Source 65d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner// License. See LICENSE.TXT for details. 75d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner// 85d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner//===----------------------------------------------------------------------===// 95d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner// 105d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner// This file declares the MCSectionMachO class. 115d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner// 125d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner//===----------------------------------------------------------------------===// 135d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 145d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#ifndef LLVM_MC_MCSECTIONMACHO_H 1528a09b6fe8d8f3e92ffee9263609a6da881b8818David 'Digit' Turner#define LLVM_MC_MCSECTIONMACHO_H 166af6765e2f3bc930d0dce21d752bea570a1b1362David 'Digit' Turner 1734c48ff1e3ad5cd2084ca40188754d45f423750bDavid 'Digit' Turner#include "llvm/MC/MCSection.h" 18e1e03df288d5a44bfbffbd86588395c7cbbc27dfDavid 'Digit' Turner#include "llvm/ADT/StringRef.h" 19d0edecb426b34ddb9b10b81dea19aee04a61a385David 'Digit' Turner 205d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnernamespace llvm { 215d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 225d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner/// MCSectionMachO - This represents a section on a Mach-O system (used by 235d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner/// Mac OS X). On a Mac system, these are also described in 245d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner/// /usr/include/mach-o/loader.h. 255d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerclass MCSectionMachO : public MCSection { 265d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner char SegmentName[16]; // Not necessarily null terminated! 275d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner char SectionName[16]; // Not necessarily null terminated! 285d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 295d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// TypeAndAttributes - This is the SECTION_TYPE and SECTION_ATTRIBUTES 305d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// field of a section, drawn from the enums below. 315d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner unsigned TypeAndAttributes; 325d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 335d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// Reserved2 - The 'reserved2' field of a section, used to represent the 345d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// size of stubs, for example. 355d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner unsigned Reserved2; 365d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 375d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner MCSectionMachO(StringRef Segment, StringRef Section, 385d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner unsigned TAA, unsigned reserved2, SectionKind K); 395d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner friend class MCContext; 405d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerpublic: 415d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 425d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// These are the section type and attributes fields. A MachO section can 435d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// have only one Type, but can have any of the attributes specified. 445d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner enum { 455d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner // TypeAndAttributes bitmasks. 465d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner SECTION_TYPE = 0x000000FFU, 475d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner SECTION_ATTRIBUTES = 0xFFFFFF00U, 485d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 495d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner // Valid section types. 505d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 515d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// S_REGULAR - Regular section. 525d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner S_REGULAR = 0x00U, 535d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// S_ZEROFILL - Zero fill on demand section. 545d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner S_ZEROFILL = 0x01U, 555d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// S_CSTRING_LITERALS - Section with literal C strings. 565d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner S_CSTRING_LITERALS = 0x02U, 575d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// S_4BYTE_LITERALS - Section with 4 byte literals. 585d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner S_4BYTE_LITERALS = 0x03U, 595d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// S_8BYTE_LITERALS - Section with 8 byte literals. 605d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner S_8BYTE_LITERALS = 0x04U, 615d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// S_LITERAL_POINTERS - Section with pointers to literals. 625d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner S_LITERAL_POINTERS = 0x05U, 635d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner /// S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers. 645d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner S_NON_LAZY_SYMBOL_POINTERS = 0x06U, 65 /// S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers. 66 S_LAZY_SYMBOL_POINTERS = 0x07U, 67 /// S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in 68 /// the Reserved2 field. 69 S_SYMBOL_STUBS = 0x08U, 70 /// S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for 71 /// initialization. 72 S_MOD_INIT_FUNC_POINTERS = 0x09U, 73 /// S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for 74 /// termination. 75 S_MOD_TERM_FUNC_POINTERS = 0x0AU, 76 /// S_COALESCED - Section contains symbols that are to be coalesced. 77 S_COALESCED = 0x0BU, 78 /// S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4 79 /// gigabytes). 80 S_GB_ZEROFILL = 0x0CU, 81 /// S_INTERPOSING - Section with only pairs of function pointers for 82 /// interposing. 83 S_INTERPOSING = 0x0DU, 84 /// S_16BYTE_LITERALS - Section with only 16 byte literals. 85 S_16BYTE_LITERALS = 0x0EU, 86 /// S_DTRACE_DOF - Section contains DTrace Object Format. 87 S_DTRACE_DOF = 0x0FU, 88 /// S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to 89 /// lazy loaded dylibs. 90 S_LAZY_DYLIB_SYMBOL_POINTERS = 0x10U, 91 /// S_THREAD_LOCAL_REGULAR - Section with .... 92 S_THREAD_LOCAL_REGULAR = 0x11U, 93 /// S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section. 94 S_THREAD_LOCAL_ZEROFILL = 0x12U, 95 /// S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure 96 /// data. 97 S_THREAD_LOCAL_VARIABLES = 0x13U, 98 /// S_THREAD_LOCAL_VARIABLE_POINTERS - Section with .... 99 S_THREAD_LOCAL_VARIABLE_POINTERS = 0x14U, 100 /// S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local 101 /// variable initialization pointers to functions. 102 S_THREAD_LOCAL_INIT_FUNCTION_POINTERS = 0x15U, 103 104 LAST_KNOWN_SECTION_TYPE = S_THREAD_LOCAL_INIT_FUNCTION_POINTERS, 105 106 107 // Valid section attributes. 108 109 /// S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine 110 /// instructions. 111 S_ATTR_PURE_INSTRUCTIONS = 1U << 31, 112 /// S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be 113 /// in a ranlib table of contents. 114 S_ATTR_NO_TOC = 1U << 30, 115 /// S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section 116 /// in files with the MY_DYLDLINK flag. 117 S_ATTR_STRIP_STATIC_SYMS = 1U << 29, 118 /// S_ATTR_NO_DEAD_STRIP - No dead stripping. 119 S_ATTR_NO_DEAD_STRIP = 1U << 28, 120 /// S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks. 121 S_ATTR_LIVE_SUPPORT = 1U << 27, 122 /// S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by 123 /// dyld. 124 S_ATTR_SELF_MODIFYING_CODE = 1U << 26, 125 /// S_ATTR_DEBUG - A debug section. 126 S_ATTR_DEBUG = 1U << 25, 127 /// S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions. 128 S_ATTR_SOME_INSTRUCTIONS = 1U << 10, 129 /// S_ATTR_EXT_RELOC - Section has external relocation entries. 130 S_ATTR_EXT_RELOC = 1U << 9, 131 /// S_ATTR_LOC_RELOC - Section has local relocation entries. 132 S_ATTR_LOC_RELOC = 1U << 8 133 }; 134 135 StringRef getSegmentName() const { 136 // SegmentName is not necessarily null terminated! 137 if (SegmentName[15]) 138 return StringRef(SegmentName, 16); 139 return StringRef(SegmentName); 140 } 141 StringRef getSectionName() const { 142 // SectionName is not necessarily null terminated! 143 if (SectionName[15]) 144 return StringRef(SectionName, 16); 145 return StringRef(SectionName); 146 } 147 148 unsigned getTypeAndAttributes() const { return TypeAndAttributes; } 149 unsigned getStubSize() const { return Reserved2; } 150 151 unsigned getType() const { return TypeAndAttributes & SECTION_TYPE; } 152 bool hasAttribute(unsigned Value) const { 153 return (TypeAndAttributes & Value) != 0; 154 } 155 156 /// ParseSectionSpecifier - Parse the section specifier indicated by "Spec". 157 /// This is a string that can appear after a .section directive in a mach-o 158 /// flavored .s file. If successful, this fills in the specified Out 159 /// parameters and returns an empty string. When an invalid section 160 /// specifier is present, this returns a string indicating the problem. 161 /// If no TAA was parsed, TAA is not altered, and TAAWasSet becomes false. 162 static std::string ParseSectionSpecifier(StringRef Spec, // In. 163 StringRef &Segment, // Out. 164 StringRef &Section, // Out. 165 unsigned &TAA, // Out. 166 bool &TAAParsed, // Out. 167 unsigned &StubSize); // Out. 168 169 virtual void PrintSwitchToSection(const MCAsmInfo &MAI, 170 raw_ostream &OS) const; 171 virtual bool UseCodeAlign() const; 172 virtual bool isVirtualSection() const; 173 174 static bool classof(const MCSection *S) { 175 return S->getVariant() == SV_MachO; 176 } 177}; 178 179} // end namespace llvm 180 181#endif 182