diff options
author | Chris Bieneman <beanz@apple.com> | 2016-05-17 21:31:02 +0000 |
---|---|---|
committer | Chris Bieneman <beanz@apple.com> | 2016-05-17 21:31:02 +0000 |
commit | 7b504b75312ec0a02f20aba47d59e254f76d2e56 (patch) | |
tree | d993365a431d4cd4682ef0fb2c001d10b651965a /llvm/tools/yaml2obj | |
parent | e3ec688df598f3ff052776b72a9f4601838a2d1a (diff) | |
download | bcm5719-llvm-7b504b75312ec0a02f20aba47d59e254f76d2e56.tar.gz bcm5719-llvm-7b504b75312ec0a02f20aba47d59e254f76d2e56.zip |
[obj2yaml] [yaml2obj] Support MachO section and section_64 structs
This patch adds round trip support for MachO section structs.
llvm-svn: 269845
Diffstat (limited to 'llvm/tools/yaml2obj')
-rw-r--r-- | llvm/tools/yaml2obj/yaml2macho.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/tools/yaml2obj/yaml2macho.cpp b/llvm/tools/yaml2obj/yaml2macho.cpp index 772c710c098..0e8799e2ce1 100644 --- a/llvm/tools/yaml2obj/yaml2macho.cpp +++ b/llvm/tools/yaml2obj/yaml2macho.cpp @@ -77,6 +77,23 @@ Error MachOWriter::writeHeader(raw_ostream &OS) { return Error::success(); } +template <typename SectionType> +SectionType constructSection(MachOYAML::Section Sec) { + SectionType TempSec; + memcpy(reinterpret_cast<void *>(&TempSec.sectname[0]), &Sec.sectname[0], 16); + memcpy(reinterpret_cast<void *>(&TempSec.segname[0]), &Sec.segname[0], 16); + TempSec.addr = Sec.addr; + TempSec.size = Sec.size; + TempSec.offset = Sec.offset; + TempSec.align = Sec.align; + TempSec.reloff = Sec.reloff; + TempSec.nreloc = Sec.nreloc; + TempSec.flags = Sec.flags; + TempSec.reserved1 = Sec.reserved1; + TempSec.reserved2 = Sec.reserved2; + return TempSec; +} + Error MachOWriter::writeLoadCommands(raw_ostream &OS) { for (auto &LC : Obj.LoadCommands) { size_t BytesWritten = 0; @@ -96,6 +113,21 @@ Error MachOWriter::writeLoadCommands(raw_ostream &OS) { #include "llvm/Support/MachO.def" } + if(LC.Data.load_command_data.cmd == MachO::LC_SEGMENT) { + for(auto Sec : LC.Sections) { + auto TempSec = constructSection<MachO::section>(Sec); + OS.write(reinterpret_cast<const char *>(&(TempSec)), sizeof(MachO::section)); + BytesWritten += sizeof(MachO::section); + } + } else if(LC.Data.load_command_data.cmd == MachO::LC_SEGMENT_64) { + for(auto Sec : LC.Sections) { + auto TempSec = constructSection<MachO::section_64>(Sec); + TempSec.reserved3 = Sec.reserved3; + OS.write(reinterpret_cast<const char *>(&(TempSec)), sizeof(MachO::section_64)); + BytesWritten += sizeof(MachO::section_64); + } + } + auto BytesRemaining = LC.Data.load_command_data.cmdsize - BytesWritten; if (BytesRemaining > 0) { |