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:41:41 +0100
commita36098b3717e14baf6a173e72082f6ef3b7bcefd (patch)
treef52b4be71f2d9182bbf751a6949ef2d74c380c57 /patchoat
parent3beb245da9392818e3154d47593f82cf0ef69aac (diff)
downloadart-a36098b3717e14baf6a173e72082f6ef3b7bcefd.zip
art-a36098b3717e14baf6a173e72082f6ef3b7bcefd.tar.gz
art-a36098b3717e14baf6a173e72082f6ef3b7bcefd.tar.bz2
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 (cherry picked from commit 3fc9903407c6e89ffbbc92ded9e272d9de58e9b6) Change-Id: Ib3e1295fc06993bcfbaadd8f253ee4f5498f52e9
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 4dc0967..ef84a17 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_);