diff options
author | Seiya Nuta <nuta@seiya.me> | 2019-08-20 08:49:07 +0000 |
---|---|---|
committer | Seiya Nuta <nuta@seiya.me> | 2019-08-20 08:49:07 +0000 |
commit | 522377494b3d7c4bfcaa9a632497231ac3c19143 (patch) | |
tree | 04b3f4e044f0b13d3518de9865b2b50ab81ce652 /llvm/lib | |
parent | 9c371309f38cfe1fe1bf52af2e70dd448044e7e2 (diff) | |
download | bcm5719-llvm-522377494b3d7c4bfcaa9a632497231ac3c19143.tar.gz bcm5719-llvm-522377494b3d7c4bfcaa9a632497231ac3c19143.zip |
[yaml2obj/obj2yaml][MachO] Allow setting custom section data
Reviewers: alexshap, jhenderson, rupprecht
Reviewed By: alexshap, jhenderson
Subscribers: abrachet, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65799
llvm-svn: 369348
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/ObjectYAML/MachOEmitter.cpp | 17 | ||||
-rw-r--r-- | llvm/lib/ObjectYAML/MachOYAML.cpp | 9 |
3 files changed, 24 insertions, 9 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index be1950e08ed..fdba3442af2 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -1945,6 +1945,11 @@ uint64_t MachOObjectFile::getSectionSize(DataRefImpl Sec) const { return SectSize; } +ArrayRef<uint8_t> MachOObjectFile::getSectionContents(uint32_t Offset, + uint64_t Size) const { + return arrayRefFromStringRef(getData().substr(Offset, Size)); +} + Expected<ArrayRef<uint8_t>> MachOObjectFile::getSectionContents(DataRefImpl Sec) const { uint32_t Offset; @@ -1960,7 +1965,7 @@ MachOObjectFile::getSectionContents(DataRefImpl Sec) const { Size = Sect.size; } - return arrayRefFromStringRef(getData().substr(Offset, Size)); + return getSectionContents(Offset, Size); } uint64_t MachOObjectFile::getSectionAlignment(DataRefImpl Sec) const { diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp index e7789d06cf7..47d7667787b 100644 --- a/llvm/lib/ObjectYAML/MachOEmitter.cpp +++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp @@ -262,11 +262,6 @@ Error MachOWriter::writeLoadCommands(raw_ostream &OS) { return Error::success(); } -static bool isVirtualSection(uint8_t type) { - return (type == MachO::S_ZEROFILL || type == MachO::S_GB_ZEROFILL || - type == MachO::S_THREAD_LOCAL_ZEROFILL); -} - Error MachOWriter::writeSectionData(raw_ostream &OS) { bool FoundLinkEditSeg = false; for (auto &LC : Obj.LoadCommands) { @@ -311,11 +306,17 @@ Error MachOWriter::writeSectionData(raw_ostream &OS) { } // Skip if it's a virtual section. - if (isVirtualSection(Sec.flags & MachO::SECTION_TYPE)) + if (MachO::isVirtualSection(Sec.flags & MachO::SECTION_TYPE)) continue; - // Fill section data with 0xDEADBEEF - Fill(OS, Sec.size, 0xDEADBEEFu); + if (Sec.content) { + yaml::BinaryRef Content = *Sec.content; + Content.writeAsBinary(OS); + ZeroFillBytes(OS, Sec.size - Content.binary_size()); + } else { + // Fill section data with 0xDEADBEEF. + Fill(OS, Sec.size, 0xDEADBEEFu); + } } uint64_t segSize = is64Bit ? LC.Data.segment_command_64_data.filesize : LC.Data.segment_command_data.filesize; diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp b/llvm/lib/ObjectYAML/MachOYAML.cpp index d12f12cf443..0f7cd1e1495 100644 --- a/llvm/lib/ObjectYAML/MachOYAML.cpp +++ b/llvm/lib/ObjectYAML/MachOYAML.cpp @@ -287,6 +287,15 @@ void MappingTraits<MachOYAML::Section>::mapping(IO &IO, IO.mapRequired("reserved1", Section.reserved1); IO.mapRequired("reserved2", Section.reserved2); IO.mapOptional("reserved3", Section.reserved3); + IO.mapOptional("content", Section.content); +} + +StringRef +MappingTraits<MachOYAML::Section>::validate(IO &IO, + MachOYAML::Section &Section) { + if (Section.content && Section.size < Section.content->binary_size()) + return "Section size must be greater than or equal to the content size"; + return {}; } void MappingTraits<MachO::build_tool_version>::mapping( |