[PATCH] [PATCH 13/13] ELF/AARCH64: Add overflow check for R_AARCH64_TLSLE_ADD_TPREL_HI12

Adhemerval Zanella adhemerval.zanella at linaro.org
Tue Mar 31 10:59:33 PDT 2015


http://reviews.llvm.org/D8739

Files:
  lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp

Index: lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
===================================================================
--- lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
+++ lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
@@ -352,17 +352,22 @@
 }
 
 /// \brief R_AARCH64_TLSLE_ADD_TPREL_HI12
-static void relocR_AARCH64_TLSLE_ADD_TPREL_HI12(uint8_t *location, uint64_t P,
-                                                uint64_t S, int64_t A) {
+static std::error_code relocR_AARCH64_TLSLE_ADD_TPREL_HI12(uint8_t *location,
+                                                           uint64_t P,
+                                                           uint64_t S,
+                                                           int64_t A) {
   int32_t result = S + A;
+  if (!isUInt<24>(result))
+    return make_out_of_range_reloc_error();
   result &= 0x0FFF000;
   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_TLSLE_ADD_TPREL_LO12_NC
@@ -473,9 +478,8 @@
                                                targetVAddress, ref.addend());
     break;
   case R_AARCH64_TLSLE_ADD_TPREL_HI12:
-    relocR_AARCH64_TLSLE_ADD_TPREL_HI12(location, relocVAddress, targetVAddress,
-                                        ref.addend());
-    break;
+    return relocR_AARCH64_TLSLE_ADD_TPREL_HI12(location, relocVAddress,
+                                               targetVAddress, ref.addend());
   case R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
     relocR_AARCH64_TLSLE_ADD_TPREL_LO12_NC(location, relocVAddress,
                                            targetVAddress, ref.addend());

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8739.22985.patch
Type: text/x-patch
Size: 2004 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150331/dd73fe0c/attachment.bin>


More information about the llvm-commits mailing list