[llvm] [Object][NFC] Normalize BBAddrMap decode address types in ELF (PR #187962)

via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 22 19:39:24 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-binary-utilities

Author: Haohai Wen (HaohaiWen)

<details>
<summary>Changes</summary>

This is part of patches to port BBAddrMap to COFF.

DataExtractor::getAddress reads 4 or 8 bytes according to AddressSize and
returns a uint64_t container value. This code path already sets AddressSize
from ELFT::Is64Bits and stores range/function addresses as uint64_t.

Replace temporary uintX_t/unsigned values in this decoder path with uint64_t
and remove the redundant cast from getAddress(). This preserves behavior for
ELF32/ELF64 inputs.

This is a preparatory step for extracting a format-agnostic BBAddrMap decoder.

---
Full diff: https://github.com/llvm/llvm-project/pull/187962.diff


1 Files Affected:

- (modified) llvm/lib/Object/ELF.cpp (+8-8) 


``````````diff
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index 35b5e0faf9007..660331d5da96d 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -784,7 +784,7 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
     }
   }
   auto GetAddressForRelocation =
-      [&](unsigned RelocationOffsetInSection) -> Expected<unsigned> {
+      [&](uint64_t RelocationOffsetInSection) -> Expected<uint64_t> {
     auto FOTIterator =
         FunctionOffsetTranslations.find(RelocationOffsetInSection);
     if (FOTIterator == FunctionOffsetTranslations.end()) {
@@ -819,24 +819,24 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
     Content = DecompressedContentRef;
   }
 
-  DataExtractor Data(Content, EF.isLE(), ELFT::Is64Bits ? 8 : 4);
+  DataExtractor Data(Content, EF.isLE(),
+                     sizeof(typename ELFFile<ELFT>::uintX_t));
   std::vector<BBAddrMap> FunctionEntries;
 
   DataExtractor::Cursor Cur(0);
   Error ULEBSizeErr = Error::success();
   Error MetadataDecodeErr = Error::success();
 
-  // Helper lampda to extract the (possiblly relocatable) address stored at Cur.
-  auto ExtractAddress = [&]() -> Expected<typename ELFFile<ELFT>::uintX_t> {
+  // Helper lambda to extract the (possibly relocatable) address stored at Cur.
+  auto ExtractAddress = [&]() -> Expected<uint64_t> {
     uint64_t RelocationOffsetInSection = Cur.tell();
-    auto Address =
-        static_cast<typename ELFFile<ELFT>::uintX_t>(Data.getAddress(Cur));
+    uint64_t Address = Data.getAddress(Cur);
     if (!Cur)
       return Cur.takeError();
     if (!IsRelocatable)
       return Address;
     assert(Address == 0);
-    Expected<unsigned> AddressOrErr =
+    Expected<uint64_t> AddressOrErr =
         GetAddressForRelocation(RelocationOffsetInSection);
     if (!AddressOrErr)
       return AddressOrErr.takeError();
@@ -878,7 +878,7 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
                          " feature = " + Twine(static_cast<int>(Feature)));
     uint32_t NumBlocksInBBRange = 0;
     uint32_t NumBBRanges = 1;
-    typename ELFFile<ELFT>::uintX_t RangeBaseAddress = 0;
+    uint64_t RangeBaseAddress = 0;
     if (FeatEnable.MultiBBRange) {
       NumBBRanges = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
       if (!Cur || ULEBSizeErr)

``````````

</details>


https://github.com/llvm/llvm-project/pull/187962


More information about the llvm-commits mailing list