From b31b773762169899ef1963673eec2da99aefebca Mon Sep 17 00:00:00 2001 From: aliaspider Date: Tue, 29 Sep 2020 14:20:30 +0100 Subject: [PATCH] - enforce the SHF_WRITE flag on data sections. - fix address calculation for SYMTAB/STRTAB relocations. --- src/elf2rpl/main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/elf2rpl/main.cpp b/src/elf2rpl/main.cpp index c316c39..034f142 100644 --- a/src/elf2rpl/main.cpp +++ b/src/elf2rpl/main.cpp @@ -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(section.header.offset)); section.data.resize(section.header.size); @@ -579,8 +583,8 @@ fixLoaderVirtualAddresses(ElfFile &file) auto §ion = 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(); }