diff options
| author | Chris Bieneman <beanz@apple.com> | 2016-05-17 17:03:28 +0000 |
|---|---|---|
| committer | Chris Bieneman <beanz@apple.com> | 2016-05-17 17:03:28 +0000 |
| commit | 3552c426e9616a3848dea20d9e6ad3335557e9f6 (patch) | |
| tree | 282903d918810c834be3be8b11e64a24f18d5c8a /llvm/tools/yaml2obj/yaml2macho.cpp | |
| parent | a73dcbcd13ee469bd154b1bc17bbd1c0444eb4b3 (diff) | |
| download | bcm5719-llvm-3552c426e9616a3848dea20d9e6ad3335557e9f6.tar.gz bcm5719-llvm-3552c426e9616a3848dea20d9e6ad3335557e9f6.zip | |
[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
Diffstat (limited to 'llvm/tools/yaml2obj/yaml2macho.cpp')
| -rw-r--r-- | llvm/tools/yaml2obj/yaml2macho.cpp | 36 |
1 files changed, 26 insertions, 10 deletions
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<const char *>(&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<const char *>(&(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<const char *>(&(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<char> 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<uint32_t> FillData; + FillData.insert(FillData.begin(), BytesRemaining / 4 + 1, 0xDEADBEEFu); + OS.write(reinterpret_cast<char *>(FillData.data()), BytesRemaining); } } return Error::success(); |

