| Chris Bieneman | b83c187 | 2016-05-11 22:07:48 +0000 | [diff] [blame] | 1 | //===- yaml2macho - Convert YAML to a Mach object file --------------------===// | 
|  | 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 | /// \file | 
|  | 11 | /// \brief The Mach component of yaml2obj. | 
|  | 12 | /// | 
|  | 13 | //===----------------------------------------------------------------------===// | 
|  | 14 |  | 
|  | 15 | #include "yaml2obj.h" | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 16 | #include "llvm/ObjectYAML/MachOYAML.h" | 
|  | 17 | #include "llvm/Support/Error.h" | 
| Chris Bieneman | e8e7555 | 2016-05-25 17:09:07 +0000 | [diff] [blame] | 18 | #include "llvm/Support/LEB128.h" | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 19 | #include "llvm/Support/MachO.h" | 
|  | 20 | #include "llvm/Support/YAMLTraits.h" | 
| Chris Bieneman | b83c187 | 2016-05-11 22:07:48 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" | 
|  | 22 |  | 
| Chris Bieneman | e8e7555 | 2016-05-25 17:09:07 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Format.h" | 
|  | 24 |  | 
| Chris Bieneman | b83c187 | 2016-05-11 22:07:48 +0000 | [diff] [blame] | 25 | using namespace llvm; | 
|  | 26 |  | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 27 | namespace { | 
|  | 28 |  | 
|  | 29 | class MachOWriter { | 
|  | 30 | public: | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 31 | MachOWriter(MachOYAML::Object &Obj) : Obj(Obj), is64Bit(true), fileStart(0) { | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 32 | is64Bit = Obj.Header.magic == MachO::MH_MAGIC_64 || | 
|  | 33 | Obj.Header.magic == MachO::MH_CIGAM_64; | 
| Chris Bieneman | 26e6cea | 2016-05-12 18:02:13 +0000 | [diff] [blame] | 34 | memset(reinterpret_cast<void *>(&Header64), 0, | 
|  | 35 | sizeof(MachO::mach_header_64)); | 
| Chris Bieneman | fc88927 | 2016-05-12 18:21:09 +0000 | [diff] [blame] | 36 | assert((is64Bit || Obj.Header.reserved == 0xDEADBEEFu) && | 
|  | 37 | "32-bit MachO has reserved in header"); | 
|  | 38 | assert((!is64Bit || Obj.Header.reserved != 0xDEADBEEFu) && | 
|  | 39 | "64-bit MachO has missing reserved in header"); | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 40 | } | 
|  | 41 |  | 
|  | 42 | Error writeMachO(raw_ostream &OS); | 
|  | 43 |  | 
|  | 44 | private: | 
|  | 45 | Error writeHeader(raw_ostream &OS); | 
| Chris Bieneman | 8b5906e | 2016-05-13 17:41:41 +0000 | [diff] [blame] | 46 | Error writeLoadCommands(raw_ostream &OS); | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 47 | Error writeSectionData(raw_ostream &OS); | 
| Chris Bieneman | e8e7555 | 2016-05-25 17:09:07 +0000 | [diff] [blame] | 48 | Error writeLinkEditData(raw_ostream &OS); | 
|  | 49 |  | 
|  | 50 | void ZeroToOffset(raw_ostream &OS, size_t offset); | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 51 |  | 
| Chris Bieneman | 8b5906e | 2016-05-13 17:41:41 +0000 | [diff] [blame] | 52 | MachOYAML::Object &Obj; | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 53 | bool is64Bit; | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 54 | uint64_t fileStart; | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 55 |  | 
|  | 56 | union { | 
|  | 57 | MachO::mach_header_64 Header64; | 
|  | 58 | MachO::mach_header Header; | 
|  | 59 | }; | 
|  | 60 | }; | 
|  | 61 |  | 
|  | 62 | Error MachOWriter::writeMachO(raw_ostream &OS) { | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 63 | fileStart = OS.tell(); | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 64 | if (auto Err = writeHeader(OS)) | 
|  | 65 | return Err; | 
| Chris Bieneman | 8b5906e | 2016-05-13 17:41:41 +0000 | [diff] [blame] | 66 | if (auto Err = writeLoadCommands(OS)) | 
|  | 67 | return Err; | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 68 | if (auto Err = writeSectionData(OS)) | 
|  | 69 | return Err; | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 70 | return Error::success(); | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 | Error MachOWriter::writeHeader(raw_ostream &OS) { | 
|  | 74 | Header.magic = Obj.Header.magic; | 
|  | 75 | Header.cputype = Obj.Header.cputype; | 
|  | 76 | Header.cpusubtype = Obj.Header.cpusubtype; | 
|  | 77 | Header.filetype = Obj.Header.filetype; | 
|  | 78 | Header.ncmds = Obj.Header.ncmds; | 
|  | 79 | Header.sizeofcmds = Obj.Header.sizeofcmds; | 
|  | 80 | Header.flags = Obj.Header.flags; | 
| Chris Bieneman | fc88927 | 2016-05-12 18:21:09 +0000 | [diff] [blame] | 81 | Header64.reserved = Obj.Header.reserved; | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 82 |  | 
| Chris Bieneman | 8b5906e | 2016-05-13 17:41:41 +0000 | [diff] [blame] | 83 | if (is64Bit) | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 84 | OS.write((const char *)&Header64, sizeof(MachO::mach_header_64)); | 
|  | 85 | else | 
|  | 86 | OS.write((const char *)&Header, sizeof(MachO::mach_header)); | 
|  | 87 |  | 
|  | 88 | return Error::success(); | 
|  | 89 | } | 
|  | 90 |  | 
| Chris Bieneman | 2de17d4 | 2016-05-18 16:17:23 +0000 | [diff] [blame] | 91 | template <typename SectionType> | 
|  | 92 | SectionType constructSection(MachOYAML::Section Sec) { | 
|  | 93 | SectionType TempSec; | 
|  | 94 | memcpy(reinterpret_cast<void *>(&TempSec.sectname[0]), &Sec.sectname[0], 16); | 
|  | 95 | memcpy(reinterpret_cast<void *>(&TempSec.segname[0]), &Sec.segname[0], 16); | 
|  | 96 | TempSec.addr = Sec.addr; | 
|  | 97 | TempSec.size = Sec.size; | 
|  | 98 | TempSec.offset = Sec.offset; | 
|  | 99 | TempSec.align = Sec.align; | 
|  | 100 | TempSec.reloff = Sec.reloff; | 
|  | 101 | TempSec.nreloc = Sec.nreloc; | 
|  | 102 | TempSec.flags = Sec.flags; | 
|  | 103 | TempSec.reserved1 = Sec.reserved1; | 
|  | 104 | TempSec.reserved2 = Sec.reserved2; | 
|  | 105 | return TempSec; | 
|  | 106 | } | 
|  | 107 |  | 
| Chris Bieneman | 9f243e9 | 2016-05-19 20:54:43 +0000 | [diff] [blame] | 108 | template <typename StructType> | 
|  | 109 | size_t writeLoadCommandData(MachOYAML::LoadCommand &LC, raw_ostream &OS) { | 
|  | 110 | return 0; | 
|  | 111 | } | 
|  | 112 |  | 
|  | 113 | template <> | 
|  | 114 | size_t writeLoadCommandData<MachO::segment_command>(MachOYAML::LoadCommand &LC, | 
|  | 115 | raw_ostream &OS) { | 
|  | 116 | size_t BytesWritten = 0; | 
|  | 117 | for (auto Sec : LC.Sections) { | 
|  | 118 | auto TempSec = constructSection<MachO::section>(Sec); | 
|  | 119 | OS.write(reinterpret_cast<const char *>(&(TempSec)), | 
|  | 120 | sizeof(MachO::section)); | 
|  | 121 | BytesWritten += sizeof(MachO::section); | 
|  | 122 | } | 
|  | 123 | return BytesWritten; | 
|  | 124 | } | 
|  | 125 |  | 
|  | 126 | template <> | 
|  | 127 | size_t | 
|  | 128 | writeLoadCommandData<MachO::segment_command_64>(MachOYAML::LoadCommand &LC, | 
|  | 129 | raw_ostream &OS) { | 
|  | 130 | size_t BytesWritten = 0; | 
|  | 131 | for (auto Sec : LC.Sections) { | 
|  | 132 | auto TempSec = constructSection<MachO::section_64>(Sec); | 
|  | 133 | TempSec.reserved3 = Sec.reserved3; | 
|  | 134 | OS.write(reinterpret_cast<const char *>(&(TempSec)), | 
|  | 135 | sizeof(MachO::section_64)); | 
|  | 136 | BytesWritten += sizeof(MachO::section_64); | 
|  | 137 | } | 
|  | 138 | return BytesWritten; | 
|  | 139 | } | 
|  | 140 |  | 
|  | 141 | size_t writePayloadString(MachOYAML::LoadCommand &LC, raw_ostream &OS) { | 
|  | 142 | size_t BytesWritten = 0; | 
|  | 143 | if (!LC.PayloadString.empty()) { | 
|  | 144 | OS.write(LC.PayloadString.c_str(), LC.PayloadString.length()); | 
|  | 145 | BytesWritten = LC.PayloadString.length(); | 
|  | 146 | } | 
|  | 147 | return BytesWritten; | 
|  | 148 | } | 
|  | 149 |  | 
|  | 150 | template <> | 
|  | 151 | size_t writeLoadCommandData<MachO::dylib_command>(MachOYAML::LoadCommand &LC, | 
|  | 152 | raw_ostream &OS) { | 
|  | 153 | return writePayloadString(LC, OS); | 
|  | 154 | } | 
|  | 155 |  | 
|  | 156 | template <> | 
|  | 157 | size_t writeLoadCommandData<MachO::dylinker_command>(MachOYAML::LoadCommand &LC, | 
|  | 158 | raw_ostream &OS) { | 
|  | 159 | return writePayloadString(LC, OS); | 
|  | 160 | } | 
|  | 161 |  | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 162 | void ZeroFillBytes(raw_ostream &OS, size_t Size) { | 
|  | 163 | std::vector<uint8_t> FillData; | 
|  | 164 | FillData.insert(FillData.begin(), Size, 0); | 
|  | 165 | OS.write(reinterpret_cast<char *>(FillData.data()), Size); | 
|  | 166 | } | 
|  | 167 |  | 
|  | 168 | void Fill(raw_ostream &OS, size_t Size, uint32_t Data) { | 
|  | 169 | std::vector<uint32_t> FillData; | 
|  | 170 | FillData.insert(FillData.begin(), (Size / 4) + 1, Data); | 
|  | 171 | OS.write(reinterpret_cast<char *>(FillData.data()), Size); | 
|  | 172 | } | 
|  | 173 |  | 
| Chris Bieneman | e8e7555 | 2016-05-25 17:09:07 +0000 | [diff] [blame] | 174 | void MachOWriter::ZeroToOffset(raw_ostream &OS, size_t Offset) { | 
|  | 175 | auto currOffset = OS.tell() - fileStart; | 
|  | 176 | if (currOffset < Offset) | 
|  | 177 | ZeroFillBytes(OS, Offset - currOffset); | 
|  | 178 | } | 
|  | 179 |  | 
| Chris Bieneman | 8b5906e | 2016-05-13 17:41:41 +0000 | [diff] [blame] | 180 | Error MachOWriter::writeLoadCommands(raw_ostream &OS) { | 
|  | 181 | for (auto &LC : Obj.LoadCommands) { | 
| Chris Bieneman | 3f2eb83 | 2016-05-17 19:44:06 +0000 | [diff] [blame] | 182 | size_t BytesWritten = 0; | 
|  | 183 | #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct)                         \ | 
|  | 184 | case MachO::LCName:                                                          \ | 
|  | 185 | OS.write(reinterpret_cast<const char *>(&(LC.Data.LCStruct##_data)),       \ | 
|  | 186 | sizeof(MachO::LCStruct));                                         \ | 
|  | 187 | BytesWritten = sizeof(MachO::LCStruct);                                    \ | 
| Chris Bieneman | 9f243e9 | 2016-05-19 20:54:43 +0000 | [diff] [blame] | 188 | BytesWritten += writeLoadCommandData<MachO::LCStruct>(LC, OS);             \ | 
| Chris Bieneman | 3f2eb83 | 2016-05-17 19:44:06 +0000 | [diff] [blame] | 189 | break; | 
|  | 190 |  | 
|  | 191 | switch (LC.Data.load_command_data.cmd) { | 
|  | 192 | default: | 
|  | 193 | OS.write(reinterpret_cast<const char *>(&(LC.Data.load_command_data)), | 
|  | 194 | sizeof(MachO::load_command)); | 
|  | 195 | BytesWritten = sizeof(MachO::load_command); | 
| Chris Bieneman | 9f243e9 | 2016-05-19 20:54:43 +0000 | [diff] [blame] | 196 | BytesWritten += writeLoadCommandData<MachO::load_command>(LC, OS); | 
| Chris Bieneman | 3f2eb83 | 2016-05-17 19:44:06 +0000 | [diff] [blame] | 197 | break; | 
|  | 198 | #include "llvm/Support/MachO.def" | 
|  | 199 | } | 
|  | 200 |  | 
| Chris Bieneman | 9f243e9 | 2016-05-19 20:54:43 +0000 | [diff] [blame] | 201 | if (LC.PayloadBytes.size() > 0) { | 
|  | 202 | OS.write(reinterpret_cast<const char *>(LC.PayloadBytes.data()), | 
|  | 203 | LC.PayloadBytes.size()); | 
|  | 204 | BytesWritten += LC.PayloadBytes.size(); | 
| Chris Bieneman | 2de17d4 | 2016-05-18 16:17:23 +0000 | [diff] [blame] | 205 | } | 
|  | 206 |  | 
| Chris Bieneman | 9f243e9 | 2016-05-19 20:54:43 +0000 | [diff] [blame] | 207 | if (LC.ZeroPadBytes > 0) { | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 208 | ZeroFillBytes(OS, LC.ZeroPadBytes); | 
| Chris Bieneman | 9f243e9 | 2016-05-19 20:54:43 +0000 | [diff] [blame] | 209 | BytesWritten += LC.ZeroPadBytes; | 
|  | 210 | } | 
|  | 211 |  | 
| Chris Bieneman | 1abf005 | 2016-05-19 23:26:31 +0000 | [diff] [blame] | 212 | // Fill remaining bytes with 0. This will only get hit in partially | 
|  | 213 | // specified test cases. | 
| Chris Bieneman | 9f243e9 | 2016-05-19 20:54:43 +0000 | [diff] [blame] | 214 | auto BytesRemaining = LC.Data.load_command_data.cmdsize - BytesWritten; | 
| Chris Bieneman | 3f2eb83 | 2016-05-17 19:44:06 +0000 | [diff] [blame] | 215 | if (BytesRemaining > 0) { | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 216 | ZeroFillBytes(OS, BytesRemaining); | 
|  | 217 | } | 
|  | 218 | } | 
|  | 219 | return Error::success(); | 
|  | 220 | } | 
|  | 221 |  | 
|  | 222 | Error MachOWriter::writeSectionData(raw_ostream &OS) { | 
|  | 223 | for (auto &LC : Obj.LoadCommands) { | 
|  | 224 | switch (LC.Data.load_command_data.cmd) { | 
|  | 225 | case MachO::LC_SEGMENT: | 
|  | 226 | case MachO::LC_SEGMENT_64: | 
| Chris Bieneman | e8e7555 | 2016-05-25 17:09:07 +0000 | [diff] [blame] | 227 | auto currOffset = OS.tell() - fileStart; | 
|  | 228 | auto segname = LC.Data.segment_command_data.segname; | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 229 | uint64_t segOff = is64Bit ? LC.Data.segment_command_64_data.fileoff | 
|  | 230 | : LC.Data.segment_command_data.fileoff; | 
|  | 231 |  | 
| Chris Bieneman | e8e7555 | 2016-05-25 17:09:07 +0000 | [diff] [blame] | 232 | if (0 == strncmp(&segname[0], "__LINKEDIT", 16)) { | 
|  | 233 | if (auto Err = writeLinkEditData(OS)) | 
|  | 234 | return Err; | 
|  | 235 | } else { | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 236 | // Zero Fill any data between the end of the last thing we wrote and the | 
|  | 237 | // start of this section. | 
| Chris Bieneman | e8e7555 | 2016-05-25 17:09:07 +0000 | [diff] [blame] | 238 | if (currOffset < segOff) { | 
|  | 239 | ZeroFillBytes(OS, segOff - currOffset); | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 240 | } | 
|  | 241 |  | 
| Chris Bieneman | e8e7555 | 2016-05-25 17:09:07 +0000 | [diff] [blame] | 242 | for (auto &Sec : LC.Sections) { | 
|  | 243 | // Zero Fill any data between the end of the last thing we wrote and | 
|  | 244 | // the | 
|  | 245 | // start of this section. | 
|  | 246 | assert( | 
|  | 247 | OS.tell() - fileStart <= Sec.offset && | 
|  | 248 | "Wrote too much data somewhere, section offsets don't line up."); | 
|  | 249 | currOffset = OS.tell() - fileStart; | 
|  | 250 | if (currOffset < Sec.offset) { | 
|  | 251 | ZeroFillBytes(OS, Sec.offset - currOffset); | 
|  | 252 | } | 
|  | 253 |  | 
|  | 254 | // Fills section data with 0xDEADBEEF | 
|  | 255 | Fill(OS, Sec.size, 0xDEADBEEFu); | 
|  | 256 | } | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 257 | } | 
|  | 258 | uint64_t segSize = is64Bit ? LC.Data.segment_command_64_data.filesize | 
|  | 259 | : LC.Data.segment_command_data.filesize; | 
| Chris Bieneman | e8e7555 | 2016-05-25 17:09:07 +0000 | [diff] [blame] | 260 | ZeroToOffset(OS, segOff + segSize); | 
| Chris Bieneman | e18fee2 | 2016-05-20 22:31:50 +0000 | [diff] [blame] | 261 | break; | 
| Chris Bieneman | 8b5906e | 2016-05-13 17:41:41 +0000 | [diff] [blame] | 262 | } | 
|  | 263 | } | 
|  | 264 | return Error::success(); | 
|  | 265 | } | 
|  | 266 |  | 
| Chris Bieneman | e8e7555 | 2016-05-25 17:09:07 +0000 | [diff] [blame] | 267 | Error MachOWriter::writeLinkEditData(raw_ostream &OS) { | 
|  | 268 | MachOYAML::LinkEditData &LinkEdit = Obj.LinkEdit; | 
|  | 269 | MachO::dyld_info_command *DyldInfoOnlyCmd = 0; | 
|  | 270 | MachO::symtab_command *SymtabCmd = 0; | 
|  | 271 | for (auto &LC : Obj.LoadCommands) { | 
|  | 272 | switch (LC.Data.load_command_data.cmd) { | 
|  | 273 | case MachO::LC_SYMTAB: | 
|  | 274 | SymtabCmd = &LC.Data.symtab_command_data; | 
|  | 275 | break; | 
|  | 276 | case MachO::LC_DYLD_INFO_ONLY: | 
|  | 277 | DyldInfoOnlyCmd = &LC.Data.dyld_info_command_data; | 
|  | 278 | break; | 
|  | 279 | } | 
|  | 280 | } | 
|  | 281 |  | 
|  | 282 | ZeroToOffset(OS, DyldInfoOnlyCmd->rebase_off); | 
|  | 283 |  | 
|  | 284 | for (auto Opcode : LinkEdit.RebaseOpcodes) { | 
|  | 285 | uint8_t OpByte = Opcode.Opcode | Opcode.Imm; | 
|  | 286 | OS.write(reinterpret_cast<char *>(&OpByte), 1); | 
|  | 287 | for (auto Data : Opcode.ExtraData) { | 
|  | 288 | encodeULEB128(Data, OS); | 
|  | 289 | } | 
|  | 290 | } | 
|  | 291 |  | 
| Chris Bieneman | 524243d | 2016-05-26 20:06:14 +0000 | [diff] [blame^] | 292 | ZeroToOffset(OS, DyldInfoOnlyCmd->bind_off); | 
|  | 293 |  | 
|  | 294 | for (auto Opcode : LinkEdit.BindOpcodes) { | 
|  | 295 | uint8_t OpByte = Opcode.Opcode | Opcode.Imm; | 
|  | 296 | OS.write(reinterpret_cast<char *>(&OpByte), 1); | 
|  | 297 | for (auto Data : Opcode.ULEBExtraData) { | 
|  | 298 | encodeULEB128(Data, OS); | 
|  | 299 | } | 
|  | 300 | for (auto Data : Opcode.SLEBExtraData) { | 
|  | 301 | encodeSLEB128(Data, OS); | 
|  | 302 | } | 
|  | 303 | if(!Opcode.Symbol.empty()) { | 
|  | 304 | OS.write(Opcode.Symbol.data(), Opcode.Symbol.size()); | 
|  | 305 | OS.write("\0", 1); | 
|  | 306 | } | 
|  | 307 | } | 
|  | 308 |  | 
| Chris Bieneman | e8e7555 | 2016-05-25 17:09:07 +0000 | [diff] [blame] | 309 | // Fill to the end of the string table | 
|  | 310 | ZeroToOffset(OS, SymtabCmd->stroff + SymtabCmd->strsize); | 
|  | 311 |  | 
|  | 312 | return Error::success(); | 
|  | 313 | } | 
|  | 314 |  | 
| Chris Bieneman | a23b26f | 2016-05-12 17:44:48 +0000 | [diff] [blame] | 315 | } // end anonymous namespace | 
|  | 316 |  | 
|  | 317 | int yaml2macho(yaml::Input &YIn, raw_ostream &Out) { | 
|  | 318 | MachOYAML::Object Doc; | 
|  | 319 | YIn >> Doc; | 
|  | 320 | if (YIn.error()) { | 
|  | 321 | errs() << "yaml2obj: Failed to parse YAML file!\n"; | 
|  | 322 | return 1; | 
|  | 323 | } | 
|  | 324 |  | 
|  | 325 | MachOWriter Writer(Doc); | 
|  | 326 | if (auto Err = Writer.writeMachO(Out)) { | 
|  | 327 | errs() << toString(std::move(Err)); | 
|  | 328 | return 1; | 
|  | 329 | } | 
|  | 330 | return 0; | 
| Chris Bieneman | b83c187 | 2016-05-11 22:07:48 +0000 | [diff] [blame] | 331 | } |