[llvm] [llvm-profgen] Set FirstLoadableAddress only once (PR #151257)

Wei Wang via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 29 16:52:43 PDT 2025


https://github.com/apolloww created https://github.com/llvm/llvm-project/pull/151257

The address of the first loadable segment can be zero, so `FirstLoadableAddress` may actually point to the second loadable segment. Use an optional instead. 

>From 740d1a52b63fddce318ac848c67c12940948a774 Mon Sep 17 00:00:00 2001
From: Wei Wang <wangwei at meta.com>
Date: Tue, 29 Jul 2025 14:00:42 -0700
Subject: [PATCH] [llvm-profgen] Set FirstLoadableAddress only once

---
 llvm/tools/llvm-profgen/ProfiledBinary.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h
index 0588cb48b2af6..8bc7e7b3b0061 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.h
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.h
@@ -199,7 +199,7 @@ class ProfiledBinary {
   // The runtime base address that the first executable segment is loaded at.
   uint64_t BaseAddress = 0;
   // The runtime base address that the first loadabe segment is loaded at.
-  uint64_t FirstLoadableAddress = 0;
+  std::optional<uint64_t> FirstLoadableAddress;
   // The preferred load address of each executable segment.
   std::vector<uint64_t> PreferredTextSegmentAddresses;
   // The file offset of each executable segment.
@@ -381,7 +381,10 @@ class ProfiledBinary {
     return PreferredTextSegmentAddresses[0];
   }
   // Return the preferred load address for the first loadable segment.
-  uint64_t getFirstLoadableAddress() const { return FirstLoadableAddress; }
+  uint64_t getFirstLoadableAddress() const {
+    assert(FirstLoadableAddress && "FirstLoadableAddress must be set.");
+    return *FirstLoadableAddress;
+  }
   // Return the file offset for the first executable segment.
   uint64_t getTextSegmentOffset() const { return TextSegmentOffsets[0]; }
   const std::vector<uint64_t> &getPreferredTextSegmentAddresses() const {



More information about the llvm-commits mailing list