[PATCH] D158310: [llvm-readobj] Avoid use of std::abs to fix ubsan failure.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 18 13:17:33 PDT 2023


craig.topper created this revision.
craig.topper added a reviewer: MaskRay.
Herald added a reviewer: jhenderson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a project: LLVM.

The input here can be INT64_MIN. We already know the number is
negative on the path that used std::abs. Cast to uint64_t and
negate that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158310

Files:
  llvm/tools/llvm-readobj/ELFDumper.cpp


Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -3775,7 +3775,7 @@
     if (!Fields[4].Str.empty()) {
       if (RelAddend < 0) {
         Addend = " - ";
-        RelAddend = std::abs(RelAddend);
+        RelAddend = -(uint64_t)RelAddend;
       } else {
         Addend = " + ";
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158310.551621.patch
Type: text/x-patch
Size: 442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230818/f240f243/attachment.bin>


More information about the llvm-commits mailing list