Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCSectionMachO.cpp - MachO Code Section Representation ------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/MC/MCSectionMachO.h" |
| 11 | #include "llvm/MC/MCContext.h" |
| 12 | #include "llvm/Support/raw_ostream.h" |
Nick Lewycky | 476b242 | 2010-12-19 20:43:38 +0000 | [diff] [blame] | 13 | #include <cctype> |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 14 | using namespace llvm; |
| 15 | |
| 16 | /// SectionTypeDescriptors - These are strings that describe the various section |
| 17 | /// types. This *must* be kept in order with and stay synchronized with the |
| 18 | /// section type list. |
| 19 | static const struct { |
| 20 | const char *AssemblerName, *EnumName; |
| 21 | } SectionTypeDescriptors[MCSectionMachO::LAST_KNOWN_SECTION_TYPE+1] = { |
| 22 | { "regular", "S_REGULAR" }, // 0x00 |
| 23 | { 0, "S_ZEROFILL" }, // 0x01 |
| 24 | { "cstring_literals", "S_CSTRING_LITERALS" }, // 0x02 |
| 25 | { "4byte_literals", "S_4BYTE_LITERALS" }, // 0x03 |
| 26 | { "8byte_literals", "S_8BYTE_LITERALS" }, // 0x04 |
| 27 | { "literal_pointers", "S_LITERAL_POINTERS" }, // 0x05 |
| 28 | { "non_lazy_symbol_pointers", "S_NON_LAZY_SYMBOL_POINTERS" }, // 0x06 |
| 29 | { "lazy_symbol_pointers", "S_LAZY_SYMBOL_POINTERS" }, // 0x07 |
| 30 | { "symbol_stubs", "S_SYMBOL_STUBS" }, // 0x08 |
| 31 | { "mod_init_funcs", "S_MOD_INIT_FUNC_POINTERS" }, // 0x09 |
| 32 | { "mod_term_funcs", "S_MOD_TERM_FUNC_POINTERS" }, // 0x0A |
| 33 | { "coalesced", "S_COALESCED" }, // 0x0B |
| 34 | { 0, /*FIXME??*/ "S_GB_ZEROFILL" }, // 0x0C |
| 35 | { "interposing", "S_INTERPOSING" }, // 0x0D |
| 36 | { "16byte_literals", "S_16BYTE_LITERALS" }, // 0x0E |
| 37 | { 0, /*FIXME??*/ "S_DTRACE_DOF" }, // 0x0F |
Eric Christopher | 423c9e3 | 2010-05-17 21:02:07 +0000 | [diff] [blame] | 38 | { 0, /*FIXME??*/ "S_LAZY_DYLIB_SYMBOL_POINTERS" }, // 0x10 |
| 39 | { "thread_local_regular", "S_THREAD_LOCAL_REGULAR" }, // 0x11 |
Eric Christopher | 9b00685 | 2010-05-21 21:08:52 +0000 | [diff] [blame] | 40 | { "thread_local_zerofill", "S_THREAD_LOCAL_ZEROFILL" }, // 0x12 |
Eric Christopher | 423c9e3 | 2010-05-17 21:02:07 +0000 | [diff] [blame] | 41 | { "thread_local_variables", "S_THREAD_LOCAL_VARIABLES" }, // 0x13 |
| 42 | { "thread_local_variable_pointers", |
| 43 | "S_THREAD_LOCAL_VARIABLE_POINTERS" }, // 0x14 |
| 44 | { "thread_local_init_function_pointers", |
| 45 | "S_THREAD_LOCAL_INIT_FUNCTION_POINTERS"}, // 0x15 |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | |
| 49 | /// SectionAttrDescriptors - This is an array of descriptors for section |
| 50 | /// attributes. Unlike the SectionTypeDescriptors, this is not directly indexed |
Kevin Enderby | 5440f63 | 2009-10-07 20:57:20 +0000 | [diff] [blame] | 51 | /// by attribute, instead it is searched. The last entry has an AttrFlagEnd |
| 52 | /// AttrFlag value. |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 53 | static const struct { |
| 54 | unsigned AttrFlag; |
| 55 | const char *AssemblerName, *EnumName; |
| 56 | } SectionAttrDescriptors[] = { |
| 57 | #define ENTRY(ASMNAME, ENUM) \ |
| 58 | { MCSectionMachO::ENUM, ASMNAME, #ENUM }, |
| 59 | ENTRY("pure_instructions", S_ATTR_PURE_INSTRUCTIONS) |
| 60 | ENTRY("no_toc", S_ATTR_NO_TOC) |
| 61 | ENTRY("strip_static_syms", S_ATTR_STRIP_STATIC_SYMS) |
| 62 | ENTRY("no_dead_strip", S_ATTR_NO_DEAD_STRIP) |
| 63 | ENTRY("live_support", S_ATTR_LIVE_SUPPORT) |
| 64 | ENTRY("self_modifying_code", S_ATTR_SELF_MODIFYING_CODE) |
| 65 | ENTRY("debug", S_ATTR_DEBUG) |
| 66 | ENTRY(0 /*FIXME*/, S_ATTR_SOME_INSTRUCTIONS) |
| 67 | ENTRY(0 /*FIXME*/, S_ATTR_EXT_RELOC) |
| 68 | ENTRY(0 /*FIXME*/, S_ATTR_LOC_RELOC) |
| 69 | #undef ENTRY |
Kevin Enderby | 5440f63 | 2009-10-07 20:57:20 +0000 | [diff] [blame] | 70 | { 0, "none", 0 }, // used if section has no attributes but has a stub size |
| 71 | #define AttrFlagEnd 0xffffffff // non legal value, multiple attribute bits set |
| 72 | { AttrFlagEnd, 0, 0 } |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 75 | MCSectionMachO::MCSectionMachO(StringRef Segment, StringRef Section, |
| 76 | unsigned TAA, unsigned reserved2, SectionKind K) |
Daniel Dunbar | 9a744e3 | 2010-05-17 21:54:26 +0000 | [diff] [blame] | 77 | : MCSection(SV_MachO, K), TypeAndAttributes(TAA), Reserved2(reserved2) { |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 78 | assert(Segment.size() <= 16 && Section.size() <= 16 && |
| 79 | "Segment or section string too long"); |
| 80 | for (unsigned i = 0; i != 16; ++i) { |
| 81 | if (i < Segment.size()) |
| 82 | SegmentName[i] = Segment[i]; |
| 83 | else |
| 84 | SegmentName[i] = 0; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 85 | |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 86 | if (i < Section.size()) |
| 87 | SectionName[i] = Section[i]; |
| 88 | else |
| 89 | SectionName[i] = 0; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 90 | } |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 93 | void MCSectionMachO::PrintSwitchToSection(const MCAsmInfo &MAI, |
Peter Collingbourne | df39be6 | 2013-04-17 21:18:16 +0000 | [diff] [blame^] | 94 | raw_ostream &OS, |
| 95 | const MCExpr *Subsection) const { |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 96 | OS << "\t.section\t" << getSegmentName() << ',' << getSectionName(); |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 97 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 98 | // Get the section type and attributes. |
| 99 | unsigned TAA = getTypeAndAttributes(); |
| 100 | if (TAA == 0) { |
| 101 | OS << '\n'; |
| 102 | return; |
| 103 | } |
| 104 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 105 | unsigned SectionType = TAA & MCSectionMachO::SECTION_TYPE; |
| 106 | assert(SectionType <= MCSectionMachO::LAST_KNOWN_SECTION_TYPE && |
| 107 | "Invalid SectionType specified!"); |
| 108 | |
Stuart Hastings | 6ad82d8 | 2011-02-21 17:27:17 +0000 | [diff] [blame] | 109 | if (SectionTypeDescriptors[SectionType].AssemblerName) { |
| 110 | OS << ','; |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 111 | OS << SectionTypeDescriptors[SectionType].AssemblerName; |
Stuart Hastings | 37c79c5 | 2011-02-21 21:07:07 +0000 | [diff] [blame] | 112 | } else { |
Stuart Hastings | 6ad82d8 | 2011-02-21 17:27:17 +0000 | [diff] [blame] | 113 | // If we have no name for the attribute, stop here. |
Stuart Hastings | 37c79c5 | 2011-02-21 21:07:07 +0000 | [diff] [blame] | 114 | OS << '\n'; |
Stuart Hastings | 6ad82d8 | 2011-02-21 17:27:17 +0000 | [diff] [blame] | 115 | return; |
Stuart Hastings | 37c79c5 | 2011-02-21 21:07:07 +0000 | [diff] [blame] | 116 | } |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 117 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 118 | // If we don't have any attributes, we're done. |
| 119 | unsigned SectionAttrs = TAA & MCSectionMachO::SECTION_ATTRIBUTES; |
| 120 | if (SectionAttrs == 0) { |
| 121 | // If we have a S_SYMBOL_STUBS size specified, print it along with 'none' as |
| 122 | // the attribute specifier. |
| 123 | if (Reserved2 != 0) |
| 124 | OS << ",none," << Reserved2; |
| 125 | OS << '\n'; |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | // Check each attribute to see if we have it. |
| 130 | char Separator = ','; |
Stuart Hastings | 6ad82d8 | 2011-02-21 17:27:17 +0000 | [diff] [blame] | 131 | for (unsigned i = 0; |
| 132 | SectionAttrs != 0 && SectionAttrDescriptors[i].AttrFlag; |
| 133 | ++i) { |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 134 | // Check to see if we have this attribute. |
| 135 | if ((SectionAttrDescriptors[i].AttrFlag & SectionAttrs) == 0) |
| 136 | continue; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 137 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 138 | // Yep, clear it and print it. |
| 139 | SectionAttrs &= ~SectionAttrDescriptors[i].AttrFlag; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 140 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 141 | OS << Separator; |
| 142 | if (SectionAttrDescriptors[i].AssemblerName) |
| 143 | OS << SectionAttrDescriptors[i].AssemblerName; |
| 144 | else |
| 145 | OS << "<<" << SectionAttrDescriptors[i].EnumName << ">>"; |
| 146 | Separator = '+'; |
| 147 | } |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 148 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 149 | assert(SectionAttrs == 0 && "Unknown section attributes!"); |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 150 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 151 | // If we have a S_SYMBOL_STUBS size specified, print it. |
| 152 | if (Reserved2 != 0) |
| 153 | OS << ',' << Reserved2; |
| 154 | OS << '\n'; |
| 155 | } |
| 156 | |
Jan Wen Voung | 083cf15 | 2010-10-04 17:32:41 +0000 | [diff] [blame] | 157 | bool MCSectionMachO::UseCodeAlign() const { |
| 158 | return hasAttribute(MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS); |
| 159 | } |
| 160 | |
Rafael Espindola | f2dc4aa | 2010-11-17 20:03:54 +0000 | [diff] [blame] | 161 | bool MCSectionMachO::isVirtualSection() const { |
| 162 | return (getType() == MCSectionMachO::S_ZEROFILL || |
| 163 | getType() == MCSectionMachO::S_GB_ZEROFILL || |
| 164 | getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL); |
| 165 | } |
| 166 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 167 | /// StripSpaces - This removes leading and trailing spaces from the StringRef. |
| 168 | static void StripSpaces(StringRef &Str) { |
Guy Benyei | 87d0b9e | 2013-02-12 21:21:59 +0000 | [diff] [blame] | 169 | while (!Str.empty() && isspace(static_cast<unsigned char>(Str[0]))) |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 170 | Str = Str.substr(1); |
Guy Benyei | 87d0b9e | 2013-02-12 21:21:59 +0000 | [diff] [blame] | 171 | while (!Str.empty() && isspace(static_cast<unsigned char>(Str.back()))) |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 172 | Str = Str.substr(0, Str.size()-1); |
| 173 | } |
| 174 | |
| 175 | /// ParseSectionSpecifier - Parse the section specifier indicated by "Spec". |
| 176 | /// This is a string that can appear after a .section directive in a mach-o |
| 177 | /// flavored .s file. If successful, this fills in the specified Out |
| 178 | /// parameters and returns an empty string. When an invalid section |
| 179 | /// specifier is present, this returns a string indicating the problem. |
| 180 | std::string MCSectionMachO::ParseSectionSpecifier(StringRef Spec, // In. |
| 181 | StringRef &Segment, // Out. |
| 182 | StringRef &Section, // Out. |
| 183 | unsigned &TAA, // Out. |
Stuart Hastings | 65c8bca | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 184 | bool &TAAParsed, // Out. |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 185 | unsigned &StubSize) { // Out. |
Stuart Hastings | 65c8bca | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 186 | TAAParsed = false; |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 187 | // Find the first comma. |
| 188 | std::pair<StringRef, StringRef> Comma = Spec.split(','); |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 189 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 190 | // If there is no comma, we fail. |
| 191 | if (Comma.second.empty()) |
| 192 | return "mach-o section specifier requires a segment and section " |
| 193 | "separated by a comma"; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 194 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 195 | // Capture segment, remove leading and trailing whitespace. |
| 196 | Segment = Comma.first; |
| 197 | StripSpaces(Segment); |
| 198 | |
| 199 | // Verify that the segment is present and not too long. |
| 200 | if (Segment.empty() || Segment.size() > 16) |
| 201 | return "mach-o section specifier requires a segment whose length is " |
| 202 | "between 1 and 16 characters"; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 203 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 204 | // Split the section name off from any attributes if present. |
| 205 | Comma = Comma.second.split(','); |
| 206 | |
| 207 | // Capture section, remove leading and trailing whitespace. |
| 208 | Section = Comma.first; |
| 209 | StripSpaces(Section); |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 210 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 211 | // Verify that the section is present and not too long. |
| 212 | if (Section.empty() || Section.size() > 16) |
| 213 | return "mach-o section specifier requires a section whose length is " |
| 214 | "between 1 and 16 characters"; |
| 215 | |
| 216 | // If there is no comma after the section, we're done. |
Stuart Hastings | 65c8bca | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 217 | TAA = 0; |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 218 | StubSize = 0; |
| 219 | if (Comma.second.empty()) |
| 220 | return ""; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 221 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 222 | // Otherwise, we need to parse the section type and attributes. |
| 223 | Comma = Comma.second.split(','); |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 224 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 225 | // Get the section type. |
| 226 | StringRef SectionType = Comma.first; |
| 227 | StripSpaces(SectionType); |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 228 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 229 | // Figure out which section type it is. |
| 230 | unsigned TypeID; |
| 231 | for (TypeID = 0; TypeID !=MCSectionMachO::LAST_KNOWN_SECTION_TYPE+1; ++TypeID) |
| 232 | if (SectionTypeDescriptors[TypeID].AssemblerName && |
| 233 | SectionType == SectionTypeDescriptors[TypeID].AssemblerName) |
| 234 | break; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 235 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 236 | // If we didn't find the section type, reject it. |
| 237 | if (TypeID > MCSectionMachO::LAST_KNOWN_SECTION_TYPE) |
| 238 | return "mach-o section specifier uses an unknown section type"; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 239 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 240 | // Remember the TypeID. |
| 241 | TAA = TypeID; |
Stuart Hastings | 65c8bca | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 242 | TAAParsed = true; |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 243 | |
| 244 | // If we have no comma after the section type, there are no attributes. |
| 245 | if (Comma.second.empty()) { |
| 246 | // S_SYMBOL_STUBS always require a symbol stub size specifier. |
| 247 | if (TAA == MCSectionMachO::S_SYMBOL_STUBS) |
| 248 | return "mach-o section specifier of type 'symbol_stubs' requires a size " |
| 249 | "specifier"; |
| 250 | return ""; |
| 251 | } |
| 252 | |
| 253 | // Otherwise, we do have some attributes. Split off the size specifier if |
| 254 | // present. |
| 255 | Comma = Comma.second.split(','); |
| 256 | StringRef Attrs = Comma.first; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 257 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 258 | // The attribute list is a '+' separated list of attributes. |
| 259 | std::pair<StringRef, StringRef> Plus = Attrs.split('+'); |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 260 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 261 | while (1) { |
| 262 | StringRef Attr = Plus.first; |
| 263 | StripSpaces(Attr); |
| 264 | |
| 265 | // Look up the attribute. |
| 266 | for (unsigned i = 0; ; ++i) { |
Kevin Enderby | 5440f63 | 2009-10-07 20:57:20 +0000 | [diff] [blame] | 267 | if (SectionAttrDescriptors[i].AttrFlag == AttrFlagEnd) |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 268 | return "mach-o section specifier has invalid attribute"; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 269 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 270 | if (SectionAttrDescriptors[i].AssemblerName && |
| 271 | Attr == SectionAttrDescriptors[i].AssemblerName) { |
| 272 | TAA |= SectionAttrDescriptors[i].AttrFlag; |
| 273 | break; |
| 274 | } |
| 275 | } |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 276 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 277 | if (Plus.second.empty()) break; |
| 278 | Plus = Plus.second.split('+'); |
| 279 | }; |
| 280 | |
| 281 | // Okay, we've parsed the section attributes, see if we have a stub size spec. |
| 282 | if (Comma.second.empty()) { |
| 283 | // S_SYMBOL_STUBS always require a symbol stub size specifier. |
| 284 | if (TAA == MCSectionMachO::S_SYMBOL_STUBS) |
| 285 | return "mach-o section specifier of type 'symbol_stubs' requires a size " |
| 286 | "specifier"; |
| 287 | return ""; |
| 288 | } |
| 289 | |
| 290 | // If we have a stub size spec, we must have a sectiontype of S_SYMBOL_STUBS. |
| 291 | if ((TAA & MCSectionMachO::SECTION_TYPE) != MCSectionMachO::S_SYMBOL_STUBS) |
| 292 | return "mach-o section specifier cannot have a stub size specified because " |
| 293 | "it does not have type 'symbol_stubs'"; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 294 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 295 | // Okay, if we do, it must be a number. |
| 296 | StringRef StubSizeStr = Comma.second; |
| 297 | StripSpaces(StubSizeStr); |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 298 | |
Chris Lattner | d9221d7 | 2009-09-20 06:58:54 +0000 | [diff] [blame] | 299 | // Convert the stub size from a string to an integer. |
| 300 | if (StubSizeStr.getAsInteger(0, StubSize)) |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 301 | return "mach-o section specifier has a malformed stub size"; |
Jim Grosbach | fe40f95 | 2010-10-21 22:04:05 +0000 | [diff] [blame] | 302 | |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 303 | return ""; |
| 304 | } |