[llvm] [BOLT] Determine address size from binary (PR #74870)

Nathan Sidwell via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 09:16:22 PST 2023


https://github.com/urnathan created https://github.com/llvm/llvm-project/pull/74870

Back on to bolt stuff.  I noticed a couple of hard-coded 8's, rather than query the executable.  I couldn't find an equivalent for the endianness check in parseBuildID, but fortunately my target is also little endian.

>From f0e3b3eb895d5301f945743cadb75054f1783815 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan at acm.org>
Date: Fri, 8 Dec 2023 12:13:31 -0500
Subject: [PATCH] [BOLT] Determine address size from binary

Don't hard code 64-bit address size.
---
 bolt/lib/Core/Exceptions.cpp         | 3 ++-
 bolt/lib/Rewrite/RewriteInstance.cpp | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/bolt/lib/Core/Exceptions.cpp b/bolt/lib/Core/Exceptions.cpp
index 993f3a7770aa81..ab1885f6bb5851 100644
--- a/bolt/lib/Core/Exceptions.cpp
+++ b/bolt/lib/Core/Exceptions.cpp
@@ -108,7 +108,8 @@ void BinaryFunction::parseLSDA(ArrayRef<uint8_t> LSDASectionData,
   DWARFDataExtractor Data(
       StringRef(reinterpret_cast<const char *>(LSDASectionData.data()),
                 LSDASectionData.size()),
-      BC.DwCtx->getDWARFObj().isLittleEndian(), 8);
+      BC.DwCtx->getDWARFObj().isLittleEndian(),
+      BC.DwCtx->getDWARFObj().getAddressSize());
   uint64_t Offset = getLSDAAddress() - LSDASectionAddress;
   assert(Data.isValidOffset(Offset) && "wrong LSDA address");
 
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 8cda0b7fcca9f8..2a8a8b2a16bc40 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -623,7 +623,9 @@ void RewriteInstance::parseBuildID() {
 
   // Reading notes section (see Portable Formats Specification, Version 1.1,
   // pg 2-5, section "Note Section").
-  DataExtractor DE = DataExtractor(Buf, true, 8);
+  DataExtractor DE = DataExtractor(Buf,
+                                   /*IsLittleEndian=*/true,
+                                   InputFile->getBytesInAddress());
   uint64_t Offset = 0;
   if (!DE.isValidOffset(Offset))
     return;



More information about the llvm-commits mailing list