[llvm-readobj] Fix std::abs overflow after D156821
authorFangrui Song <i@maskray.me>
Fri, 18 Aug 2023 20:21:36 +0000 (13:21 -0700)
committerTobias Hieta <tobias@hieta.se>
Mon, 21 Aug 2023 08:05:59 +0000 (10:05 +0200)
Tested by llvm/test/tools/llvm-readobj/ELF/relocations.test

(cherry picked from commit 07bb66784c17ef6b98ce38f9cc74d1d92f1aac08)

llvm/tools/llvm-readobj/ELFDumper.cpp

index aa92482..bc8e041 100644 (file)
@@ -3775,7 +3775,7 @@ void GNUELFDumper<ELFT>::printRelRelaReloc(const Relocation<ELFT> &R,
     if (!Fields[4].Str.empty()) {
       if (RelAddend < 0) {
         Addend = " - ";
-        RelAddend = std::abs(RelAddend);
+        RelAddend = -static_cast<uint64_t>(RelAddend);
       } else {
         Addend = " + ";
       }