summaryrefslogtreecommitdiffstats
path: root/llvm/tools/yaml2obj/yaml2macho.cpp
diff options
context:
space:
mode:
authorSeiya Nuta <nuta@seiya.me>2019-06-17 02:07:20 +0000
committerSeiya Nuta <nuta@seiya.me>2019-06-17 02:07:20 +0000
commit4f15732067602c38f5280899971bb24f43612dd4 (patch)
tree3c1596f24f2e98caabe4c8c5eb07b3dcbb7cfe4b /llvm/tools/yaml2obj/yaml2macho.cpp
parent13de174b4c4847255f1d510dc6dafeb5294753ef (diff)
downloadbcm5719-llvm-4f15732067602c38f5280899971bb24f43612dd4.tar.gz
bcm5719-llvm-4f15732067602c38f5280899971bb24f43612dd4.zip
[yaml2obj][MachO] Don't fill dummy data for virtual sections
Summary: Currently, MachOWriter::writeSectionData writes dummy data (0xdeadbeef) to fill section data areas in the file even if the section is a virtual one. Since virtual sections don't occupy any space in the file, writing dummy data could results the "OS.tell() - fileStart <= Sec.offset" assertion failure. This patch fixes the bug by simply not writing any dummy data for virtual sections. Reviewers: beanz, jhenderson, rupprecht, alexshap Reviewed By: alexshap Subscribers: compnerd, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62991 llvm-svn: 363525
Diffstat (limited to 'llvm/tools/yaml2obj/yaml2macho.cpp')
-rw-r--r--llvm/tools/yaml2obj/yaml2macho.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/llvm/tools/yaml2obj/yaml2macho.cpp b/llvm/tools/yaml2obj/yaml2macho.cpp
index 2df03fd3901..9dcc7d1d759 100644
--- a/llvm/tools/yaml2obj/yaml2macho.cpp
+++ b/llvm/tools/yaml2obj/yaml2macho.cpp
@@ -262,6 +262,12 @@ 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) {
@@ -300,10 +306,16 @@ Error MachOWriter::writeSectionData(raw_ostream &OS) {
} else if (0 == strncmp(&Sec.sectname[0], "__debug_line", 16)) {
DWARFYAML::EmitDebugLine(OS, Obj.DWARF);
}
- } else {
- // Fills section data with 0xDEADBEEF
- Fill(OS, Sec.size, 0xDEADBEEFu);
+
+ continue;
}
+
+ // Skip if it's a virtual section.
+ if (isVirtualSection(Sec.flags & MachO::SECTION_TYPE))
+ continue;
+
+ // 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;
OpenPOWER on IntegriCloud