[PATCH] D14922: [ELF/AArch64] Factor out overflow check into a separate function.
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 23 05:58:58 PST 2015
ikudrin created this revision.
ikudrin added reviewers: ruiu, davide.
ikudrin added a subscriber: llvm-commits.
ikudrin added a project: lld.
Herald added subscribers: rengolin, aemerson.
This patch mainly extracts overflow checks for AArch64 relocations into a separate function.
In addition, it corrects checks for R_AARCH64_PREL16 and R_AARCH64_PREL32 relocations.
http://reviews.llvm.org/D14922
Files:
ELF/Target.cpp
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -703,18 +703,22 @@
return Expr & (~static_cast<uint64_t>(0xFFF));
}
+template <unsigned N> static void checkOutOfRange(int64_t X, uint32_t Type) {
+ if (!isInt<N>(X))
+ error("Relocation " + getELFRelocationTypeName(EM_AARCH64, Type) +
+ " out of range");
+}
+
void AArch64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd,
uint32_t Type, uint64_t P,
uint64_t SA) const {
switch (Type) {
case R_AARCH64_ABS16:
- if (!isInt<16>(SA))
- error("Relocation R_AARCH64_ABS16 out of range");
+ checkOutOfRange<16>(SA, Type);
write16le(Loc, SA);
break;
case R_AARCH64_ABS32:
- if (!isInt<32>(SA))
- error("Relocation R_AARCH64_ABS32 out of range");
+ checkOutOfRange<32>(SA, Type);
write32le(Loc, SA);
break;
case R_AARCH64_ABS64:
@@ -731,30 +735,21 @@
break;
case R_AARCH64_ADR_PREL_LO21: {
uint64_t X = SA - P;
- if (!isInt<21>(X))
- error("Relocation R_AARCH64_ADR_PREL_LO21 out of range");
+ checkOutOfRange<21>(X, Type);
updateAArch64Adr(Loc, X & 0x1FFFFF);
break;
}
case R_AARCH64_ADR_GOT_PAGE:
case R_AARCH64_ADR_PREL_PG_HI21: {
uint64_t X = getAArch64Page(SA) - getAArch64Page(P);
- if (!isInt<33>(X)) {
- if (Type == R_AARCH64_ADR_GOT_PAGE)
- error("Relocation R_AARCH64_ADR_GOT_PAGE out of range");
- error("Relocation R_AARCH64_ADR_PREL_PG_HI21 out of range");
- }
+ checkOutOfRange<33>(X, Type);
updateAArch64Adr(Loc, (X >> 12) & 0x1FFFFF); // X[32:12]
break;
}
case R_AARCH64_JUMP26:
case R_AARCH64_CALL26: {
uint64_t X = SA - P;
- if (!isInt<28>(X)) {
- if (Type == R_AARCH64_JUMP26)
- error("Relocation R_AARCH64_JUMP26 out of range");
- error("Relocation R_AARCH64_CALL26 out of range");
- }
+ checkOutOfRange<28>(X, Type);
or32le(Loc, (X & 0x0FFFFFFC) >> 2);
break;
}
@@ -777,13 +772,11 @@
or32le(Loc, (SA & 0xFFF) << 10);
break;
case R_AARCH64_PREL16:
- if (!isInt<16>(SA))
- error("Relocation R_AARCH64_PREL16 out of range");
+ checkOutOfRange<16>(SA - P, Type);
write16le(Loc, SA - P);
break;
case R_AARCH64_PREL32:
- if (!isInt<32>(SA))
- error("Relocation R_AARCH64_PREL32 out of range");
+ checkOutOfRange<32>(SA - P, Type);
write32le(Loc, SA - P);
break;
case R_AARCH64_PREL64:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14922.40919.patch
Type: text/x-patch
Size: 2574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151123/85715f64/attachment.bin>
More information about the llvm-commits
mailing list