Skip to content

Commit

Permalink
- enforce the SHF_WRITE flag on data sections.
Browse files Browse the repository at this point in the history
- fix address calculation for SYMTAB/STRTAB relocations.
  • Loading branch information
aliaspider committed Sep 29, 2020
1 parent ea66999 commit b31b773
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/elf2rpl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ readElf(ElfFile &file, const std::string &filename)
continue;
}

if (section.header.addr >= DataBaseAddress && section.header.addr < LoadBaseAddress) {
section.header.flags |= elf::SHF_WRITE;
}

auto pos = in.tellg();
in.seekg(static_cast<size_t>(section.header.offset));
section.data.resize(section.header.size);
Expand Down Expand Up @@ -579,8 +583,8 @@ fixLoaderVirtualAddresses(ElfFile &file)
auto &section = file.sections[i];
if (section->header.type == elf::SHT_SYMTAB ||
section->header.type == elf::SHT_STRTAB) {
relocateSection(file, *section, i,
align_up(loadMax, section->header.addralign));
loadMax = align_up(loadMax, section->header.addralign);
relocateSection(file, *section, i, loadMax);
section->header.flags |= elf::SHF_ALLOC;
loadMax += section->data.size();
}
Expand Down

0 comments on commit b31b773

Please sign in to comment.