LLVM API Documentation
00001 //===- MCSectionMachO.h - MachO 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 MCSectionMachO class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_MC_MCSECTIONMACHO_H 00015 #define LLVM_MC_MCSECTIONMACHO_H 00016 00017 #include "llvm/ADT/StringRef.h" 00018 #include "llvm/MC/MCSection.h" 00019 00020 namespace llvm { 00021 00022 /// MCSectionMachO - This represents a section on a Mach-O system (used by 00023 /// Mac OS X). On a Mac system, these are also described in 00024 /// /usr/include/mach-o/loader.h. 00025 class MCSectionMachO : public MCSection { 00026 char SegmentName[16]; // Not necessarily null terminated! 00027 char SectionName[16]; // Not necessarily null terminated! 00028 00029 /// TypeAndAttributes - This is the SECTION_TYPE and SECTION_ATTRIBUTES 00030 /// field of a section, drawn from the enums below. 00031 unsigned TypeAndAttributes; 00032 00033 /// Reserved2 - The 'reserved2' field of a section, used to represent the 00034 /// size of stubs, for example. 00035 unsigned Reserved2; 00036 00037 MCSectionMachO(StringRef Segment, StringRef Section, 00038 unsigned TAA, unsigned reserved2, SectionKind K); 00039 friend class MCContext; 00040 public: 00041 00042 /// These are the section type and attributes fields. A MachO section can 00043 /// have only one Type, but can have any of the attributes specified. 00044 enum { 00045 // TypeAndAttributes bitmasks. 00046 SECTION_TYPE = 0x000000FFU, 00047 SECTION_ATTRIBUTES = 0xFFFFFF00U, 00048 00049 // Valid section types. 00050 00051 /// S_REGULAR - Regular section. 00052 S_REGULAR = 0x00U, 00053 /// S_ZEROFILL - Zero fill on demand section. 00054 S_ZEROFILL = 0x01U, 00055 /// S_CSTRING_LITERALS - Section with literal C strings. 00056 S_CSTRING_LITERALS = 0x02U, 00057 /// S_4BYTE_LITERALS - Section with 4 byte literals. 00058 S_4BYTE_LITERALS = 0x03U, 00059 /// S_8BYTE_LITERALS - Section with 8 byte literals. 00060 S_8BYTE_LITERALS = 0x04U, 00061 /// S_LITERAL_POINTERS - Section with pointers to literals. 00062 S_LITERAL_POINTERS = 0x05U, 00063 /// S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers. 00064 S_NON_LAZY_SYMBOL_POINTERS = 0x06U, 00065 /// S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers. 00066 S_LAZY_SYMBOL_POINTERS = 0x07U, 00067 /// S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in 00068 /// the Reserved2 field. 00069 S_SYMBOL_STUBS = 0x08U, 00070 /// S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for 00071 /// initialization. 00072 S_MOD_INIT_FUNC_POINTERS = 0x09U, 00073 /// S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for 00074 /// termination. 00075 S_MOD_TERM_FUNC_POINTERS = 0x0AU, 00076 /// S_COALESCED - Section contains symbols that are to be coalesced. 00077 S_COALESCED = 0x0BU, 00078 /// S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4 00079 /// gigabytes). 00080 S_GB_ZEROFILL = 0x0CU, 00081 /// S_INTERPOSING - Section with only pairs of function pointers for 00082 /// interposing. 00083 S_INTERPOSING = 0x0DU, 00084 /// S_16BYTE_LITERALS - Section with only 16 byte literals. 00085 S_16BYTE_LITERALS = 0x0EU, 00086 /// S_DTRACE_DOF - Section contains DTrace Object Format. 00087 S_DTRACE_DOF = 0x0FU, 00088 /// S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to 00089 /// lazy loaded dylibs. 00090 S_LAZY_DYLIB_SYMBOL_POINTERS = 0x10U, 00091 /// S_THREAD_LOCAL_REGULAR - Section with .... 00092 S_THREAD_LOCAL_REGULAR = 0x11U, 00093 /// S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section. 00094 S_THREAD_LOCAL_ZEROFILL = 0x12U, 00095 /// S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure 00096 /// data. 00097 S_THREAD_LOCAL_VARIABLES = 0x13U, 00098 /// S_THREAD_LOCAL_VARIABLE_POINTERS - Section with .... 00099 S_THREAD_LOCAL_VARIABLE_POINTERS = 0x14U, 00100 /// S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local 00101 /// variable initialization pointers to functions. 00102 S_THREAD_LOCAL_INIT_FUNCTION_POINTERS = 0x15U, 00103 00104 LAST_KNOWN_SECTION_TYPE = S_THREAD_LOCAL_INIT_FUNCTION_POINTERS, 00105 00106 00107 // Valid section attributes. 00108 00109 /// S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine 00110 /// instructions. 00111 S_ATTR_PURE_INSTRUCTIONS = 1U << 31, 00112 /// S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be 00113 /// in a ranlib table of contents. 00114 S_ATTR_NO_TOC = 1U << 30, 00115 /// S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section 00116 /// in files with the MY_DYLDLINK flag. 00117 S_ATTR_STRIP_STATIC_SYMS = 1U << 29, 00118 /// S_ATTR_NO_DEAD_STRIP - No dead stripping. 00119 S_ATTR_NO_DEAD_STRIP = 1U << 28, 00120 /// S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks. 00121 S_ATTR_LIVE_SUPPORT = 1U << 27, 00122 /// S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by 00123 /// dyld. 00124 S_ATTR_SELF_MODIFYING_CODE = 1U << 26, 00125 /// S_ATTR_DEBUG - A debug section. 00126 S_ATTR_DEBUG = 1U << 25, 00127 /// S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions. 00128 S_ATTR_SOME_INSTRUCTIONS = 1U << 10, 00129 /// S_ATTR_EXT_RELOC - Section has external relocation entries. 00130 S_ATTR_EXT_RELOC = 1U << 9, 00131 /// S_ATTR_LOC_RELOC - Section has local relocation entries. 00132 S_ATTR_LOC_RELOC = 1U << 8 00133 }; 00134 00135 StringRef getSegmentName() const { 00136 // SegmentName is not necessarily null terminated! 00137 if (SegmentName[15]) 00138 return StringRef(SegmentName, 16); 00139 return StringRef(SegmentName); 00140 } 00141 StringRef getSectionName() const { 00142 // SectionName is not necessarily null terminated! 00143 if (SectionName[15]) 00144 return StringRef(SectionName, 16); 00145 return StringRef(SectionName); 00146 } 00147 00148 virtual std::string getLabelBeginName() const { 00149 return StringRef(getSegmentName().str() + getSectionName().str() + "_begin"); 00150 } 00151 00152 virtual std::string getLabelEndName() const { 00153 return StringRef(getSegmentName().str() + getSectionName().str() + "_end"); 00154 } 00155 00156 unsigned getTypeAndAttributes() const { return TypeAndAttributes; } 00157 unsigned getStubSize() const { return Reserved2; } 00158 00159 unsigned getType() const { return TypeAndAttributes & SECTION_TYPE; } 00160 bool hasAttribute(unsigned Value) const { 00161 return (TypeAndAttributes & Value) != 0; 00162 } 00163 00164 /// ParseSectionSpecifier - Parse the section specifier indicated by "Spec". 00165 /// This is a string that can appear after a .section directive in a mach-o 00166 /// flavored .s file. If successful, this fills in the specified Out 00167 /// parameters and returns an empty string. When an invalid section 00168 /// specifier is present, this returns a string indicating the problem. 00169 /// If no TAA was parsed, TAA is not altered, and TAAWasSet becomes false. 00170 static std::string ParseSectionSpecifier(StringRef Spec, // In. 00171 StringRef &Segment, // Out. 00172 StringRef &Section, // Out. 00173 unsigned &TAA, // Out. 00174 bool &TAAParsed, // Out. 00175 unsigned &StubSize); // Out. 00176 00177 virtual void PrintSwitchToSection(const MCAsmInfo &MAI, 00178 raw_ostream &OS, 00179 const MCExpr *Subsection) const; 00180 virtual bool UseCodeAlign() const; 00181 virtual bool isVirtualSection() const; 00182 00183 static bool classof(const MCSection *S) { 00184 return S->getVariant() == SV_MachO; 00185 } 00186 }; 00187 00188 } // end namespace llvm 00189 00190 #endif