[lld] r234746 - [PATCH 08/10] ELF/Aarch64: Add R_AARCH64_ADR_GOT_PAGE and R_AARCH64_LD64_GOT_LO12_NC checks
Adhemerval Zanella
azanella at linux.vnet.ibm.com
Mon Apr 13 05:08:22 PDT 2015
Author: azanella
Date: Mon Apr 13 07:08:21 2015
New Revision: 234746
URL: http://llvm.org/viewvc/llvm-project?rev=234746&view=rev
Log:
[PATCH 08/10] ELF/Aarch64: Add R_AARCH64_ADR_GOT_PAGE and R_AARCH64_LD64_GOT_LO12_NC checks
This patch adds R_AARCH64_ADR_GOT_PAGE overflow and R_AARCH64_LD64_GOT_LO12_NC
unaligned value checks.
Modified:
lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h
Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp?rev=234746&r1=234745&r2=234746&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp Mon Apr 13 07:08:21 2015
@@ -263,10 +263,12 @@ static void relocR_AARCH64_LDST128_ABS_L
write32le(location, result | read32le(location));
}
-static void relocR_AARCH64_ADR_GOT_PAGE(uint8_t *location, uint64_t P,
+static std::error_code relocR_AARCH64_ADR_GOT_PAGE(uint8_t *location, uint64_t P,
uint64_t S, int64_t A) {
uint64_t result = page(S + A) - page(P);
- result >>= 12;
+ if (!isInt<32>(result))
+ return make_out_of_range_reloc_error();
+ result = (result >> 12) & 0x3FFFF;
uint32_t immlo = result & 0x3;
uint32_t immhi = result & 0x1FFFFC;
immlo = immlo << 29;
@@ -279,20 +281,23 @@ static void relocR_AARCH64_ADR_GOT_PAGE(
llvm::dbgs() << " immlo: " << Twine::utohexstr(immlo);
llvm::dbgs() << " result: " << Twine::utohexstr(result) << "\n");
write32le(location, immlo | immhi | read32le(location));
+ return std::error_code();
}
// R_AARCH64_LD64_GOT_LO12_NC
-static void relocR_AARCH64_LD64_GOT_LO12_NC(uint8_t *location, uint64_t P,
+static std::error_code relocR_AARCH64_LD64_GOT_LO12_NC(uint8_t *location, uint64_t P,
uint64_t S, int64_t A) {
int32_t result = S + A;
- DEBUG(llvm::dbgs() << "\t\tHandle " << LLVM_FUNCTION_NAME << " -";
- llvm::dbgs() << " S: " << Twine::utohexstr(S);
+ DEBUG(llvm::dbgs() << " S: " << Twine::utohexstr(S);
llvm::dbgs() << " A: " << Twine::utohexstr(A);
llvm::dbgs() << " P: " << Twine::utohexstr(P);
llvm::dbgs() << " result: " << Twine::utohexstr(result) << "\n");
+ if ((result & 0x7) != 0)
+ return make_unaligned_range_reloc_error();
result &= 0xFF8;
result <<= 7;
write32le(location, result | read32le(location));
+ return std::error_code();
}
// ADD_AARCH64_GOTRELINDEX
@@ -424,11 +429,9 @@ std::error_code AArch64TargetRelocationH
relocR_AARCH64_CONDBR19(loc, reloc, target, addend);
break;
case R_AARCH64_ADR_GOT_PAGE:
- relocR_AARCH64_ADR_GOT_PAGE(loc, reloc, target, addend);
- break;
+ return relocR_AARCH64_ADR_GOT_PAGE(loc, reloc, target, addend);
case R_AARCH64_LD64_GOT_LO12_NC:
- relocR_AARCH64_LD64_GOT_LO12_NC(loc, reloc, target, addend);
- break;
+ return relocR_AARCH64_LD64_GOT_LO12_NC(loc, reloc, target, addend);
case R_AARCH64_LDST8_ABS_LO12_NC:
relocR_AARCH64_LDST8_ABS_LO12_NC(loc, reloc, target, addend);
break;
Modified: lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h?rev=234746&r1=234745&r2=234746&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h Mon Apr 13 07:08:21 2015
@@ -25,6 +25,10 @@ inline std::error_code make_out_of_range
return make_dynamic_error_code(Twine("Relocation out of range"));
}
+inline std::error_code make_unaligned_range_reloc_error() {
+ return make_dynamic_error_code(Twine("Relocation not aligned"));
+}
+
} // end namespace elf
} // end namespace lld
More information about the llvm-commits
mailing list