summaryrefslogtreecommitdiffstats
path: root/patchoat
diff options
context:
space:
mode:
authorVladimir Marko <vmarko@google.com>2015-05-13 19:06:30 +0100
committerVladimir Marko <vmarko@google.com>2015-05-14 13:34:08 +0100
commit3fc9903407c6e89ffbbc92ded9e272d9de58e9b6 (patch)
treeae8898200f09c4015ecc7d920711dd1053834e94 /patchoat
parentc3912c8a2db109a15603554fd456f56cd0a69ad0 (diff)
downloadandroid_art-3fc9903407c6e89ffbbc92ded9e272d9de58e9b6.tar.gz
android_art-3fc9903407c6e89ffbbc92ded9e272d9de58e9b6.tar.bz2
android_art-3fc9903407c6e89ffbbc92ded9e272d9de58e9b6.zip
ART: Do not relocate app program headers in patchoat.
Change the check whether to relocate program headers in patchoat to simply look whether there is a PT_LOAD section with p_vaddr == 0. If there is, don't relocate the headers, it should be an app. Otherwise, it's a boot image and needs to be relocated. Add overflow checking to ElfFileImpl<>::GetLoadedSize(). Bug: 21047854 Change-Id: Ie6737f338687296b6dbf4bb3b36358501dfb1587
Diffstat (limited to 'patchoat')
-rw-r--r--patchoat/patchoat.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc
index 4dc0967bc0..ef84a1717c 100644
--- a/patchoat/patchoat.cc
+++ b/patchoat/patchoat.cc
@@ -650,29 +650,34 @@ bool PatchOat::PatchElf() {
template <typename ElfFileImpl>
bool PatchOat::PatchElf(ElfFileImpl* oat_file) {
TimingLogger::ScopedTiming t("Fixup Elf Text Section", timings_);
+
+ // Fix up absolute references to locations within the boot image.
if (!oat_file->ApplyOatPatchesTo(".text", delta_)) {
return false;
}
+ // Update the OatHeader fields referencing the boot image.
if (!PatchOatHeader<ElfFileImpl>(oat_file)) {
return false;
}
- bool need_fixup = false;
+ bool need_boot_oat_fixup = true;
for (unsigned int i = 0; i < oat_file->GetProgramHeaderNum(); ++i) {
auto hdr = oat_file->GetProgramHeader(i);
- if ((hdr->p_vaddr != 0 && hdr->p_vaddr != hdr->p_offset) ||
- (hdr->p_paddr != 0 && hdr->p_paddr != hdr->p_offset)) {
- need_fixup = true;
+ if (hdr->p_type == PT_LOAD && hdr->p_vaddr == 0u) {
+ need_boot_oat_fixup = false;
break;
}
}
- if (!need_fixup) {
- // This was never passed through ElfFixup so all headers/symbols just have their offset as
- // their addr. Therefore we do not need to update these parts.
+ if (!need_boot_oat_fixup) {
+ // This is an app oat file that can be loaded at an arbitrary address in memory.
+ // Boot image references were patched above and there's nothing else to do.
return true;
}
+ // This is a boot oat file that's loaded at a particular address and we need
+ // to patch all absolute addresses, starting with ELF program headers.
+
t.NewTiming("Fixup Elf Headers");
// Fixup Phdr's
oat_file->FixupProgramHeaders(delta_);