From c6dbf778f13a5c70613ca6e165a09cd610b3436d Mon Sep 17 00:00:00 2001 From: quic-areg Date: Wed, 26 Nov 2025 15:55:43 -0800 Subject: [PATCH 1/2] Move PAddr from ELFSection to OutputSectionEntry Signed-off-by: quic-areg --- include/eld/Object/OutputSectionEntry.h | 4 ++++ include/eld/Readers/ELFSection.h | 13 +++++-------- lib/Readers/ELFSection.cpp | 15 ++++++++++++++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/eld/Object/OutputSectionEntry.h b/include/eld/Object/OutputSectionEntry.h index ba4f485b6..6844123dc 100644 --- a/include/eld/Object/OutputSectionEntry.h +++ b/include/eld/Object/OutputSectionEntry.h @@ -154,6 +154,9 @@ class OutputSectionEntry { std::string getSectionTypeStr() const; + uint64_t pAddr() const { return PAddr; } + void setPaddr(uint64_t A) { PAddr = A; } + // ----------------------Reuse trampolines optimization--------------- std::vector getBranchIslandsForSymbol(ResolveInfo *PSym) const { @@ -219,6 +222,7 @@ class OutputSectionEntry { llvm::SmallVector AllStrings; uint64_t Hash = 0; llvm::StringMap TrampolineNameToCountMap; + uint64_t PAddr = 0; }; } // namespace eld diff --git a/include/eld/Readers/ELFSection.h b/include/eld/Readers/ELFSection.h index a3fbdbdb2..2690d887c 100644 --- a/include/eld/Readers/ELFSection.h +++ b/include/eld/Readers/ELFSection.h @@ -127,8 +127,7 @@ class ELFSection : public ELFSectionBase { ELFSectionBase *Link, uint32_t SectionSize, uint64_t PAddr) : ELFSectionBase(Section::ELF, ELFSectionKind, Name, Flags, EntSize, - AddrAlign, Type, Info, Link, SectionSize), - PAddr(PAddr) {} + AddrAlign, Type, Info, Link, SectionSize) {} explicit ELFSection(Section::Kind SectionKind, LDFileFormat::Kind ELFSectionKind, @@ -137,8 +136,7 @@ class ELFSection : public ELFSectionBase { ELFSectionBase *Link, uint32_t SectionSize, uint64_t PAddr) : ELFSectionBase(SectionKind, ELFSectionKind, Name, Flags, EntSize, - AddrAlign, Type, Info, Link, SectionSize), - PAddr(PAddr) {} + AddrAlign, Type, Info, Link, SectionSize) {} static bool classof(const Section *S) { return S->isELF(); } @@ -177,7 +175,7 @@ class ELFSection : public ELFSectionBase { bool hasVMA() const { return Addr != InvalidAddr; } - uint64_t pAddr() const { return PAddr; } + uint64_t pAddr() const; void setOffsetAndAddr(uint64_t Off); @@ -195,7 +193,7 @@ class ELFSection : public ELFSectionBase { return !isDiscard() && !isIgnore() && WantedInOutput; } - void setPaddr(size_t A) { PAddr = A; } + void setPaddr(size_t A); void setSymbol(LDSymbol *S) { Symbol = S; } @@ -300,8 +298,7 @@ class ELFSection : public ELFSectionBase { /// FIXME: This has different meanings for Input/Output sections. uint64_t Offset = ~uint64_t(0); uint64_t Addr = InvalidAddr; - /// FIXME: only relevant for output sections. - uint64_t PAddr; + LDSymbol *Symbol = nullptr; /// FIXME: Only relevant for LTO. This should be moved out. diff --git a/lib/Readers/ELFSection.cpp b/lib/Readers/ELFSection.cpp index a6f3ecc95..1537836f7 100644 --- a/lib/Readers/ELFSection.cpp +++ b/lib/Readers/ELFSection.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "eld/Readers/ELFSection.h" +#include "eld/Object/OutputSectionEntry.h" #include "llvm/ADT/StringRef.h" using namespace eld; @@ -160,13 +161,25 @@ Fragment *ELFSection::getFirstFragmentInRule() const { return nullptr; } +uint64_t ELFSection::pAddr() const { + OutputSectionEntry *OE = getOutputSection(); + if (!OE) + return 0; + return OE->pAddr(); +} + +void ELFSection::setPaddr(size_t A) { + OutputSectionEntry *OE = getOutputSection(); + ASSERT(OE, "expected putput section"); + OE->setPaddr(A); +} + void ELFSection::setOffsetAndAddr(uint64_t Off) { Offset = Off; OutputSectionEntry *OE = getOutputSection(); if (!OE) return; Addr = Offset + OE->getSection()->addr(); - PAddr = Offset + OE->getSection()->pAddr(); } std::string ELFSection::getDecoratedName(const GeneralOptions &options) const { From b52697ebdb76e2bbd2f46255f6bf292cfce94dbc Mon Sep 17 00:00:00 2001 From: quic-areg Date: Thu, 8 Jan 2026 11:37:29 -0600 Subject: [PATCH 2/2] Update lib/Readers/ELFSection.cpp Co-authored-by: Parth Arora Signed-off-by: quic-areg --- lib/Readers/ELFSection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Readers/ELFSection.cpp b/lib/Readers/ELFSection.cpp index 1537836f7..17af8b255 100644 --- a/lib/Readers/ELFSection.cpp +++ b/lib/Readers/ELFSection.cpp @@ -170,7 +170,7 @@ uint64_t ELFSection::pAddr() const { void ELFSection::setPaddr(size_t A) { OutputSectionEntry *OE = getOutputSection(); - ASSERT(OE, "expected putput section"); + ASSERT(OE, "expected output section"); OE->setPaddr(A); }