Skip to content

Commit

Permalink
Fix calculateSectionOffsets for import sections.
Browse files Browse the repository at this point in the history
Fuck.
  • Loading branch information
exjam committed Sep 30, 2018
1 parent b03e4af commit 63119de
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tools/elf2rpl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ calculateSectionOffsets(ElfFile &file)
}

// Next the "readMin / readMax" sections, which are:
// - !(flags & SHF_EXECINSTR) || type == SHT_RPL_EXPORTS || type == SHT_RPL_IMPORTS
// - !(flags & SHF_EXECINSTR) || type == SHT_RPL_EXPORTS
// - !(flags & SHF_WRITE)
// - flags & SHF_ALLOC
for (auto &section : file.sections) {
Expand All @@ -629,8 +629,7 @@ calculateSectionOffsets(ElfFile &file)
}

if ((!(section->header.flags & elf::SHF_EXECINSTR) ||
section->header.type == elf::SHT_RPL_EXPORTS ||
section->header.type == elf::SHT_RPL_IMPORTS) &&
section->header.type == elf::SHT_RPL_EXPORTS) &&
!(section->header.flags & elf::SHF_WRITE) &&
(section->header.flags & elf::SHF_ALLOC)) {
section->header.offset = offset;
Expand All @@ -639,6 +638,16 @@ calculateSectionOffsets(ElfFile &file)
}
}

// Import sections are part of the read sections, but have execinstr flag set
// so let's insert them here to avoid complicating the above logic.
for (auto &section : file.sections) {
if (section->header.type == elf::SHT_RPL_IMPORTS) {
section->header.offset = offset;
section->header.size = static_cast<uint32_t>(section->data.size());
offset += section->header.size;
}
}

// Next the "textMin / textMax" sections, which are:
// - flags & SHF_EXECINSTR
// - type != SHT_RPL_EXPORTS
Expand Down

0 comments on commit 63119de

Please sign in to comment.