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