Fix R_AARCH64_ABS/PREL relocations
According to specification arm64 relocations should not use *reloc value. See http://infocenter.arm.com/help/topic/com.arm.doc.ihi0056b/IHI0056B_aaelf64.pdf section 4.6.5 Bug: http://b/24977219 Bug: http://b/24527155 Change-Id: I3813255771f408ba957963c6ad56ed08e5110d83
This commit is contained in:
@@ -2165,24 +2165,23 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r
|
|||||||
count_relocation(kRelocAbsolute);
|
count_relocation(kRelocAbsolute);
|
||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO ABS64 %16llx <- %16llx %s\n",
|
TRACE_TYPE(RELO, "RELO ABS64 %16llx <- %16llx %s\n",
|
||||||
reloc, (sym_addr + addend), sym_name);
|
reloc, sym_addr + addend, sym_name);
|
||||||
*reinterpret_cast<ElfW(Addr)*>(reloc) += (sym_addr + addend);
|
*reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr + addend;
|
||||||
break;
|
break;
|
||||||
case R_AARCH64_ABS32:
|
case R_AARCH64_ABS32:
|
||||||
count_relocation(kRelocAbsolute);
|
count_relocation(kRelocAbsolute);
|
||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO ABS32 %16llx <- %16llx %s\n",
|
TRACE_TYPE(RELO, "RELO ABS32 %16llx <- %16llx %s\n",
|
||||||
reloc, (sym_addr + addend), sym_name);
|
reloc, sym_addr + addend, sym_name);
|
||||||
{
|
{
|
||||||
const ElfW(Addr) reloc_value = *reinterpret_cast<ElfW(Addr)*>(reloc);
|
|
||||||
const ElfW(Addr) min_value = static_cast<ElfW(Addr)>(INT32_MIN);
|
const ElfW(Addr) min_value = static_cast<ElfW(Addr)>(INT32_MIN);
|
||||||
const ElfW(Addr) max_value = static_cast<ElfW(Addr)>(UINT32_MAX);
|
const ElfW(Addr) max_value = static_cast<ElfW(Addr)>(UINT32_MAX);
|
||||||
if ((min_value <= (reloc_value + (sym_addr + addend))) &&
|
if ((min_value <= (sym_addr + addend)) &&
|
||||||
((reloc_value + (sym_addr + addend)) <= max_value)) {
|
((sym_addr + addend) <= max_value)) {
|
||||||
*reinterpret_cast<ElfW(Addr)*>(reloc) += (sym_addr + addend);
|
*reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr + addend;
|
||||||
} else {
|
} else {
|
||||||
DL_ERR("0x%016llx out of range 0x%016llx to 0x%016llx",
|
DL_ERR("0x%016llx out of range 0x%016llx to 0x%016llx",
|
||||||
(reloc_value + (sym_addr + addend)), min_value, max_value);
|
sym_addr + addend, min_value, max_value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2191,17 +2190,16 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r
|
|||||||
count_relocation(kRelocAbsolute);
|
count_relocation(kRelocAbsolute);
|
||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO ABS16 %16llx <- %16llx %s\n",
|
TRACE_TYPE(RELO, "RELO ABS16 %16llx <- %16llx %s\n",
|
||||||
reloc, (sym_addr + addend), sym_name);
|
reloc, sym_addr + addend, sym_name);
|
||||||
{
|
{
|
||||||
const ElfW(Addr) reloc_value = *reinterpret_cast<ElfW(Addr)*>(reloc);
|
|
||||||
const ElfW(Addr) min_value = static_cast<ElfW(Addr)>(INT16_MIN);
|
const ElfW(Addr) min_value = static_cast<ElfW(Addr)>(INT16_MIN);
|
||||||
const ElfW(Addr) max_value = static_cast<ElfW(Addr)>(UINT16_MAX);
|
const ElfW(Addr) max_value = static_cast<ElfW(Addr)>(UINT16_MAX);
|
||||||
if ((min_value <= (reloc_value + (sym_addr + addend))) &&
|
if ((min_value <= (sym_addr + addend)) &&
|
||||||
((reloc_value + (sym_addr + addend)) <= max_value)) {
|
((sym_addr + addend) <= max_value)) {
|
||||||
*reinterpret_cast<ElfW(Addr)*>(reloc) += (sym_addr + addend);
|
*reinterpret_cast<ElfW(Addr)*>(reloc) = (sym_addr + addend);
|
||||||
} else {
|
} else {
|
||||||
DL_ERR("0x%016llx out of range 0x%016llx to 0x%016llx",
|
DL_ERR("0x%016llx out of range 0x%016llx to 0x%016llx",
|
||||||
reloc_value + (sym_addr + addend), min_value, max_value);
|
sym_addr + addend, min_value, max_value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2210,24 +2208,23 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r
|
|||||||
count_relocation(kRelocRelative);
|
count_relocation(kRelocRelative);
|
||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO REL64 %16llx <- %16llx - %16llx %s\n",
|
TRACE_TYPE(RELO, "RELO REL64 %16llx <- %16llx - %16llx %s\n",
|
||||||
reloc, (sym_addr + addend), rel->r_offset, sym_name);
|
reloc, sym_addr + addend, rel->r_offset, sym_name);
|
||||||
*reinterpret_cast<ElfW(Addr)*>(reloc) += (sym_addr + addend) - rel->r_offset;
|
*reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr + addend - rel->r_offset;
|
||||||
break;
|
break;
|
||||||
case R_AARCH64_PREL32:
|
case R_AARCH64_PREL32:
|
||||||
count_relocation(kRelocRelative);
|
count_relocation(kRelocRelative);
|
||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO REL32 %16llx <- %16llx - %16llx %s\n",
|
TRACE_TYPE(RELO, "RELO REL32 %16llx <- %16llx - %16llx %s\n",
|
||||||
reloc, (sym_addr + addend), rel->r_offset, sym_name);
|
reloc, sym_addr + addend, rel->r_offset, sym_name);
|
||||||
{
|
{
|
||||||
const ElfW(Addr) reloc_value = *reinterpret_cast<ElfW(Addr)*>(reloc);
|
|
||||||
const ElfW(Addr) min_value = static_cast<ElfW(Addr)>(INT32_MIN);
|
const ElfW(Addr) min_value = static_cast<ElfW(Addr)>(INT32_MIN);
|
||||||
const ElfW(Addr) max_value = static_cast<ElfW(Addr)>(UINT32_MAX);
|
const ElfW(Addr) max_value = static_cast<ElfW(Addr)>(UINT32_MAX);
|
||||||
if ((min_value <= (reloc_value + ((sym_addr + addend) - rel->r_offset))) &&
|
if ((min_value <= (sym_addr + addend - rel->r_offset)) &&
|
||||||
((reloc_value + ((sym_addr + addend) - rel->r_offset)) <= max_value)) {
|
((sym_addr + addend - rel->r_offset) <= max_value)) {
|
||||||
*reinterpret_cast<ElfW(Addr)*>(reloc) += ((sym_addr + addend) - rel->r_offset);
|
*reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr + addend - rel->r_offset;
|
||||||
} else {
|
} else {
|
||||||
DL_ERR("0x%016llx out of range 0x%016llx to 0x%016llx",
|
DL_ERR("0x%016llx out of range 0x%016llx to 0x%016llx",
|
||||||
reloc_value + ((sym_addr + addend) - rel->r_offset), min_value, max_value);
|
sym_addr + addend - rel->r_offset, min_value, max_value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2236,17 +2233,16 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r
|
|||||||
count_relocation(kRelocRelative);
|
count_relocation(kRelocRelative);
|
||||||
MARK(rel->r_offset);
|
MARK(rel->r_offset);
|
||||||
TRACE_TYPE(RELO, "RELO REL16 %16llx <- %16llx - %16llx %s\n",
|
TRACE_TYPE(RELO, "RELO REL16 %16llx <- %16llx - %16llx %s\n",
|
||||||
reloc, (sym_addr + addend), rel->r_offset, sym_name);
|
reloc, sym_addr + addend, rel->r_offset, sym_name);
|
||||||
{
|
{
|
||||||
const ElfW(Addr) reloc_value = *reinterpret_cast<ElfW(Addr)*>(reloc);
|
|
||||||
const ElfW(Addr) min_value = static_cast<ElfW(Addr)>(INT16_MIN);
|
const ElfW(Addr) min_value = static_cast<ElfW(Addr)>(INT16_MIN);
|
||||||
const ElfW(Addr) max_value = static_cast<ElfW(Addr)>(UINT16_MAX);
|
const ElfW(Addr) max_value = static_cast<ElfW(Addr)>(UINT16_MAX);
|
||||||
if ((min_value <= (reloc_value + ((sym_addr + addend) - rel->r_offset))) &&
|
if ((min_value <= (sym_addr + addend - rel->r_offset)) &&
|
||||||
((reloc_value + ((sym_addr + addend) - rel->r_offset)) <= max_value)) {
|
((sym_addr + addend - rel->r_offset) <= max_value)) {
|
||||||
*reinterpret_cast<ElfW(Addr)*>(reloc) += ((sym_addr + addend) - rel->r_offset);
|
*reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr + addend - rel->r_offset;
|
||||||
} else {
|
} else {
|
||||||
DL_ERR("0x%016llx out of range 0x%016llx to 0x%016llx",
|
DL_ERR("0x%016llx out of range 0x%016llx to 0x%016llx",
|
||||||
reloc_value + ((sym_addr + addend) - rel->r_offset), min_value, max_value);
|
sym_addr + addend - rel->r_offset, min_value, max_value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user