git: bf61c2737559 - stable/15 - Merge commit cbf48349e3e1 from llvm-project (by Jessica Clarke):

Jessica Clarke <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a74cc6d.32726.18607b62__29653.676068277$1786039455$gmane$org@gitrepo.freebsd.org>
The branch stable/15 has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=bf61c2737559aad0f00c7e7a2e7c75b0c472979c

commit bf61c2737559aad0f00c7e7a2e7c75b0c472979c
Author:     Jessica Clarke <[email protected]>
AuthorDate: 2026-07-27 16:53:53 +0000
Commit:     Jessica Clarke <[email protected]>
CommitDate: 2026-08-06 18:02:04 +0000

    Merge commit cbf48349e3e1 from llvm-project (by Jessica Clarke):
    
      [NFC][ELF][PPC64] Pass address not offset to writePPC64LoadAndBranch (#212275)
    
      Every caller currently subtracts the TOC base in its argument, so move
      that into common code inside writePPC64LoadAndBranch. This will also
      allow a different computation to be used in some cases in a future
      commit.
    
      Note that offset is now unsigned not signed; even previously, all
      arguments were uint64_t, and all uses are unsigned, so making it signed
      doesn't make much sense.
    
    MFC after:      1 week
    
    (cherry picked from commit bcbcd7303009344dc1051e4601284620bca29be8)
---
 contrib/llvm-project/lld/ELF/Arch/PPC64.cpp |  3 +--
 contrib/llvm-project/lld/ELF/Thunks.cpp     | 20 +++++++++-----------
 contrib/llvm-project/lld/ELF/Thunks.h       |  2 +-
 3 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/contrib/llvm-project/lld/ELF/Arch/PPC64.cpp b/contrib/llvm-project/lld/ELF/Arch/PPC64.cpp
index 3cd4a6294e2a..8e85cfab8a63 100644
--- a/contrib/llvm-project/lld/ELF/Arch/PPC64.cpp
+++ b/contrib/llvm-project/lld/ELF/Arch/PPC64.cpp
@@ -1168,8 +1168,7 @@ void PPC64::writePlt(uint8_t *buf, const Symbol &sym,
 
 void PPC64::writeIplt(uint8_t *buf, const Symbol &sym,
                       uint64_t /*pltEntryAddr*/) const {
-  writePPC64LoadAndBranch(ctx, buf,
-                          sym.getGotPltVA(ctx) - getPPC64TocBase(ctx));
+  writePPC64LoadAndBranch(ctx, buf, sym.getGotPltVA(ctx));
 }
 
 static std::pair<RelType, uint64_t> toAddr16Rel(RelType type, uint64_t val) {
diff --git a/contrib/llvm-project/lld/ELF/Thunks.cpp b/contrib/llvm-project/lld/ELF/Thunks.cpp
index 65d0f094c43c..45b9ab9530e0 100644
--- a/contrib/llvm-project/lld/ELF/Thunks.cpp
+++ b/contrib/llvm-project/lld/ELF/Thunks.cpp
@@ -1402,7 +1402,8 @@ void PPC32LongThunk::writeTo(uint8_t *buf) {
   write32(ctx, buf + 4, 0x4e800420); // bctr
 }
 
-void elf::writePPC64LoadAndBranch(Ctx &ctx, uint8_t *buf, int64_t offset) {
+void elf::writePPC64LoadAndBranch(Ctx &ctx, uint8_t *buf, uint64_t addr) {
+  uint64_t offset = addr - getPPC64TocBase(ctx);
   uint16_t offHa = (offset + 0x8000) >> 16;
   uint16_t offLo = offset & 0xffff;
 
@@ -1413,10 +1414,9 @@ void elf::writePPC64LoadAndBranch(Ctx &ctx, uint8_t *buf, int64_t offset) {
 }
 
 void PPC64PltCallStub::writeTo(uint8_t *buf) {
-  int64_t offset = destination.getGotPltVA(ctx) - getPPC64TocBase(ctx);
   // Save the TOC pointer to the save-slot reserved in the call frame.
   write32(ctx, buf + 0, 0xf8410018); // std     r2,24(r1)
-  writePPC64LoadAndBranch(ctx, buf + 4, offset);
+  writePPC64LoadAndBranch(ctx, buf + 4, destination.getGotPltVA(ctx));
 }
 
 void PPC64PltCallStub::addSymbols(ThunkSection &isec) {
@@ -1456,10 +1456,9 @@ void PPC64R2SaveStub::writeTo(uint8_t *buf) {
     write32(ctx, buf + nextInstOffset + 4, BCTR);  // bctr
   } else {
     ctx.in.ppc64LongBranchTarget->addEntry(&destination, addend);
-    const int64_t offsetFromTOC =
-        ctx.in.ppc64LongBranchTarget->getEntryVA(&destination, addend) -
-        getPPC64TocBase(ctx);
-    writePPC64LoadAndBranch(ctx, buf + 4, offsetFromTOC);
+    const uint64_t addr =
+        ctx.in.ppc64LongBranchTarget->getEntryVA(&destination, addend);
+    writePPC64LoadAndBranch(ctx, buf + 4, addr);
   }
 }
 
@@ -1519,10 +1518,9 @@ bool PPC64R12SetupStub::isCompatibleWith(const InputSection &isec,
 }
 
 void PPC64LongBranchThunk::writeTo(uint8_t *buf) {
-  int64_t offset =
-      ctx.in.ppc64LongBranchTarget->getEntryVA(&destination, addend) -
-      getPPC64TocBase(ctx);
-  writePPC64LoadAndBranch(ctx, buf, offset);
+  uint64_t addr =
+      ctx.in.ppc64LongBranchTarget->getEntryVA(&destination, addend);
+  writePPC64LoadAndBranch(ctx, buf, addr);
 }
 
 void PPC64LongBranchThunk::addSymbols(ThunkSection &isec) {
diff --git a/contrib/llvm-project/lld/ELF/Thunks.h b/contrib/llvm-project/lld/ELF/Thunks.h
index 446345b8517f..a802827ba407 100644
--- a/contrib/llvm-project/lld/ELF/Thunks.h
+++ b/contrib/llvm-project/lld/ELF/Thunks.h
@@ -85,7 +85,7 @@ std::unique_ptr<Thunk> addLandingPadThunk(Ctx &, Symbol &s, int64_t a);
 
 void writePPC32PltCallStub(Ctx &, uint8_t *buf, uint64_t gotPltVA,
                            const InputFile *file, int64_t addend);
-void writePPC64LoadAndBranch(Ctx &, uint8_t *buf, int64_t offset);
+void writePPC64LoadAndBranch(Ctx &, uint8_t *buf, uint64_t addr);
 
 } // namespace lld::elf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.