[PATCH] [PATCH 10/13] ELF/AARCH64: Add overflow check for R_AARCH64_CALL26 and R_AARCH64_JUMP26
Adhemerval Zanella
adhemerval.zanella at linaro.org
Tue Mar 31 10:56:40 PDT 2015
Add support for overflow checking when processing
R_AARCH64_CALL26 and R_AARCH64_JUMP26.
http://reviews.llvm.org/D8736
Files:
lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
test/elf/AArch64/rel-adr_prel_lo21-overflow.test
Index: lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
===================================================================
--- lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
+++ lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
@@ -155,16 +155,21 @@
write32le(location, result | read32le(location));
}
-static void relocJump26(uint8_t *location, uint64_t P, uint64_t S, int64_t A) {
+/// \brief R_AARCH64_CALL26 and R_AARCH64_JUMP26
+static std::error_code relocJump26(uint8_t *location, uint64_t P, uint64_t S,
+ int64_t A) {
int32_t result = (int32_t)((S + A) - P);
+ if (!isInt<27>(result))
+ return make_out_of_range_reloc_error();
result &= 0x0FFFFFFC;
result >>= 2;
DEBUG(llvm::dbgs() << "\t\tHandle " << LLVM_FUNCTION_NAME << " -";
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");
write32le(location, result | read32le(location));
+ return std::error_code();
}
/// \brief R_AARCH64_CONDBR19
@@ -419,8 +424,7 @@
break;
case R_AARCH64_CALL26:
case R_AARCH64_JUMP26:
- relocJump26(location, relocVAddress, targetVAddress, ref.addend());
- break;
+ return relocJump26(location, relocVAddress, targetVAddress, ref.addend());
case R_AARCH64_CONDBR19:
relocR_AARCH64_CONDBR19(location, relocVAddress, targetVAddress,
ref.addend());
Index: test/elf/AArch64/rel-adr_prel_lo21-overflow.test
===================================================================
--- test/elf/AArch64/rel-adr_prel_lo21-overflow.test
+++ test/elf/AArch64/rel-adr_prel_lo21-overflow.test
@@ -2,7 +2,7 @@
# RUN: yaml2obj -format=elf %s > %t-obj
# RUN: not lld -flavor gnu -target arm64 -o %t-exe %t-obj
-# CHECK: Relocation out of range in file {{.*}}: reference from _start+0 to data1+1048577 of type 274 (R_AARCH64_ADR_PREL_LO21)
+# CHECK: Relocation out of range in file {{.*}}: reference from _start+0 to data1+1048577 of type 274 (R_AARCH64_ADR_PREL_LO21)
!ELF
FileHeader: !FileHeader
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8736.22982.patch
Type: text/x-patch
Size: 2216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150331/77f97ebe/attachment.bin>
More information about the llvm-commits
mailing list