MachOYAML.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. //===- MachOYAML.cpp - MachO YAMLIO implementation ------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines classes for handling the YAML representation of MachO.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "llvm/ObjectYAML/MachOYAML.h"
  13. #include "llvm/ADT/StringRef.h"
  14. #include "llvm/BinaryFormat/MachO.h"
  15. #include "llvm/Support/Format.h"
  16. #include "llvm/Support/Host.h"
  17. #include "llvm/Support/YAMLTraits.h"
  18. #include "llvm/Support/raw_ostream.h"
  19. #include <cinttypes>
  20. #include <cstdint>
  21. #include <cstring>
  22. namespace llvm {
  23. MachOYAML::LoadCommand::~LoadCommand() = default;
  24. bool MachOYAML::LinkEditData::isEmpty() const {
  25. return 0 ==
  26. RebaseOpcodes.size() + BindOpcodes.size() + WeakBindOpcodes.size() +
  27. LazyBindOpcodes.size() + ExportTrie.Children.size() +
  28. NameList.size() + StringTable.size();
  29. }
  30. namespace yaml {
  31. void ScalarTraits<char_16>::output(const char_16 &Val, void *,
  32. raw_ostream &Out) {
  33. auto Len = strnlen(&Val[0], 16);
  34. Out << StringRef(&Val[0], Len);
  35. }
  36. StringRef ScalarTraits<char_16>::input(StringRef Scalar, void *, char_16 &Val) {
  37. size_t CopySize = 16 >= Scalar.size() ? 16 : Scalar.size();
  38. memcpy((void *)Val, Scalar.data(), CopySize);
  39. if (Scalar.size() < 16) {
  40. memset((void *)&Val[Scalar.size()], 0, 16 - Scalar.size());
  41. }
  42. return StringRef();
  43. }
  44. QuotingType ScalarTraits<char_16>::mustQuote(StringRef S) {
  45. return needsQuotes(S);
  46. }
  47. void ScalarTraits<uuid_t>::output(const uuid_t &Val, void *, raw_ostream &Out) {
  48. Out.write_uuid(Val);
  49. }
  50. StringRef ScalarTraits<uuid_t>::input(StringRef Scalar, void *, uuid_t &Val) {
  51. size_t OutIdx = 0;
  52. for (size_t Idx = 0; Idx < Scalar.size(); ++Idx) {
  53. if (Scalar[Idx] == '-' || OutIdx >= 16)
  54. continue;
  55. unsigned long long TempInt;
  56. if (getAsUnsignedInteger(Scalar.slice(Idx, Idx + 2), 16, TempInt))
  57. return "invalid number";
  58. if (TempInt > 0xFF)
  59. return "out of range number";
  60. Val[OutIdx] = static_cast<uint8_t>(TempInt);
  61. ++Idx; // increment idx an extra time because we're consuming 2 chars
  62. ++OutIdx;
  63. }
  64. return StringRef();
  65. }
  66. QuotingType ScalarTraits<uuid_t>::mustQuote(StringRef S) {
  67. return needsQuotes(S);
  68. }
  69. void MappingTraits<MachOYAML::FileHeader>::mapping(
  70. IO &IO, MachOYAML::FileHeader &FileHdr) {
  71. IO.mapRequired("magic", FileHdr.magic);
  72. IO.mapRequired("cputype", FileHdr.cputype);
  73. IO.mapRequired("cpusubtype", FileHdr.cpusubtype);
  74. IO.mapRequired("filetype", FileHdr.filetype);
  75. IO.mapRequired("ncmds", FileHdr.ncmds);
  76. IO.mapRequired("sizeofcmds", FileHdr.sizeofcmds);
  77. IO.mapRequired("flags", FileHdr.flags);
  78. if (FileHdr.magic == MachO::MH_MAGIC_64 ||
  79. FileHdr.magic == MachO::MH_CIGAM_64)
  80. IO.mapRequired("reserved", FileHdr.reserved);
  81. }
  82. void MappingTraits<MachOYAML::Object>::mapping(IO &IO,
  83. MachOYAML::Object &Object) {
  84. // If the context isn't already set, tag the document as !mach-o.
  85. // For Fat files there will be a different tag so they can be differentiated.
  86. if (!IO.getContext()) {
  87. IO.setContext(&Object);
  88. }
  89. IO.mapTag("!mach-o", true);
  90. IO.mapOptional("IsLittleEndian", Object.IsLittleEndian,
  91. sys::IsLittleEndianHost);
  92. Object.DWARF.IsLittleEndian = Object.IsLittleEndian;
  93. IO.mapRequired("FileHeader", Object.Header);
  94. Object.DWARF.Is64BitAddrSize = Object.Header.magic == MachO::MH_MAGIC_64 ||
  95. Object.Header.magic == MachO::MH_CIGAM_64;
  96. IO.mapOptional("LoadCommands", Object.LoadCommands);
  97. if (Object.RawLinkEditSegment || !IO.outputting())
  98. IO.mapOptional("__LINKEDIT", Object.RawLinkEditSegment);
  99. if(!Object.LinkEdit.isEmpty() || !IO.outputting())
  100. IO.mapOptional("LinkEditData", Object.LinkEdit);
  101. if(!Object.DWARF.isEmpty() || !IO.outputting())
  102. IO.mapOptional("DWARF", Object.DWARF);
  103. if (IO.getContext() == &Object)
  104. IO.setContext(nullptr);
  105. }
  106. void MappingTraits<MachOYAML::FatHeader>::mapping(
  107. IO &IO, MachOYAML::FatHeader &FatHeader) {
  108. IO.mapRequired("magic", FatHeader.magic);
  109. IO.mapRequired("nfat_arch", FatHeader.nfat_arch);
  110. }
  111. void MappingTraits<MachOYAML::FatArch>::mapping(IO &IO,
  112. MachOYAML::FatArch &FatArch) {
  113. IO.mapRequired("cputype", FatArch.cputype);
  114. IO.mapRequired("cpusubtype", FatArch.cpusubtype);
  115. IO.mapRequired("offset", FatArch.offset);
  116. IO.mapRequired("size", FatArch.size);
  117. IO.mapRequired("align", FatArch.align);
  118. IO.mapOptional("reserved", FatArch.reserved,
  119. static_cast<llvm::yaml::Hex32>(0));
  120. }
  121. void MappingTraits<MachOYAML::UniversalBinary>::mapping(
  122. IO &IO, MachOYAML::UniversalBinary &UniversalBinary) {
  123. if (!IO.getContext()) {
  124. IO.setContext(&UniversalBinary);
  125. IO.mapTag("!fat-mach-o", true);
  126. }
  127. IO.mapRequired("FatHeader", UniversalBinary.Header);
  128. IO.mapRequired("FatArchs", UniversalBinary.FatArchs);
  129. IO.mapRequired("Slices", UniversalBinary.Slices);
  130. if (IO.getContext() == &UniversalBinary)
  131. IO.setContext(nullptr);
  132. }
  133. void MappingTraits<MachOYAML::LinkEditData>::mapping(
  134. IO &IO, MachOYAML::LinkEditData &LinkEditData) {
  135. IO.mapOptional("RebaseOpcodes", LinkEditData.RebaseOpcodes);
  136. IO.mapOptional("BindOpcodes", LinkEditData.BindOpcodes);
  137. IO.mapOptional("WeakBindOpcodes", LinkEditData.WeakBindOpcodes);
  138. IO.mapOptional("LazyBindOpcodes", LinkEditData.LazyBindOpcodes);
  139. if (!LinkEditData.ExportTrie.Children.empty() || !IO.outputting())
  140. IO.mapOptional("ExportTrie", LinkEditData.ExportTrie);
  141. IO.mapOptional("NameList", LinkEditData.NameList);
  142. IO.mapOptional("StringTable", LinkEditData.StringTable);
  143. IO.mapOptional("IndirectSymbols", LinkEditData.IndirectSymbols);
  144. }
  145. void MappingTraits<MachOYAML::RebaseOpcode>::mapping(
  146. IO &IO, MachOYAML::RebaseOpcode &RebaseOpcode) {
  147. IO.mapRequired("Opcode", RebaseOpcode.Opcode);
  148. IO.mapRequired("Imm", RebaseOpcode.Imm);
  149. IO.mapOptional("ExtraData", RebaseOpcode.ExtraData);
  150. }
  151. void MappingTraits<MachOYAML::BindOpcode>::mapping(
  152. IO &IO, MachOYAML::BindOpcode &BindOpcode) {
  153. IO.mapRequired("Opcode", BindOpcode.Opcode);
  154. IO.mapRequired("Imm", BindOpcode.Imm);
  155. IO.mapOptional("ULEBExtraData", BindOpcode.ULEBExtraData);
  156. IO.mapOptional("SLEBExtraData", BindOpcode.SLEBExtraData);
  157. IO.mapOptional("Symbol", BindOpcode.Symbol);
  158. }
  159. void MappingTraits<MachOYAML::ExportEntry>::mapping(
  160. IO &IO, MachOYAML::ExportEntry &ExportEntry) {
  161. IO.mapRequired("TerminalSize", ExportEntry.TerminalSize);
  162. IO.mapOptional("NodeOffset", ExportEntry.NodeOffset);
  163. IO.mapOptional("Name", ExportEntry.Name);
  164. IO.mapOptional("Flags", ExportEntry.Flags);
  165. IO.mapOptional("Address", ExportEntry.Address);
  166. IO.mapOptional("Other", ExportEntry.Other);
  167. IO.mapOptional("ImportName", ExportEntry.ImportName);
  168. IO.mapOptional("Children", ExportEntry.Children);
  169. }
  170. void MappingTraits<MachOYAML::NListEntry>::mapping(
  171. IO &IO, MachOYAML::NListEntry &NListEntry) {
  172. IO.mapRequired("n_strx", NListEntry.n_strx);
  173. IO.mapRequired("n_type", NListEntry.n_type);
  174. IO.mapRequired("n_sect", NListEntry.n_sect);
  175. IO.mapRequired("n_desc", NListEntry.n_desc);
  176. IO.mapRequired("n_value", NListEntry.n_value);
  177. }
  178. template <typename StructType>
  179. void mapLoadCommandData(IO &IO, MachOYAML::LoadCommand &LoadCommand) {}
  180. template <>
  181. void mapLoadCommandData<MachO::segment_command>(
  182. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  183. IO.mapOptional("Sections", LoadCommand.Sections);
  184. }
  185. template <>
  186. void mapLoadCommandData<MachO::segment_command_64>(
  187. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  188. IO.mapOptional("Sections", LoadCommand.Sections);
  189. }
  190. template <>
  191. void mapLoadCommandData<MachO::dylib_command>(
  192. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  193. IO.mapOptional("Content", LoadCommand.Content);
  194. }
  195. template <>
  196. void mapLoadCommandData<MachO::rpath_command>(
  197. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  198. IO.mapOptional("Content", LoadCommand.Content);
  199. }
  200. template <>
  201. void mapLoadCommandData<MachO::dylinker_command>(
  202. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  203. IO.mapOptional("Content", LoadCommand.Content);
  204. }
  205. template <>
  206. void mapLoadCommandData<MachO::sub_framework_command>(
  207. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  208. IO.mapOptional("Content", LoadCommand.Content);
  209. }
  210. template <>
  211. void mapLoadCommandData<MachO::sub_umbrella_command>(
  212. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  213. IO.mapOptional("Content", LoadCommand.Content);
  214. }
  215. template <>
  216. void mapLoadCommandData<MachO::sub_client_command>(
  217. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  218. IO.mapOptional("Content", LoadCommand.Content);
  219. }
  220. template <>
  221. void mapLoadCommandData<MachO::sub_library_command>(
  222. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  223. IO.mapOptional("Content", LoadCommand.Content);
  224. }
  225. template <>
  226. void mapLoadCommandData<MachO::build_version_command>(
  227. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  228. IO.mapOptional("Tools", LoadCommand.Tools);
  229. }
  230. void MappingTraits<MachOYAML::LoadCommand>::mapping(
  231. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  232. MachO::LoadCommandType TempCmd = static_cast<MachO::LoadCommandType>(
  233. LoadCommand.Data.load_command_data.cmd);
  234. IO.mapRequired("cmd", TempCmd);
  235. LoadCommand.Data.load_command_data.cmd = TempCmd;
  236. IO.mapRequired("cmdsize", LoadCommand.Data.load_command_data.cmdsize);
  237. #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
  238. case MachO::LCName: \
  239. MappingTraits<MachO::LCStruct>::mapping(IO, \
  240. LoadCommand.Data.LCStruct##_data); \
  241. mapLoadCommandData<MachO::LCStruct>(IO, LoadCommand); \
  242. break;
  243. switch (LoadCommand.Data.load_command_data.cmd) {
  244. #include "llvm/BinaryFormat/MachO.def"
  245. }
  246. IO.mapOptional("PayloadBytes", LoadCommand.PayloadBytes);
  247. IO.mapOptional("ZeroPadBytes", LoadCommand.ZeroPadBytes, (uint64_t)0ull);
  248. }
  249. void MappingTraits<MachO::dyld_info_command>::mapping(
  250. IO &IO, MachO::dyld_info_command &LoadCommand) {
  251. IO.mapRequired("rebase_off", LoadCommand.rebase_off);
  252. IO.mapRequired("rebase_size", LoadCommand.rebase_size);
  253. IO.mapRequired("bind_off", LoadCommand.bind_off);
  254. IO.mapRequired("bind_size", LoadCommand.bind_size);
  255. IO.mapRequired("weak_bind_off", LoadCommand.weak_bind_off);
  256. IO.mapRequired("weak_bind_size", LoadCommand.weak_bind_size);
  257. IO.mapRequired("lazy_bind_off", LoadCommand.lazy_bind_off);
  258. IO.mapRequired("lazy_bind_size", LoadCommand.lazy_bind_size);
  259. IO.mapRequired("export_off", LoadCommand.export_off);
  260. IO.mapRequired("export_size", LoadCommand.export_size);
  261. }
  262. void MappingTraits<MachOYAML::Relocation>::mapping(
  263. IO &IO, MachOYAML::Relocation &Relocation) {
  264. IO.mapRequired("address", Relocation.address);
  265. IO.mapRequired("symbolnum", Relocation.symbolnum);
  266. IO.mapRequired("pcrel", Relocation.is_pcrel);
  267. IO.mapRequired("length", Relocation.length);
  268. IO.mapRequired("extern", Relocation.is_extern);
  269. IO.mapRequired("type", Relocation.type);
  270. IO.mapRequired("scattered", Relocation.is_scattered);
  271. IO.mapRequired("value", Relocation.value);
  272. }
  273. void MappingTraits<MachOYAML::Section>::mapping(IO &IO,
  274. MachOYAML::Section &Section) {
  275. IO.mapRequired("sectname", Section.sectname);
  276. IO.mapRequired("segname", Section.segname);
  277. IO.mapRequired("addr", Section.addr);
  278. IO.mapRequired("size", Section.size);
  279. IO.mapRequired("offset", Section.offset);
  280. IO.mapRequired("align", Section.align);
  281. IO.mapRequired("reloff", Section.reloff);
  282. IO.mapRequired("nreloc", Section.nreloc);
  283. IO.mapRequired("flags", Section.flags);
  284. IO.mapRequired("reserved1", Section.reserved1);
  285. IO.mapRequired("reserved2", Section.reserved2);
  286. IO.mapOptional("reserved3", Section.reserved3);
  287. IO.mapOptional("content", Section.content);
  288. IO.mapOptional("relocations", Section.relocations);
  289. }
  290. std::string
  291. MappingTraits<MachOYAML::Section>::validate(IO &IO,
  292. MachOYAML::Section &Section) {
  293. if (Section.content && Section.size < Section.content->binary_size())
  294. return "Section size must be greater than or equal to the content size";
  295. return "";
  296. }
  297. void MappingTraits<MachO::build_tool_version>::mapping(
  298. IO &IO, MachO::build_tool_version &tool) {
  299. IO.mapRequired("tool", tool.tool);
  300. IO.mapRequired("version", tool.version);
  301. }
  302. void MappingTraits<MachO::dylib>::mapping(IO &IO, MachO::dylib &DylibStruct) {
  303. IO.mapRequired("name", DylibStruct.name);
  304. IO.mapRequired("timestamp", DylibStruct.timestamp);
  305. IO.mapRequired("current_version", DylibStruct.current_version);
  306. IO.mapRequired("compatibility_version", DylibStruct.compatibility_version);
  307. }
  308. void MappingTraits<MachO::dylib_command>::mapping(
  309. IO &IO, MachO::dylib_command &LoadCommand) {
  310. IO.mapRequired("dylib", LoadCommand.dylib);
  311. }
  312. void MappingTraits<MachO::dylinker_command>::mapping(
  313. IO &IO, MachO::dylinker_command &LoadCommand) {
  314. IO.mapRequired("name", LoadCommand.name);
  315. }
  316. void MappingTraits<MachO::dysymtab_command>::mapping(
  317. IO &IO, MachO::dysymtab_command &LoadCommand) {
  318. IO.mapRequired("ilocalsym", LoadCommand.ilocalsym);
  319. IO.mapRequired("nlocalsym", LoadCommand.nlocalsym);
  320. IO.mapRequired("iextdefsym", LoadCommand.iextdefsym);
  321. IO.mapRequired("nextdefsym", LoadCommand.nextdefsym);
  322. IO.mapRequired("iundefsym", LoadCommand.iundefsym);
  323. IO.mapRequired("nundefsym", LoadCommand.nundefsym);
  324. IO.mapRequired("tocoff", LoadCommand.tocoff);
  325. IO.mapRequired("ntoc", LoadCommand.ntoc);
  326. IO.mapRequired("modtaboff", LoadCommand.modtaboff);
  327. IO.mapRequired("nmodtab", LoadCommand.nmodtab);
  328. IO.mapRequired("extrefsymoff", LoadCommand.extrefsymoff);
  329. IO.mapRequired("nextrefsyms", LoadCommand.nextrefsyms);
  330. IO.mapRequired("indirectsymoff", LoadCommand.indirectsymoff);
  331. IO.mapRequired("nindirectsyms", LoadCommand.nindirectsyms);
  332. IO.mapRequired("extreloff", LoadCommand.extreloff);
  333. IO.mapRequired("nextrel", LoadCommand.nextrel);
  334. IO.mapRequired("locreloff", LoadCommand.locreloff);
  335. IO.mapRequired("nlocrel", LoadCommand.nlocrel);
  336. }
  337. void MappingTraits<MachO::encryption_info_command>::mapping(
  338. IO &IO, MachO::encryption_info_command &LoadCommand) {
  339. IO.mapRequired("cryptoff", LoadCommand.cryptoff);
  340. IO.mapRequired("cryptsize", LoadCommand.cryptsize);
  341. IO.mapRequired("cryptid", LoadCommand.cryptid);
  342. }
  343. void MappingTraits<MachO::encryption_info_command_64>::mapping(
  344. IO &IO, MachO::encryption_info_command_64 &LoadCommand) {
  345. IO.mapRequired("cryptoff", LoadCommand.cryptoff);
  346. IO.mapRequired("cryptsize", LoadCommand.cryptsize);
  347. IO.mapRequired("cryptid", LoadCommand.cryptid);
  348. IO.mapRequired("pad", LoadCommand.pad);
  349. }
  350. void MappingTraits<MachO::entry_point_command>::mapping(
  351. IO &IO, MachO::entry_point_command &LoadCommand) {
  352. IO.mapRequired("entryoff", LoadCommand.entryoff);
  353. IO.mapRequired("stacksize", LoadCommand.stacksize);
  354. }
  355. void MappingTraits<MachO::fvmfile_command>::mapping(
  356. IO &IO, MachO::fvmfile_command &LoadCommand) {
  357. IO.mapRequired("name", LoadCommand.name);
  358. IO.mapRequired("header_addr", LoadCommand.header_addr);
  359. }
  360. void MappingTraits<MachO::fvmlib>::mapping(IO &IO, MachO::fvmlib &FVMLib) {
  361. IO.mapRequired("name", FVMLib.name);
  362. IO.mapRequired("minor_version", FVMLib.minor_version);
  363. IO.mapRequired("header_addr", FVMLib.header_addr);
  364. }
  365. void MappingTraits<MachO::fvmlib_command>::mapping(
  366. IO &IO, MachO::fvmlib_command &LoadCommand) {
  367. IO.mapRequired("fvmlib", LoadCommand.fvmlib);
  368. }
  369. void MappingTraits<MachO::ident_command>::mapping(
  370. IO &IO, MachO::ident_command &LoadCommand) {}
  371. void MappingTraits<MachO::linkedit_data_command>::mapping(
  372. IO &IO, MachO::linkedit_data_command &LoadCommand) {
  373. IO.mapRequired("dataoff", LoadCommand.dataoff);
  374. IO.mapRequired("datasize", LoadCommand.datasize);
  375. }
  376. void MappingTraits<MachO::linker_option_command>::mapping(
  377. IO &IO, MachO::linker_option_command &LoadCommand) {
  378. IO.mapRequired("count", LoadCommand.count);
  379. }
  380. void MappingTraits<MachO::prebind_cksum_command>::mapping(
  381. IO &IO, MachO::prebind_cksum_command &LoadCommand) {
  382. IO.mapRequired("cksum", LoadCommand.cksum);
  383. }
  384. void MappingTraits<MachO::load_command>::mapping(
  385. IO &IO, MachO::load_command &LoadCommand) {}
  386. void MappingTraits<MachO::prebound_dylib_command>::mapping(
  387. IO &IO, MachO::prebound_dylib_command &LoadCommand) {
  388. IO.mapRequired("name", LoadCommand.name);
  389. IO.mapRequired("nmodules", LoadCommand.nmodules);
  390. IO.mapRequired("linked_modules", LoadCommand.linked_modules);
  391. }
  392. void MappingTraits<MachO::routines_command>::mapping(
  393. IO &IO, MachO::routines_command &LoadCommand) {
  394. IO.mapRequired("init_address", LoadCommand.init_address);
  395. IO.mapRequired("init_module", LoadCommand.init_module);
  396. IO.mapRequired("reserved1", LoadCommand.reserved1);
  397. IO.mapRequired("reserved2", LoadCommand.reserved2);
  398. IO.mapRequired("reserved3", LoadCommand.reserved3);
  399. IO.mapRequired("reserved4", LoadCommand.reserved4);
  400. IO.mapRequired("reserved5", LoadCommand.reserved5);
  401. IO.mapRequired("reserved6", LoadCommand.reserved6);
  402. }
  403. void MappingTraits<MachO::routines_command_64>::mapping(
  404. IO &IO, MachO::routines_command_64 &LoadCommand) {
  405. IO.mapRequired("init_address", LoadCommand.init_address);
  406. IO.mapRequired("init_module", LoadCommand.init_module);
  407. IO.mapRequired("reserved1", LoadCommand.reserved1);
  408. IO.mapRequired("reserved2", LoadCommand.reserved2);
  409. IO.mapRequired("reserved3", LoadCommand.reserved3);
  410. IO.mapRequired("reserved4", LoadCommand.reserved4);
  411. IO.mapRequired("reserved5", LoadCommand.reserved5);
  412. IO.mapRequired("reserved6", LoadCommand.reserved6);
  413. }
  414. void MappingTraits<MachO::rpath_command>::mapping(
  415. IO &IO, MachO::rpath_command &LoadCommand) {
  416. IO.mapRequired("path", LoadCommand.path);
  417. }
  418. void MappingTraits<MachO::section>::mapping(IO &IO, MachO::section &Section) {
  419. IO.mapRequired("sectname", Section.sectname);
  420. IO.mapRequired("segname", Section.segname);
  421. IO.mapRequired("addr", Section.addr);
  422. IO.mapRequired("size", Section.size);
  423. IO.mapRequired("offset", Section.offset);
  424. IO.mapRequired("align", Section.align);
  425. IO.mapRequired("reloff", Section.reloff);
  426. IO.mapRequired("nreloc", Section.nreloc);
  427. IO.mapRequired("flags", Section.flags);
  428. IO.mapRequired("reserved1", Section.reserved1);
  429. IO.mapRequired("reserved2", Section.reserved2);
  430. }
  431. void MappingTraits<MachO::section_64>::mapping(IO &IO,
  432. MachO::section_64 &Section) {
  433. IO.mapRequired("sectname", Section.sectname);
  434. IO.mapRequired("segname", Section.segname);
  435. IO.mapRequired("addr", Section.addr);
  436. IO.mapRequired("size", Section.size);
  437. IO.mapRequired("offset", Section.offset);
  438. IO.mapRequired("align", Section.align);
  439. IO.mapRequired("reloff", Section.reloff);
  440. IO.mapRequired("nreloc", Section.nreloc);
  441. IO.mapRequired("flags", Section.flags);
  442. IO.mapRequired("reserved1", Section.reserved1);
  443. IO.mapRequired("reserved2", Section.reserved2);
  444. IO.mapRequired("reserved3", Section.reserved3);
  445. }
  446. void MappingTraits<MachO::segment_command>::mapping(
  447. IO &IO, MachO::segment_command &LoadCommand) {
  448. IO.mapRequired("segname", LoadCommand.segname);
  449. IO.mapRequired("vmaddr", LoadCommand.vmaddr);
  450. IO.mapRequired("vmsize", LoadCommand.vmsize);
  451. IO.mapRequired("fileoff", LoadCommand.fileoff);
  452. IO.mapRequired("filesize", LoadCommand.filesize);
  453. IO.mapRequired("maxprot", LoadCommand.maxprot);
  454. IO.mapRequired("initprot", LoadCommand.initprot);
  455. IO.mapRequired("nsects", LoadCommand.nsects);
  456. IO.mapRequired("flags", LoadCommand.flags);
  457. }
  458. void MappingTraits<MachO::segment_command_64>::mapping(
  459. IO &IO, MachO::segment_command_64 &LoadCommand) {
  460. IO.mapRequired("segname", LoadCommand.segname);
  461. IO.mapRequired("vmaddr", LoadCommand.vmaddr);
  462. IO.mapRequired("vmsize", LoadCommand.vmsize);
  463. IO.mapRequired("fileoff", LoadCommand.fileoff);
  464. IO.mapRequired("filesize", LoadCommand.filesize);
  465. IO.mapRequired("maxprot", LoadCommand.maxprot);
  466. IO.mapRequired("initprot", LoadCommand.initprot);
  467. IO.mapRequired("nsects", LoadCommand.nsects);
  468. IO.mapRequired("flags", LoadCommand.flags);
  469. }
  470. void MappingTraits<MachO::source_version_command>::mapping(
  471. IO &IO, MachO::source_version_command &LoadCommand) {
  472. IO.mapRequired("version", LoadCommand.version);
  473. }
  474. void MappingTraits<MachO::sub_client_command>::mapping(
  475. IO &IO, MachO::sub_client_command &LoadCommand) {
  476. IO.mapRequired("client", LoadCommand.client);
  477. }
  478. void MappingTraits<MachO::sub_framework_command>::mapping(
  479. IO &IO, MachO::sub_framework_command &LoadCommand) {
  480. IO.mapRequired("umbrella", LoadCommand.umbrella);
  481. }
  482. void MappingTraits<MachO::sub_library_command>::mapping(
  483. IO &IO, MachO::sub_library_command &LoadCommand) {
  484. IO.mapRequired("sub_library", LoadCommand.sub_library);
  485. }
  486. void MappingTraits<MachO::sub_umbrella_command>::mapping(
  487. IO &IO, MachO::sub_umbrella_command &LoadCommand) {
  488. IO.mapRequired("sub_umbrella", LoadCommand.sub_umbrella);
  489. }
  490. void MappingTraits<MachO::symseg_command>::mapping(
  491. IO &IO, MachO::symseg_command &LoadCommand) {
  492. IO.mapRequired("offset", LoadCommand.offset);
  493. IO.mapRequired("size", LoadCommand.size);
  494. }
  495. void MappingTraits<MachO::symtab_command>::mapping(
  496. IO &IO, MachO::symtab_command &LoadCommand) {
  497. IO.mapRequired("symoff", LoadCommand.symoff);
  498. IO.mapRequired("nsyms", LoadCommand.nsyms);
  499. IO.mapRequired("stroff", LoadCommand.stroff);
  500. IO.mapRequired("strsize", LoadCommand.strsize);
  501. }
  502. void MappingTraits<MachO::thread_command>::mapping(
  503. IO &IO, MachO::thread_command &LoadCommand) {}
  504. void MappingTraits<MachO::twolevel_hints_command>::mapping(
  505. IO &IO, MachO::twolevel_hints_command &LoadCommand) {
  506. IO.mapRequired("offset", LoadCommand.offset);
  507. IO.mapRequired("nhints", LoadCommand.nhints);
  508. }
  509. void MappingTraits<MachO::uuid_command>::mapping(
  510. IO &IO, MachO::uuid_command &LoadCommand) {
  511. IO.mapRequired("uuid", LoadCommand.uuid);
  512. }
  513. void MappingTraits<MachO::version_min_command>::mapping(
  514. IO &IO, MachO::version_min_command &LoadCommand) {
  515. IO.mapRequired("version", LoadCommand.version);
  516. IO.mapRequired("sdk", LoadCommand.sdk);
  517. }
  518. void MappingTraits<MachO::note_command>::mapping(
  519. IO &IO, MachO::note_command &LoadCommand) {
  520. IO.mapRequired("data_owner", LoadCommand.data_owner);
  521. IO.mapRequired("offset", LoadCommand.offset);
  522. IO.mapRequired("size", LoadCommand.size);
  523. }
  524. void MappingTraits<MachO::build_version_command>::mapping(
  525. IO &IO, MachO::build_version_command &LoadCommand) {
  526. IO.mapRequired("platform", LoadCommand.platform);
  527. IO.mapRequired("minos", LoadCommand.minos);
  528. IO.mapRequired("sdk", LoadCommand.sdk);
  529. IO.mapRequired("ntools", LoadCommand.ntools);
  530. }
  531. } // end namespace yaml
  532. } // end namespace llvm