MachOYAML.cpp 23 KB

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