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

Adhemerval Zanella adhemerval.zanella at linaro.org
Tue Mar 31 10:58:28 PDT 2015


http://reviews.llvm.org/D8738

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
@@ -313,10 +313,13 @@
 }
 
 // R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
-static void relocR_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21(uint8_t *location,
-                                                     uint64_t P, uint64_t S,
-                                                     int64_t A) {
+static std::error_code relocR_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21(uint8_t *location,
+                                                                uint64_t P,
+                                                                uint64_t S,
+                                                                int64_t A) {
   int64_t result = PAGE(S + A) - PAGE(P);
+  if (!isInt<32>(result))
+    return make_out_of_range_reloc_error();
   result >>= 12;
   uint32_t immlo = result & 0x3;
   uint32_t immhi = result & 0x1FFFFC;
@@ -330,6 +333,7 @@
         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_TLSIE_LD64_GOTTPREL_LO12_NC
@@ -462,9 +466,8 @@
                                  ref.addend());
     break;
   case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
-    relocR_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21(location, relocVAddress,
-                                             targetVAddress, ref.addend());
-    break;
+    return relocR_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21(location, relocVAddress,
+                                                    targetVAddress, ref.addend());
   case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
     relocR_AARCH64_TLSIE_LD64_GOTTPREL_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: D8738.22984.patch
Type: text/x-patch
Size: 2006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150331/5e299b65/attachment.bin>


More information about the llvm-commits mailing list