From 3552c426e9616a3848dea20d9e6ad3335557e9f6 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Tue, 17 May 2016 17:03:28 +0000 Subject: [obj2yaml] [yaml2obj] Support for MachO load command structures This adds support for all the MachO *_command structures. The load_command payloads still are not represented, but that will come next. llvm-svn: 269782 --- llvm/tools/yaml2obj/yaml2macho.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'llvm/tools/yaml2obj/yaml2macho.cpp') diff --git a/llvm/tools/yaml2obj/yaml2macho.cpp b/llvm/tools/yaml2obj/yaml2macho.cpp index ed243a2cdd9..bf891a6e983 100644 --- a/llvm/tools/yaml2obj/yaml2macho.cpp +++ b/llvm/tools/yaml2obj/yaml2macho.cpp @@ -79,17 +79,33 @@ Error MachOWriter::writeHeader(raw_ostream &OS) { Error MachOWriter::writeLoadCommands(raw_ostream &OS) { for (auto &LC : Obj.LoadCommands) { - MachO::load_command LCTemp; - LCTemp.cmd = LC->cmd; - LCTemp.cmdsize = LC->cmdsize; - OS.write(reinterpret_cast(&LCTemp), - sizeof(MachO::load_command)); - auto remaining_size = LC->cmdsize - sizeof(MachO::load_command); - if (remaining_size > 0) { + size_t BytesWritten = 0; +#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \ + case MachO::LCName: \ + OS.write(reinterpret_cast(&(LC.load_command_data.LCStruct)), \ + sizeof(MachO::LCStruct)); \ + BytesWritten = sizeof(MachO::LCStruct); \ + break; + + switch (LC.load_command_data.load_command.cmd) { + default: + OS.write( + reinterpret_cast(&(LC.load_command_data.load_command)), + sizeof(MachO::load_command)); + BytesWritten = sizeof(MachO::load_command); + break; +#include "llvm/Support/MachO.def" + } + + auto BytesRemaining = + LC.load_command_data.load_command.cmdsize - BytesWritten; + if (BytesRemaining > 0) { // TODO: Replace all this once the load command data is present in yaml. - std::vector fill_data; - fill_data.insert(fill_data.begin(), remaining_size, 0); - OS.write(fill_data.data(), remaining_size); + // For now I fill with 0xDEADBEEF because it is easy to spot on a hex + // viewer. + std::vector FillData; + FillData.insert(FillData.begin(), BytesRemaining / 4 + 1, 0xDEADBEEFu); + OS.write(reinterpret_cast(FillData.data()), BytesRemaining); } } return Error::success(); -- cgit v1.2.3