MachOYAML.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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.LinkEdit.isEmpty() || !IO.outputting())
  98. IO.mapOptional("LinkEditData", Object.LinkEdit);
  99. if(!Object.DWARF.isEmpty() || !IO.outputting())
  100. IO.mapOptional("DWARF", Object.DWARF);
  101. if (IO.getContext() == &Object)
  102. IO.setContext(nullptr);
  103. }
  104. void MappingTraits<MachOYAML::FatHeader>::mapping(
  105. IO &IO, MachOYAML::FatHeader &FatHeader) {
  106. IO.mapRequired("magic", FatHeader.magic);
  107. IO.mapRequired("nfat_arch", FatHeader.nfat_arch);
  108. }
  109. void MappingTraits<MachOYAML::FatArch>::mapping(IO &IO,
  110. MachOYAML::FatArch &FatArch) {
  111. IO.mapRequired("cputype", FatArch.cputype);
  112. IO.mapRequired("cpusubtype", FatArch.cpusubtype);
  113. IO.mapRequired("offset", FatArch.offset);
  114. IO.mapRequired("size", FatArch.size);
  115. IO.mapRequired("align", FatArch.align);
  116. IO.mapOptional("reserved", FatArch.reserved,
  117. static_cast<llvm::yaml::Hex32>(0));
  118. }
  119. void MappingTraits<MachOYAML::UniversalBinary>::mapping(
  120. IO &IO, MachOYAML::UniversalBinary &UniversalBinary) {
  121. if (!IO.getContext()) {
  122. IO.setContext(&UniversalBinary);
  123. IO.mapTag("!fat-mach-o", true);
  124. }
  125. IO.mapRequired("FatHeader", UniversalBinary.Header);
  126. IO.mapRequired("FatArchs", UniversalBinary.FatArchs);
  127. IO.mapRequired("Slices", UniversalBinary.Slices);
  128. if (IO.getContext() == &UniversalBinary)
  129. IO.setContext(nullptr);
  130. }
  131. void MappingTraits<MachOYAML::LinkEditData>::mapping(
  132. IO &IO, MachOYAML::LinkEditData &LinkEditData) {
  133. IO.mapOptional("RebaseOpcodes", LinkEditData.RebaseOpcodes);
  134. IO.mapOptional("BindOpcodes", LinkEditData.BindOpcodes);
  135. IO.mapOptional("WeakBindOpcodes", LinkEditData.WeakBindOpcodes);
  136. IO.mapOptional("LazyBindOpcodes", LinkEditData.LazyBindOpcodes);
  137. if (!LinkEditData.ExportTrie.Children.empty() || !IO.outputting())
  138. IO.mapOptional("ExportTrie", LinkEditData.ExportTrie);
  139. IO.mapOptional("NameList", LinkEditData.NameList);
  140. IO.mapOptional("StringTable", LinkEditData.StringTable);
  141. }
  142. void MappingTraits<MachOYAML::RebaseOpcode>::mapping(
  143. IO &IO, MachOYAML::RebaseOpcode &RebaseOpcode) {
  144. IO.mapRequired("Opcode", RebaseOpcode.Opcode);
  145. IO.mapRequired("Imm", RebaseOpcode.Imm);
  146. IO.mapOptional("ExtraData", RebaseOpcode.ExtraData);
  147. }
  148. void MappingTraits<MachOYAML::BindOpcode>::mapping(
  149. IO &IO, MachOYAML::BindOpcode &BindOpcode) {
  150. IO.mapRequired("Opcode", BindOpcode.Opcode);
  151. IO.mapRequired("Imm", BindOpcode.Imm);
  152. IO.mapOptional("ULEBExtraData", BindOpcode.ULEBExtraData);
  153. IO.mapOptional("SLEBExtraData", BindOpcode.SLEBExtraData);
  154. IO.mapOptional("Symbol", BindOpcode.Symbol);
  155. }
  156. void MappingTraits<MachOYAML::ExportEntry>::mapping(
  157. IO &IO, MachOYAML::ExportEntry &ExportEntry) {
  158. IO.mapRequired("TerminalSize", ExportEntry.TerminalSize);
  159. IO.mapOptional("NodeOffset", ExportEntry.NodeOffset);
  160. IO.mapOptional("Name", ExportEntry.Name);
  161. IO.mapOptional("Flags", ExportEntry.Flags);
  162. IO.mapOptional("Address", ExportEntry.Address);
  163. IO.mapOptional("Other", ExportEntry.Other);
  164. IO.mapOptional("ImportName", ExportEntry.ImportName);
  165. IO.mapOptional("Children", ExportEntry.Children);
  166. }
  167. void MappingTraits<MachOYAML::NListEntry>::mapping(
  168. IO &IO, MachOYAML::NListEntry &NListEntry) {
  169. IO.mapRequired("n_strx", NListEntry.n_strx);
  170. IO.mapRequired("n_type", NListEntry.n_type);
  171. IO.mapRequired("n_sect", NListEntry.n_sect);
  172. IO.mapRequired("n_desc", NListEntry.n_desc);
  173. IO.mapRequired("n_value", NListEntry.n_value);
  174. }
  175. template <typename StructType>
  176. void mapLoadCommandData(IO &IO, MachOYAML::LoadCommand &LoadCommand) {}
  177. template <>
  178. void mapLoadCommandData<MachO::segment_command>(
  179. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  180. IO.mapOptional("Sections", LoadCommand.Sections);
  181. }
  182. template <>
  183. void mapLoadCommandData<MachO::segment_command_64>(
  184. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  185. IO.mapOptional("Sections", LoadCommand.Sections);
  186. }
  187. template <>
  188. void mapLoadCommandData<MachO::dylib_command>(
  189. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  190. IO.mapOptional("PayloadString", LoadCommand.PayloadString);
  191. }
  192. template <>
  193. void mapLoadCommandData<MachO::rpath_command>(
  194. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  195. IO.mapOptional("PayloadString", LoadCommand.PayloadString);
  196. }
  197. template <>
  198. void mapLoadCommandData<MachO::dylinker_command>(
  199. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  200. IO.mapOptional("PayloadString", LoadCommand.PayloadString);
  201. }
  202. template <>
  203. void mapLoadCommandData<MachO::build_version_command>(
  204. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  205. IO.mapOptional("Tools", LoadCommand.Tools);
  206. }
  207. void MappingTraits<MachOYAML::LoadCommand>::mapping(
  208. IO &IO, MachOYAML::LoadCommand &LoadCommand) {
  209. MachO::LoadCommandType TempCmd = static_cast<MachO::LoadCommandType>(
  210. LoadCommand.Data.load_command_data.cmd);
  211. IO.mapRequired("cmd", TempCmd);
  212. LoadCommand.Data.load_command_data.cmd = TempCmd;
  213. IO.mapRequired("cmdsize", LoadCommand.Data.load_command_data.cmdsize);
  214. #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
  215. case MachO::LCName: \
  216. MappingTraits<MachO::LCStruct>::mapping(IO, \
  217. LoadCommand.Data.LCStruct##_data); \
  218. mapLoadCommandData<MachO::LCStruct>(IO, LoadCommand); \
  219. break;
  220. switch (LoadCommand.Data.load_command_data.cmd) {
  221. #include "llvm/BinaryFormat/MachO.def"
  222. }
  223. IO.mapOptional("PayloadBytes", LoadCommand.PayloadBytes);
  224. IO.mapOptional("ZeroPadBytes", LoadCommand.ZeroPadBytes, (uint64_t)0ull);
  225. }
  226. void MappingTraits<MachO::dyld_info_command>::mapping(
  227. IO &IO, MachO::dyld_info_command &LoadCommand) {
  228. IO.mapRequired("rebase_off", LoadCommand.rebase_off);
  229. IO.mapRequired("rebase_size", LoadCommand.rebase_size);
  230. IO.mapRequired("bind_off", LoadCommand.bind_off);
  231. IO.mapRequired("bind_size", LoadCommand.bind_size);
  232. IO.mapRequired("weak_bind_off", LoadCommand.weak_bind_off);
  233. IO.mapRequired("weak_bind_size", LoadCommand.weak_bind_size);
  234. IO.mapRequired("lazy_bind_off", LoadCommand.lazy_bind_off);
  235. IO.mapRequired("lazy_bind_size", LoadCommand.lazy_bind_size);
  236. IO.mapRequired("export_off", LoadCommand.export_off);
  237. IO.mapRequired("export_size", LoadCommand.export_size);
  238. }
  239. void MappingTraits<MachOYAML::Relocation>::mapping(
  240. IO &IO, MachOYAML::Relocation &Relocation) {
  241. IO.mapRequired("address", Relocation.address);
  242. IO.mapRequired("symbolnum", Relocation.symbolnum);
  243. IO.mapRequired("pcrel", Relocation.is_pcrel);
  244. IO.mapRequired("length", Relocation.length);
  245. IO.mapRequired("extern", Relocation.is_extern);
  246. IO.mapRequired("type", Relocation.type);
  247. IO.mapRequired("scattered", Relocation.is_scattered);
  248. IO.mapRequired("value", Relocation.value);
  249. }
  250. void MappingTraits<MachOYAML::Section>::mapping(IO &IO,
  251. MachOYAML::Section &Section) {
  252. IO.mapRequired("sectname", Section.sectname);
  253. IO.mapRequired("segname", Section.segname);
  254. IO.mapRequired("addr", Section.addr);
  255. IO.mapRequired("size", Section.size);
  256. IO.mapRequired("offset", Section.offset);
  257. IO.mapRequired("align", Section.align);
  258. IO.mapRequired("reloff", Section.reloff);
  259. IO.mapRequired("nreloc", Section.nreloc);
  260. IO.mapRequired("flags", Section.flags);
  261. IO.mapRequired("reserved1", Section.reserved1);
  262. IO.mapRequired("reserved2", Section.reserved2);
  263. IO.mapOptional("reserved3", Section.reserved3);
  264. IO.mapOptional("content", Section.content);
  265. IO.mapOptional("relocations", Section.relocations);
  266. }
  267. std::string
  268. MappingTraits<MachOYAML::Section>::validate(IO &IO,
  269. MachOYAML::Section &Section) {
  270. if (Section.content && Section.size < Section.content->binary_size())
  271. return "Section size must be greater than or equal to the content size";
  272. return "";
  273. }
  274. void MappingTraits<MachO::build_tool_version>::mapping(
  275. IO &IO, MachO::build_tool_version &tool) {
  276. IO.mapRequired("tool", tool.tool);
  277. IO.mapRequired("version", tool.version);
  278. }
  279. void MappingTraits<MachO::dylib>::mapping(IO &IO, MachO::dylib &DylibStruct) {
  280. IO.mapRequired("name", DylibStruct.name);
  281. IO.mapRequired("timestamp", DylibStruct.timestamp);
  282. IO.mapRequired("current_version", DylibStruct.current_version);
  283. IO.mapRequired("compatibility_version", DylibStruct.compatibility_version);
  284. }
  285. void MappingTraits<MachO::dylib_command>::mapping(
  286. IO &IO, MachO::dylib_command &LoadCommand) {
  287. IO.mapRequired("dylib", LoadCommand.dylib);
  288. }
  289. void MappingTraits<MachO::dylinker_command>::mapping(
  290. IO &IO, MachO::dylinker_command &LoadCommand) {
  291. IO.mapRequired("name", LoadCommand.name);
  292. }
  293. void MappingTraits<MachO::dysymtab_command>::mapping(
  294. IO &IO, MachO::dysymtab_command &LoadCommand) {
  295. IO.mapRequired("ilocalsym", LoadCommand.ilocalsym);
  296. IO.mapRequired("nlocalsym", LoadCommand.nlocalsym);
  297. IO.mapRequired("iextdefsym", LoadCommand.iextdefsym);
  298. IO.mapRequired("nextdefsym", LoadCommand.nextdefsym);
  299. IO.mapRequired("iundefsym", LoadCommand.iundefsym);
  300. IO.mapRequired("nundefsym", LoadCommand.nundefsym);
  301. IO.mapRequired("tocoff", LoadCommand.tocoff);
  302. IO.mapRequired("ntoc", LoadCommand.ntoc);
  303. IO.mapRequired("modtaboff", LoadCommand.modtaboff);
  304. IO.mapRequired("nmodtab", LoadCommand.nmodtab);
  305. IO.mapRequired("extrefsymoff", LoadCommand.extrefsymoff);
  306. IO.mapRequired("nextrefsyms", LoadCommand.nextrefsyms);
  307. IO.mapRequired("indirectsymoff", LoadCommand.indirectsymoff);
  308. IO.mapRequired("nindirectsyms", LoadCommand.nindirectsyms);
  309. IO.mapRequired("extreloff", LoadCommand.extreloff);
  310. IO.mapRequired("nextrel", LoadCommand.nextrel);
  311. IO.mapRequired("locreloff", LoadCommand.locreloff);
  312. IO.mapRequired("nlocrel", LoadCommand.nlocrel);
  313. }
  314. void MappingTraits<MachO::encryption_info_command>::mapping(
  315. IO &IO, MachO::encryption_info_command &LoadCommand) {
  316. IO.mapRequired("cryptoff", LoadCommand.cryptoff);
  317. IO.mapRequired("cryptsize", LoadCommand.cryptsize);
  318. IO.mapRequired("cryptid", LoadCommand.cryptid);
  319. }
  320. void MappingTraits<MachO::encryption_info_command_64>::mapping(
  321. IO &IO, MachO::encryption_info_command_64 &LoadCommand) {
  322. IO.mapRequired("cryptoff", LoadCommand.cryptoff);
  323. IO.mapRequired("cryptsize", LoadCommand.cryptsize);
  324. IO.mapRequired("cryptid", LoadCommand.cryptid);
  325. IO.mapRequired("pad", LoadCommand.pad);
  326. }
  327. void MappingTraits<MachO::entry_point_command>::mapping(
  328. IO &IO, MachO::entry_point_command &LoadCommand) {
  329. IO.mapRequired("entryoff", LoadCommand.entryoff);
  330. IO.mapRequired("stacksize", LoadCommand.stacksize);
  331. }
  332. void MappingTraits<MachO::fvmfile_command>::mapping(
  333. IO &IO, MachO::fvmfile_command &LoadCommand) {
  334. IO.mapRequired("name", LoadCommand.name);
  335. IO.mapRequired("header_addr", LoadCommand.header_addr);
  336. }
  337. void MappingTraits<MachO::fvmlib>::mapping(IO &IO, MachO::fvmlib &FVMLib) {
  338. IO.mapRequired("name", FVMLib.name);
  339. IO.mapRequired("minor_version", FVMLib.minor_version);
  340. IO.mapRequired("header_addr", FVMLib.header_addr);
  341. }
  342. void MappingTraits<MachO::fvmlib_command>::mapping(
  343. IO &IO, MachO::fvmlib_command &LoadCommand) {
  344. IO.mapRequired("fvmlib", LoadCommand.fvmlib);
  345. }
  346. void MappingTraits<MachO::ident_command>::mapping(
  347. IO &IO, MachO::ident_command &LoadCommand) {}
  348. void MappingTraits<MachO::linkedit_data_command>::mapping(
  349. IO &IO, MachO::linkedit_data_command &LoadCommand) {
  350. IO.mapRequired("dataoff", LoadCommand.dataoff);
  351. IO.mapRequired("datasize", LoadCommand.datasize);
  352. }
  353. void MappingTraits<MachO::linker_option_command>::mapping(
  354. IO &IO, MachO::linker_option_command &LoadCommand) {
  355. IO.mapRequired("count", LoadCommand.count);
  356. }
  357. void MappingTraits<MachO::prebind_cksum_command>::mapping(
  358. IO &IO, MachO::prebind_cksum_command &LoadCommand) {
  359. IO.mapRequired("cksum", LoadCommand.cksum);
  360. }
  361. void MappingTraits<MachO::load_command>::mapping(
  362. IO &IO, MachO::load_command &LoadCommand) {}
  363. void MappingTraits<MachO::prebound_dylib_command>::mapping(
  364. IO &IO, MachO::prebound_dylib_command &LoadCommand) {
  365. IO.mapRequired("name", LoadCommand.name);
  366. IO.mapRequired("nmodules", LoadCommand.nmodules);
  367. IO.mapRequired("linked_modules", LoadCommand.linked_modules);
  368. }
  369. void MappingTraits<MachO::routines_command>::mapping(
  370. IO &IO, MachO::routines_command &LoadCommand) {
  371. IO.mapRequired("init_address", LoadCommand.init_address);
  372. IO.mapRequired("init_module", LoadCommand.init_module);
  373. IO.mapRequired("reserved1", LoadCommand.reserved1);
  374. IO.mapRequired("reserved2", LoadCommand.reserved2);
  375. IO.mapRequired("reserved3", LoadCommand.reserved3);
  376. IO.mapRequired("reserved4", LoadCommand.reserved4);
  377. IO.mapRequired("reserved5", LoadCommand.reserved5);
  378. IO.mapRequired("reserved6", LoadCommand.reserved6);
  379. }
  380. void MappingTraits<MachO::routines_command_64>::mapping(
  381. IO &IO, MachO::routines_command_64 &LoadCommand) {
  382. IO.mapRequired("init_address", LoadCommand.init_address);
  383. IO.mapRequired("init_module", LoadCommand.init_module);
  384. IO.mapRequired("reserved1", LoadCommand.reserved1);
  385. IO.mapRequired("reserved2", LoadCommand.reserved2);
  386. IO.mapRequired("reserved3", LoadCommand.reserved3);
  387. IO.mapRequired("reserved4", LoadCommand.reserved4);
  388. IO.mapRequired("reserved5", LoadCommand.reserved5);
  389. IO.mapRequired("reserved6", LoadCommand.reserved6);
  390. }
  391. void MappingTraits<MachO::rpath_command>::mapping(
  392. IO &IO, MachO::rpath_command &LoadCommand) {
  393. IO.mapRequired("path", LoadCommand.path);
  394. }
  395. void MappingTraits<MachO::section>::mapping(IO &IO, MachO::section &Section) {
  396. IO.mapRequired("sectname", Section.sectname);
  397. IO.mapRequired("segname", Section.segname);
  398. IO.mapRequired("addr", Section.addr);
  399. IO.mapRequired("size", Section.size);
  400. IO.mapRequired("offset", Section.offset);
  401. IO.mapRequired("align", Section.align);
  402. IO.mapRequired("reloff", Section.reloff);
  403. IO.mapRequired("nreloc", Section.nreloc);
  404. IO.mapRequired("flags", Section.flags);
  405. IO.mapRequired("reserved1", Section.reserved1);
  406. IO.mapRequired("reserved2", Section.reserved2);
  407. }
  408. void MappingTraits<MachO::section_64>::mapping(IO &IO,
  409. MachO::section_64 &Section) {
  410. IO.mapRequired("sectname", Section.sectname);
  411. IO.mapRequired("segname", Section.segname);
  412. IO.mapRequired("addr", Section.addr);
  413. IO.mapRequired("size", Section.size);
  414. IO.mapRequired("offset", Section.offset);
  415. IO.mapRequired("align", Section.align);
  416. IO.mapRequired("reloff", Section.reloff);
  417. IO.mapRequired("nreloc", Section.nreloc);
  418. IO.mapRequired("flags", Section.flags);
  419. IO.mapRequired("reserved1", Section.reserved1);
  420. IO.mapRequired("reserved2", Section.reserved2);
  421. IO.mapRequired("reserved3", Section.reserved3);
  422. }
  423. void MappingTraits<MachO::segment_command>::mapping(
  424. IO &IO, MachO::segment_command &LoadCommand) {
  425. IO.mapRequired("segname", LoadCommand.segname);
  426. IO.mapRequired("vmaddr", LoadCommand.vmaddr);
  427. IO.mapRequired("vmsize", LoadCommand.vmsize);
  428. IO.mapRequired("fileoff", LoadCommand.fileoff);
  429. IO.mapRequired("filesize", LoadCommand.filesize);
  430. IO.mapRequired("maxprot", LoadCommand.maxprot);
  431. IO.mapRequired("initprot", LoadCommand.initprot);
  432. IO.mapRequired("nsects", LoadCommand.nsects);
  433. IO.mapRequired("flags", LoadCommand.flags);
  434. }
  435. void MappingTraits<MachO::segment_command_64>::mapping(
  436. IO &IO, MachO::segment_command_64 &LoadCommand) {
  437. IO.mapRequired("segname", LoadCommand.segname);
  438. IO.mapRequired("vmaddr", LoadCommand.vmaddr);
  439. IO.mapRequired("vmsize", LoadCommand.vmsize);
  440. IO.mapRequired("fileoff", LoadCommand.fileoff);
  441. IO.mapRequired("filesize", LoadCommand.filesize);
  442. IO.mapRequired("maxprot", LoadCommand.maxprot);
  443. IO.mapRequired("initprot", LoadCommand.initprot);
  444. IO.mapRequired("nsects", LoadCommand.nsects);
  445. IO.mapRequired("flags", LoadCommand.flags);
  446. }
  447. void MappingTraits<MachO::source_version_command>::mapping(
  448. IO &IO, MachO::source_version_command &LoadCommand) {
  449. IO.mapRequired("version", LoadCommand.version);
  450. }
  451. void MappingTraits<MachO::sub_client_command>::mapping(
  452. IO &IO, MachO::sub_client_command &LoadCommand) {
  453. IO.mapRequired("client", LoadCommand.client);
  454. }
  455. void MappingTraits<MachO::sub_framework_command>::mapping(
  456. IO &IO, MachO::sub_framework_command &LoadCommand) {
  457. IO.mapRequired("umbrella", LoadCommand.umbrella);
  458. }
  459. void MappingTraits<MachO::sub_library_command>::mapping(
  460. IO &IO, MachO::sub_library_command &LoadCommand) {
  461. IO.mapRequired("sub_library", LoadCommand.sub_library);
  462. }
  463. void MappingTraits<MachO::sub_umbrella_command>::mapping(
  464. IO &IO, MachO::sub_umbrella_command &LoadCommand) {
  465. IO.mapRequired("sub_umbrella", LoadCommand.sub_umbrella);
  466. }
  467. void MappingTraits<MachO::symseg_command>::mapping(
  468. IO &IO, MachO::symseg_command &LoadCommand) {
  469. IO.mapRequired("offset", LoadCommand.offset);
  470. IO.mapRequired("size", LoadCommand.size);
  471. }
  472. void MappingTraits<MachO::symtab_command>::mapping(
  473. IO &IO, MachO::symtab_command &LoadCommand) {
  474. IO.mapRequired("symoff", LoadCommand.symoff);
  475. IO.mapRequired("nsyms", LoadCommand.nsyms);
  476. IO.mapRequired("stroff", LoadCommand.stroff);
  477. IO.mapRequired("strsize", LoadCommand.strsize);
  478. }
  479. void MappingTraits<MachO::thread_command>::mapping(
  480. IO &IO, MachO::thread_command &LoadCommand) {}
  481. void MappingTraits<MachO::twolevel_hints_command>::mapping(
  482. IO &IO, MachO::twolevel_hints_command &LoadCommand) {
  483. IO.mapRequired("offset", LoadCommand.offset);
  484. IO.mapRequired("nhints", LoadCommand.nhints);
  485. }
  486. void MappingTraits<MachO::uuid_command>::mapping(
  487. IO &IO, MachO::uuid_command &LoadCommand) {
  488. IO.mapRequired("uuid", LoadCommand.uuid);
  489. }
  490. void MappingTraits<MachO::version_min_command>::mapping(
  491. IO &IO, MachO::version_min_command &LoadCommand) {
  492. IO.mapRequired("version", LoadCommand.version);
  493. IO.mapRequired("sdk", LoadCommand.sdk);
  494. }
  495. void MappingTraits<MachO::note_command>::mapping(
  496. IO &IO, MachO::note_command &LoadCommand) {
  497. IO.mapRequired("data_owner", LoadCommand.data_owner);
  498. IO.mapRequired("offset", LoadCommand.offset);
  499. IO.mapRequired("size", LoadCommand.size);
  500. }
  501. void MappingTraits<MachO::build_version_command>::mapping(
  502. IO &IO, MachO::build_version_command &LoadCommand) {
  503. IO.mapRequired("platform", LoadCommand.platform);
  504. IO.mapRequired("minos", LoadCommand.minos);
  505. IO.mapRequired("sdk", LoadCommand.sdk);
  506. IO.mapRequired("ntools", LoadCommand.ntools);
  507. }
  508. } // end namespace yaml
  509. } // end namespace llvm