[lld] r247768 - [elf2] Simplify overflow checks.

Michael J. Spencer via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 19:02:04 PDT 2015


Author: mspencer
Date: Tue Sep 15 21:02:04 2015
New Revision: 247768

URL: http://llvm.org/viewvc/llvm-project?rev=247768&view=rev
Log:
[elf2] Simplify overflow checks.

Modified:
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/elf2/relocation-errors.s

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=247768&r1=247767&r2=247768&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Sep 15 21:02:04 2015
@@ -14,7 +14,6 @@
 #include "Symbols.h"
 #include "SymbolTable.h"
 
-#include "llvm/ADT/APInt.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/MC/StringTableBuilder.h"
@@ -502,18 +501,13 @@ template <class ELFT> void OutputSection
           break;
         case llvm::ELF::R_X86_64_32: {
         case llvm::ELF::R_X86_64_32S:
-          APInt VA(64, SymVA);
-          APInt Addend(64, RI.r_addend, true);
-          APInt Result64 = VA + Addend;
-          APInt Result = Result64.trunc(32);
-          if (Type == llvm::ELF::R_X86_64_32) {
-            if (Result.zext(64) != Result64)
-              error("Relocation out of range");
-          } else
-            if (Result.sext(64) != Result64)
-              error("R_X86_64_32S out of range");
+          uint64_t VA = SymVA + RI.r_addend;
+          if (Type == llvm::ELF::R_X86_64_32 && !isUInt<32>(VA))
+            error("R_X86_64_32 out of range");
+          else if (!isInt<32>(VA))
+            error("R_X86_64_32S out of range");
 
-          support::endian::write32le(Location, Result.getZExtValue());
+          support::endian::write32le(Location, VA);
           break;
         }
         default:

Modified: lld/trunk/test/elf2/relocation-errors.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/relocation-errors.s?rev=247768&r1=247767&r2=247768&view=diff
==============================================================================
--- lld/trunk/test/elf2/relocation-errors.s (original)
+++ lld/trunk/test/elf2/relocation-errors.s Tue Sep 15 21:02:04 2015
@@ -7,4 +7,4 @@
 _start:
   movl $big, %edx
 
-#CHECK: Relocation out of range
+#CHECK: R_X86_64_32 out of range




More information about the llvm-commits mailing list