Bug Summary

File:tools/obj2yaml/macho2yaml.cpp
Warning:line 210, column 17
Value stored to 'EndPtr' during its initialization is never read

Annotated Source Code

1//===------ macho2yaml.cpp - obj2yaml conversion tool -----------*- C++ -*-===//
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 "Error.h"
11#include "obj2yaml.h"
12#include "llvm/DebugInfo/DWARF/DWARFContext.h"
13#include "llvm/Object/MachOUniversal.h"
14#include "llvm/ObjectYAML/ObjectYAML.h"
15#include "llvm/Support/ErrorHandling.h"
16#include "llvm/Support/LEB128.h"
17
18#include <string.h> // for memcpy
19
20using namespace llvm;
21
22class MachODumper {
23
24 template <typename StructType>
25 const char *processLoadCommandData(
26 MachOYAML::LoadCommand &LC,
27 const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd);
28
29 const object::MachOObjectFile &Obj;
30 void dumpHeader(std::unique_ptr<MachOYAML::Object> &Y);
31 void dumpLoadCommands(std::unique_ptr<MachOYAML::Object> &Y);
32 void dumpLinkEdit(std::unique_ptr<MachOYAML::Object> &Y);
33 void dumpRebaseOpcodes(std::unique_ptr<MachOYAML::Object> &Y);
34 void dumpBindOpcodes(std::vector<MachOYAML::BindOpcode> &BindOpcodes,
35 ArrayRef<uint8_t> OpcodeBuffer, bool Lazy = false);
36 void dumpExportTrie(std::unique_ptr<MachOYAML::Object> &Y);
37 void dumpSymbols(std::unique_ptr<MachOYAML::Object> &Y);
38 void dumpDebugAbbrev(DWARFContextInMemory &DCtx,
39 std::unique_ptr<MachOYAML::Object> &Y);
40 void dumpDebugStrings(DWARFContextInMemory &DCtx,
41 std::unique_ptr<MachOYAML::Object> &Y);
42
43public:
44 MachODumper(const object::MachOObjectFile &O) : Obj(O) {}
45 Expected<std::unique_ptr<MachOYAML::Object>> dump();
46};
47
48#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
49 case MachO::LCName: \
50 memcpy((void *) & (LC.Data.LCStruct##_data), LoadCmd.Ptr, \
51 sizeof(MachO::LCStruct)); \
52 if (Obj.isLittleEndian() != sys::IsLittleEndianHost) \
53 MachO::swapStruct(LC.Data.LCStruct##_data); \
54 EndPtr = processLoadCommandData<MachO::LCStruct>(LC, LoadCmd); \
55 break;
56
57template <typename SectionType>
58MachOYAML::Section constructSectionCommon(SectionType Sec) {
59 MachOYAML::Section TempSec;
60 memcpy(reinterpret_cast<void *>(&TempSec.sectname[0]), &Sec.sectname[0], 16);
61 memcpy(reinterpret_cast<void *>(&TempSec.segname[0]), &Sec.segname[0], 16);
62 TempSec.addr = Sec.addr;
63 TempSec.size = Sec.size;
64 TempSec.offset = Sec.offset;
65 TempSec.align = Sec.align;
66 TempSec.reloff = Sec.reloff;
67 TempSec.nreloc = Sec.nreloc;
68 TempSec.flags = Sec.flags;
69 TempSec.reserved1 = Sec.reserved1;
70 TempSec.reserved2 = Sec.reserved2;
71 TempSec.reserved3 = 0;
72 return TempSec;
73}
74
75template <typename SectionType>
76MachOYAML::Section constructSection(SectionType Sec);
77
78template <> MachOYAML::Section constructSection(MachO::section Sec) {
79 MachOYAML::Section TempSec = constructSectionCommon(Sec);
80 TempSec.reserved3 = 0;
81 return TempSec;
82}
83
84template <> MachOYAML::Section constructSection(MachO::section_64 Sec) {
85 MachOYAML::Section TempSec = constructSectionCommon(Sec);
86 TempSec.reserved3 = Sec.reserved3;
87 return TempSec;
88}
89
90template <typename SectionType, typename SegmentType>
91const char *
92extractSections(const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd,
93 std::vector<MachOYAML::Section> &Sections,
94 bool IsLittleEndian) {
95 auto End = LoadCmd.Ptr + LoadCmd.C.cmdsize;
96 const SectionType *Curr =
97 reinterpret_cast<const SectionType *>(LoadCmd.Ptr + sizeof(SegmentType));
98 for (; reinterpret_cast<const void *>(Curr) < End; Curr++) {
99 if (IsLittleEndian != sys::IsLittleEndianHost) {
100 SectionType Sec;
101 memcpy((void *)&Sec, Curr, sizeof(SectionType));
102 MachO::swapStruct(Sec);
103 Sections.push_back(constructSection(Sec));
104 } else {
105 Sections.push_back(constructSection(*Curr));
106 }
107 }
108 return reinterpret_cast<const char *>(Curr);
109}
110
111template <typename StructType>
112const char *MachODumper::processLoadCommandData(
113 MachOYAML::LoadCommand &LC,
114 const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
115 return LoadCmd.Ptr + sizeof(StructType);
116}
117
118template <>
119const char *MachODumper::processLoadCommandData<MachO::segment_command>(
120 MachOYAML::LoadCommand &LC,
121 const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
122 return extractSections<MachO::section, MachO::segment_command>(
123 LoadCmd, LC.Sections, Obj.isLittleEndian());
124}
125
126template <>
127const char *MachODumper::processLoadCommandData<MachO::segment_command_64>(
128 MachOYAML::LoadCommand &LC,
129 const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
130 return extractSections<MachO::section_64, MachO::segment_command_64>(
131 LoadCmd, LC.Sections, Obj.isLittleEndian());
132}
133
134template <typename StructType>
135const char *
136readString(MachOYAML::LoadCommand &LC,
137 const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
138 auto Start = LoadCmd.Ptr + sizeof(StructType);
139 auto MaxSize = LoadCmd.C.cmdsize - sizeof(StructType);
140 auto Size = strnlen(Start, MaxSize);
141 LC.PayloadString = StringRef(Start, Size).str();
142 return Start + Size;
143}
144
145template <>
146const char *MachODumper::processLoadCommandData<MachO::dylib_command>(
147 MachOYAML::LoadCommand &LC,
148 const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
149 return readString<MachO::dylib_command>(LC, LoadCmd);
150}
151
152template <>
153const char *MachODumper::processLoadCommandData<MachO::dylinker_command>(
154 MachOYAML::LoadCommand &LC,
155 const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
156 return readString<MachO::dylinker_command>(LC, LoadCmd);
157}
158
159template <>
160const char *MachODumper::processLoadCommandData<MachO::rpath_command>(
161 MachOYAML::LoadCommand &LC,
162 const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
163 return readString<MachO::rpath_command>(LC, LoadCmd);
164}
165
166template <>
167const char *MachODumper::processLoadCommandData<MachO::build_version_command>(
168 MachOYAML::LoadCommand &LC,
169 const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
170 auto Start = LoadCmd.Ptr + sizeof(MachO::build_version_command);
171 auto NTools = LC.Data.build_version_command_data.ntools;
172 for (unsigned i = 0; i < NTools; ++i) {
173 auto Curr = Start + i * sizeof(MachO::build_tool_version);
174 MachO::build_tool_version BV;
175 memcpy((void *)&BV, Curr, sizeof(MachO::build_tool_version));
176 if (Obj.isLittleEndian() != sys::IsLittleEndianHost)
177 MachO::swapStruct(BV);
178 LC.Tools.push_back(BV);
179 }
180 return Start + NTools * sizeof(MachO::build_tool_version);
181}
182
183Expected<std::unique_ptr<MachOYAML::Object>> MachODumper::dump() {
184 auto Y = make_unique<MachOYAML::Object>();
185 Y->IsLittleEndian = Obj.isLittleEndian();
186 dumpHeader(Y);
187 dumpLoadCommands(Y);
188 dumpLinkEdit(Y);
189
190 DWARFContextInMemory DICtx(Obj);
191 if (auto Err = dwarf2yaml(DICtx, Y->DWARF))
192 return errorCodeToError(Err);
193 return std::move(Y);
194}
195
196void MachODumper::dumpHeader(std::unique_ptr<MachOYAML::Object> &Y) {
197 Y->Header.magic = Obj.getHeader().magic;
198 Y->Header.cputype = Obj.getHeader().cputype;
199 Y->Header.cpusubtype = Obj.getHeader().cpusubtype;
200 Y->Header.filetype = Obj.getHeader().filetype;
201 Y->Header.ncmds = Obj.getHeader().ncmds;
202 Y->Header.sizeofcmds = Obj.getHeader().sizeofcmds;
203 Y->Header.flags = Obj.getHeader().flags;
204 Y->Header.reserved = 0;
205}
206
207void MachODumper::dumpLoadCommands(std::unique_ptr<MachOYAML::Object> &Y) {
208 for (auto LoadCmd : Obj.load_commands()) {
209 MachOYAML::LoadCommand LC;
210 const char *EndPtr = LoadCmd.Ptr;
Value stored to 'EndPtr' during its initialization is never read
211 switch (LoadCmd.C.cmd) {
212 default:
213 memcpy((void *)&(LC.Data.load_command_data), LoadCmd.Ptr,
214 sizeof(MachO::load_command));
215 if (Obj.isLittleEndian() != sys::IsLittleEndianHost)
216 MachO::swapStruct(LC.Data.load_command_data);
217 EndPtr = processLoadCommandData<MachO::load_command>(LC, LoadCmd);
218 break;
219#include "llvm/Support/MachO.def"
220 }
221 auto RemainingBytes = LoadCmd.C.cmdsize - (EndPtr - LoadCmd.Ptr);
222 if (!std::all_of(EndPtr, &EndPtr[RemainingBytes],
223 [](const char C) { return C == 0; })) {
224 LC.PayloadBytes.insert(LC.PayloadBytes.end(), EndPtr,
225 &EndPtr[RemainingBytes]);
226 RemainingBytes = 0;
227 }
228 LC.ZeroPadBytes = RemainingBytes;
229 Y->LoadCommands.push_back(std::move(LC));
230 }
231}
232
233void MachODumper::dumpLinkEdit(std::unique_ptr<MachOYAML::Object> &Y) {
234 dumpRebaseOpcodes(Y);
235 dumpBindOpcodes(Y->LinkEdit.BindOpcodes, Obj.getDyldInfoBindOpcodes());
236 dumpBindOpcodes(Y->LinkEdit.WeakBindOpcodes,
237 Obj.getDyldInfoWeakBindOpcodes());
238 dumpBindOpcodes(Y->LinkEdit.LazyBindOpcodes, Obj.getDyldInfoLazyBindOpcodes(),
239 true);
240 dumpExportTrie(Y);
241 dumpSymbols(Y);
242}
243
244void MachODumper::dumpRebaseOpcodes(std::unique_ptr<MachOYAML::Object> &Y) {
245 MachOYAML::LinkEditData &LEData = Y->LinkEdit;
246
247 auto RebaseOpcodes = Obj.getDyldInfoRebaseOpcodes();
248 for (auto OpCode = RebaseOpcodes.begin(); OpCode != RebaseOpcodes.end();
249 ++OpCode) {
250 MachOYAML::RebaseOpcode RebaseOp;
251 RebaseOp.Opcode =
252 static_cast<MachO::RebaseOpcode>(*OpCode & MachO::REBASE_OPCODE_MASK);
253 RebaseOp.Imm = *OpCode & MachO::REBASE_IMMEDIATE_MASK;
254
255 unsigned Count;
256 uint64_t ULEB = 0;
257
258 switch (RebaseOp.Opcode) {
259 case MachO::REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB:
260
261 ULEB = decodeULEB128(OpCode + 1, &Count);
262 RebaseOp.ExtraData.push_back(ULEB);
263 OpCode += Count;
264 // Intentionally no break here -- This opcode has two ULEB values
265 case MachO::REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
266 case MachO::REBASE_OPCODE_ADD_ADDR_ULEB:
267 case MachO::REBASE_OPCODE_DO_REBASE_ULEB_TIMES:
268 case MachO::REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB:
269
270 ULEB = decodeULEB128(OpCode + 1, &Count);
271 RebaseOp.ExtraData.push_back(ULEB);
272 OpCode += Count;
273 break;
274 default:
275 break;
276 }
277
278 LEData.RebaseOpcodes.push_back(RebaseOp);
279
280 if (RebaseOp.Opcode == MachO::REBASE_OPCODE_DONE)
281 break;
282 }
283}
284
285StringRef ReadStringRef(const uint8_t *Start) {
286 const uint8_t *Itr = Start;
287 for (; *Itr; ++Itr)
288 ;
289 return StringRef(reinterpret_cast<const char *>(Start), Itr - Start);
290}
291
292void MachODumper::dumpBindOpcodes(
293 std::vector<MachOYAML::BindOpcode> &BindOpcodes,
294 ArrayRef<uint8_t> OpcodeBuffer, bool Lazy) {
295 for (auto OpCode = OpcodeBuffer.begin(); OpCode != OpcodeBuffer.end();
296 ++OpCode) {
297 MachOYAML::BindOpcode BindOp;
298 BindOp.Opcode =
299 static_cast<MachO::BindOpcode>(*OpCode & MachO::BIND_OPCODE_MASK);
300 BindOp.Imm = *OpCode & MachO::BIND_IMMEDIATE_MASK;
301
302 unsigned Count;
303 uint64_t ULEB = 0;
304 int64_t SLEB = 0;
305
306 switch (BindOp.Opcode) {
307 case MachO::BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB:
308 ULEB = decodeULEB128(OpCode + 1, &Count);
309 BindOp.ULEBExtraData.push_back(ULEB);
310 OpCode += Count;
311 // Intentionally no break here -- this opcode has two ULEB values
312
313 case MachO::BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB:
314 case MachO::BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
315 case MachO::BIND_OPCODE_ADD_ADDR_ULEB:
316 case MachO::BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB:
317 ULEB = decodeULEB128(OpCode + 1, &Count);
318 BindOp.ULEBExtraData.push_back(ULEB);
319 OpCode += Count;
320 break;
321
322 case MachO::BIND_OPCODE_SET_ADDEND_SLEB:
323 SLEB = decodeSLEB128(OpCode + 1, &Count);
324 BindOp.SLEBExtraData.push_back(SLEB);
325 OpCode += Count;
326 break;
327
328 case MachO::BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM:
329 BindOp.Symbol = ReadStringRef(OpCode + 1);
330 OpCode += BindOp.Symbol.size() + 1;
331 break;
332 default:
333 break;
334 }
335
336 BindOpcodes.push_back(BindOp);
337
338 // Lazy bindings have DONE opcodes between operations, so we need to keep
339 // processing after a DONE.
340 if (!Lazy && BindOp.Opcode == MachO::BIND_OPCODE_DONE)
341 break;
342 }
343}
344
345/*!
346 * /brief processes a node from the export trie, and its children.
347 *
348 * To my knowledge there is no documentation of the encoded format of this data
349 * other than in the heads of the Apple linker engineers. To that end hopefully
350 * this comment and the implementation below can serve to light the way for
351 * anyone crazy enough to come down this path in the future.
352 *
353 * This function reads and preserves the trie structure of the export trie. To
354 * my knowledge there is no code anywhere else that reads the data and preserves
355 * the Trie. LD64 (sources available at opensource.apple.com) has a similar
356 * implementation that parses the export trie into a vector. That code as well
357 * as LLVM's libObject MachO implementation were the basis for this.
358 *
359 * The export trie is an encoded trie. The node serialization is a bit awkward.
360 * The below pseudo-code is the best description I've come up with for it.
361 *
362 * struct SerializedNode {
363 * ULEB128 TerminalSize;
364 * struct TerminalData { <-- This is only present if TerminalSize > 0
365 * ULEB128 Flags;
366 * ULEB128 Address; <-- Present if (! Flags & REEXPORT )
367 * ULEB128 Other; <-- Present if ( Flags & REEXPORT ||
368 * Flags & STUB_AND_RESOLVER )
369 * char[] ImportName; <-- Present if ( Flags & REEXPORT )
370 * }
371 * uint8_t ChildrenCount;
372 * Pair<char[], ULEB128> ChildNameOffsetPair[ChildrenCount];
373 * SerializedNode Children[ChildrenCount]
374 * }
375 *
376 * Terminal nodes are nodes that represent actual exports. They can appear
377 * anywhere in the tree other than at the root; they do not need to be leaf
378 * nodes. When reading the data out of the trie this routine reads it in-order,
379 * but it puts the child names and offsets directly into the child nodes. This
380 * results in looping over the children twice during serialization and
381 * de-serialization, but it makes the YAML representation more human readable.
382 *
383 * Below is an example of the graph from a "Hello World" executable:
384 *
385 * -------
386 * | '' |
387 * -------
388 * |
389 * -------
390 * | '_' |
391 * -------
392 * |
393 * |----------------------------------------|
394 * | |
395 * ------------------------ ---------------------
396 * | '_mh_execute_header' | | 'main' |
397 * | Flags: 0x00000000 | | Flags: 0x00000000 |
398 * | Addr: 0x00000000 | | Addr: 0x00001160 |
399 * ------------------------ ---------------------
400 *
401 * This graph represents the trie for the exports "__mh_execute_header" and
402 * "_main". In the graph only the "_main" and "__mh_execute_header" nodes are
403 * terminal.
404*/
405
406const uint8_t *processExportNode(const uint8_t *CurrPtr,
407 const uint8_t *const End,
408 MachOYAML::ExportEntry &Entry) {
409 if (CurrPtr >= End)
410 return CurrPtr;
411 unsigned Count = 0;
412 Entry.TerminalSize = decodeULEB128(CurrPtr, &Count);
413 CurrPtr += Count;
414 if (Entry.TerminalSize != 0) {
415 Entry.Flags = decodeULEB128(CurrPtr, &Count);
416 CurrPtr += Count;
417 if (Entry.Flags & MachO::EXPORT_SYMBOL_FLAGS_REEXPORT) {
418 Entry.Address = 0;
419 Entry.Other = decodeULEB128(CurrPtr, &Count);
420 CurrPtr += Count;
421 Entry.ImportName = std::string(reinterpret_cast<const char *>(CurrPtr));
422 } else {
423 Entry.Address = decodeULEB128(CurrPtr, &Count);
424 CurrPtr += Count;
425 if (Entry.Flags & MachO::EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER) {
426 Entry.Other = decodeULEB128(CurrPtr, &Count);
427 CurrPtr += Count;
428 } else
429 Entry.Other = 0;
430 }
431 }
432 uint8_t childrenCount = *CurrPtr++;
433 if (childrenCount == 0)
434 return CurrPtr;
435
436 Entry.Children.insert(Entry.Children.begin(), (size_t)childrenCount,
437 MachOYAML::ExportEntry());
438 for (auto &Child : Entry.Children) {
439 Child.Name = std::string(reinterpret_cast<const char *>(CurrPtr));
440 CurrPtr += Child.Name.length() + 1;
441 Child.NodeOffset = decodeULEB128(CurrPtr, &Count);
442 CurrPtr += Count;
443 }
444 for (auto &Child : Entry.Children) {
445 CurrPtr = processExportNode(CurrPtr, End, Child);
446 }
447 return CurrPtr;
448}
449
450void MachODumper::dumpExportTrie(std::unique_ptr<MachOYAML::Object> &Y) {
451 MachOYAML::LinkEditData &LEData = Y->LinkEdit;
452 auto ExportsTrie = Obj.getDyldInfoExportsTrie();
453 processExportNode(ExportsTrie.begin(), ExportsTrie.end(), LEData.ExportTrie);
454}
455
456template <typename nlist_t>
457MachOYAML::NListEntry constructNameList(const nlist_t &nlist) {
458 MachOYAML::NListEntry NL;
459 NL.n_strx = nlist.n_strx;
460 NL.n_type = nlist.n_type;
461 NL.n_sect = nlist.n_sect;
462 NL.n_desc = nlist.n_desc;
463 NL.n_value = nlist.n_value;
464 return NL;
465}
466
467void MachODumper::dumpSymbols(std::unique_ptr<MachOYAML::Object> &Y) {
468 MachOYAML::LinkEditData &LEData = Y->LinkEdit;
469
470 for (auto Symbol : Obj.symbols()) {
471 MachOYAML::NListEntry NLE =
472 Obj.is64Bit()
473 ? constructNameList<MachO::nlist_64>(
474 Obj.getSymbol64TableEntry(Symbol.getRawDataRefImpl()))
475 : constructNameList<MachO::nlist>(
476 Obj.getSymbolTableEntry(Symbol.getRawDataRefImpl()));
477 LEData.NameList.push_back(NLE);
478 }
479
480 StringRef RemainingTable = Obj.getStringTableData();
481 while (RemainingTable.size() > 0) {
482 auto SymbolPair = RemainingTable.split('\0');
483 RemainingTable = SymbolPair.second;
484 LEData.StringTable.push_back(SymbolPair.first);
485 }
486}
487
488Error macho2yaml(raw_ostream &Out, const object::MachOObjectFile &Obj) {
489 MachODumper Dumper(Obj);
490 Expected<std::unique_ptr<MachOYAML::Object>> YAML = Dumper.dump();
491 if (!YAML)
492 return YAML.takeError();
493
494 yaml::YamlObjectFile YAMLFile;
495 YAMLFile.MachO = std::move(YAML.get());
496
497 yaml::Output Yout(Out);
498 Yout << YAMLFile;
499 return Error::success();
500}
501
502Error macho2yaml(raw_ostream &Out, const object::MachOUniversalBinary &Obj) {
503 yaml::YamlObjectFile YAMLFile;
504 YAMLFile.FatMachO.reset(new MachOYAML::UniversalBinary());
505 MachOYAML::UniversalBinary &YAML = *YAMLFile.FatMachO;
506 YAML.Header.magic = Obj.getMagic();
507 YAML.Header.nfat_arch = Obj.getNumberOfObjects();
508
509 for (auto Slice : Obj.objects()) {
510 MachOYAML::FatArch arch;
511 arch.cputype = Slice.getCPUType();
512 arch.cpusubtype = Slice.getCPUSubType();
513 arch.offset = Slice.getOffset();
514 arch.size = Slice.getSize();
515 arch.align = Slice.getAlign();
516 arch.reserved = Slice.getReserved();
517 YAML.FatArchs.push_back(arch);
518
519 auto SliceObj = Slice.getAsObjectFile();
520 if (!SliceObj)
521 return SliceObj.takeError();
522
523 MachODumper Dumper(*SliceObj.get());
524 Expected<std::unique_ptr<MachOYAML::Object>> YAMLObj = Dumper.dump();
525 if (!YAMLObj)
526 return YAMLObj.takeError();
527 YAML.Slices.push_back(*YAMLObj.get());
528 }
529
530 yaml::Output Yout(Out);
531 Yout << YAML;
532 return Error::success();
533}
534
535std::error_code macho2yaml(raw_ostream &Out, const object::Binary &Binary) {
536 if (const auto *MachOObj = dyn_cast<object::MachOUniversalBinary>(&Binary)) {
537 if (auto Err = macho2yaml(Out, *MachOObj)) {
538 return errorToErrorCode(std::move(Err));
539 }
540 return obj2yaml_error::success;
541 }
542
543 if (const auto *MachOObj = dyn_cast<object::MachOObjectFile>(&Binary)) {
544 if (auto Err = macho2yaml(Out, *MachOObj)) {
545 return errorToErrorCode(std::move(Err));
546 }
547 return obj2yaml_error::success;
548 }
549
550 return obj2yaml_error::unsupported_obj_file_format;
551}