[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 09:18:54 PST 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL253884: [ELF/AArch64] Factor out overflow checks into a separate function. NFC. (authored by ikudrin).

Changed prior to commit:
  http://reviews.llvm.org/D14922?vs=40919&id=40936#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14922

Files:
  lld/trunk/ELF/Target.cpp

Index: lld/trunk/ELF/Target.cpp
===================================================================
--- lld/trunk/ELF/Target.cpp
+++ lld/trunk/ELF/Target.cpp
@@ -691,18 +691,23 @@
   return Expr & (~static_cast<uint64_t>(0xFFF));
 }
 
+template <unsigned N>
+static void checkAArch64OutOfRange(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");
+    checkAArch64OutOfRange<16>(SA, Type);
     write16le(Loc, SA);
     break;
   case R_AARCH64_ABS32:
-    if (!isInt<32>(SA))
-      error("Relocation R_AARCH64_ABS32 out of range");
+    checkAArch64OutOfRange<32>(SA, Type);
     write32le(Loc, SA);
     break;
   case R_AARCH64_ABS64:
@@ -719,26 +724,20 @@
     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");
+    checkAArch64OutOfRange<21>(X, Type);
     updateAArch64Adr(Loc, X & 0x1FFFFF);
     break;
   }
   case R_AARCH64_ADR_PREL_PG_HI21: {
     uint64_t X = getAArch64Page(SA) - getAArch64Page(P);
-    if (!isInt<33>(X))
-      error("Relocation R_AARCH64_ADR_PREL_PG_HI21 out of range");
+    checkAArch64OutOfRange<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");
-    }
+    checkAArch64OutOfRange<28>(X, Type);
     or32le(Loc, (X & 0x0FFFFFFC) >> 2);
     break;
   }
@@ -755,13 +754,11 @@
     or32le(Loc, (SA & 0xFFF) << 10);
     break;
   case R_AARCH64_PREL16:
-    if (!isInt<16>(SA - P))
-      error("Relocation R_AARCH64_PREL16 out of range");
+    checkAArch64OutOfRange<16>(SA - P, Type);
     write16le(Loc, SA - P);
     break;
   case R_AARCH64_PREL32:
-    if (!isInt<32>(SA - P))
-      error("Relocation R_AARCH64_PREL32 out of range");
+    checkAArch64OutOfRange<32>(SA - P, Type);
     write32le(Loc, SA - P);
     break;
   case R_AARCH64_PREL64:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14922.40936.patch
Type: text/x-patch
Size: 2519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151123/d7d11c46/attachment.bin>


More information about the llvm-commits mailing list