elf2rpl: Fix .rodata section flags to have WRITE.

Yes, READ ONLY data requires a WRITE flag.
This commit is contained in:
James Benton 2018-05-25 00:16:57 +01:00
parent 0a4a7c66b3
commit a1072fc729

View File

@ -597,12 +597,37 @@ fixSectionAlign(ElfFile &file)
section->header.addralign = 64u; section->header.addralign = 64u;
} else if (section->header.type == elf::SHT_RPL_IMPORTS) { } else if (section->header.type == elf::SHT_RPL_IMPORTS) {
section->header.addralign = 4u; section->header.addralign = 4u;
} else if (section->header.type == elf::SHT_RPL_EXPORTS) {
section->header.addralign = 4u;
} else if (section->header.type == elf::SHT_STRTAB) {
section->header.addralign = 1u;
} }
} }
return true; return true;
} }
/**
* .rodate requires W flag.
*/
static bool
fixRoDataFlags(ElfFile &file)
{
for (auto &section : file.sections) {
if (section->header.type == elf::SHT_PROGBITS &&
!(section->header.flags & elf::SHF_EXECINSTR)) {
section->header.flags |= elf::SHF_WRITE;
}
}
return true;
}
/**
* Relocate a section to a new address.
*/
static bool static bool
relocateSection(ElfFile &file, relocateSection(ElfFile &file,
ElfFile::Section &section, ElfFile::Section &section,
@ -719,6 +744,10 @@ fixLoaderVirtualAddresses(ElfFile &file)
return true; return true;
} }
/**
* zlib deflate any suitable section.
*/
static bool static bool
deflateSections(ElfFile &file) deflateSections(ElfFile &file)
{ {
@ -962,6 +991,11 @@ int main(int argc, const char **argv)
return -1; return -1;
} }
if (!fixRoDataFlags(elf)) {
fmt::print("ERROR: fixRoDataFlags failed");
return -1;
}
if (!deflateSections(elf)) { if (!deflateSections(elf)) {
fmt::print("ERROR: deflateSections failed"); fmt::print("ERROR: deflateSections failed");
return -1; return -1;