[llvm-branch-commits] [lld] release/21.x: [ELF][Hexagon] Fix host endianness assumption (PR #151886)

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 5 01:56:20 PDT 2025


https://github.com/tru updated https://github.com/llvm/llvm-project/pull/151886

>From 489d36cedc71b13b04a579c52ba58924bc6bafb6 Mon Sep 17 00:00:00 2001
From: Jessica Clarke <jrtc27 at jrtc27.com>
Date: Sun, 3 Aug 2025 21:22:08 +0100
Subject: [PATCH 1/3] [NFC][ELF] Add missing blank line between functions

Fixes: b42f96bc057f ("[lld] Add thunks for hexagon (#111217)")
(cherry picked from commit b03d1e1e2e8e4b0b4b9e035b7ad9fb86dccefb93)
---
 lld/ELF/Relocations.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 2ee308a2d1b3c..b6c676e294e44 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -2162,6 +2162,7 @@ static int getHexagonPacketOffset(const InputSection &isec,
       return i * 4;
   }
 }
+
 static int64_t getPCBias(Ctx &ctx, const InputSection &isec,
                          const Relocation &rel) {
   if (ctx.arg.emachine == EM_ARM) {

>From 74a0c1e962c04a500f79d2d02b8cdf6c170c2937 Mon Sep 17 00:00:00 2001
From: Jessica Clarke <jrtc27 at jrtc27.com>
Date: Sun, 3 Aug 2025 21:24:10 +0100
Subject: [PATCH 2/3] [NFC][ELF][Hexagon] Avoid pointless ArrayRef::drop_front

Fixes: b42f96bc057f ("[lld] Add thunks for hexagon (#111217)")
(cherry picked from commit de15d365743e16848a9d15fc32ae6ab98d399ec2)
---
 lld/ELF/Relocations.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index b6c676e294e44..9549cc6f56326 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -2154,9 +2154,8 @@ static int getHexagonPacketOffset(const InputSection &isec,
     if (i == 3 || rel.offset < (i + 1) * 4)
       return i * 4;
     uint32_t instWord = 0;
-    const ArrayRef<uint8_t> instWordContents =
-        data.drop_front(rel.offset - (i + 1) * 4);
-    memcpy(&instWord, instWordContents.data(), sizeof(instWord));
+    memcpy(&instWord, data.data() + (rel.offset - (i + 1) * 4),
+           sizeof(instWord));
     if (((instWord & HEXAGON_MASK_END_PACKET) == HEXAGON_END_OF_PACKET) ||
         ((instWord & HEXAGON_MASK_END_PACKET) == HEXAGON_END_OF_DUPLEX))
       return i * 4;

>From f5ad8dc6876ab667d07fe6c3bd2ac2bad434f6fb Mon Sep 17 00:00:00 2001
From: Jessica Clarke <jrtc27 at jrtc27.com>
Date: Sun, 3 Aug 2025 21:28:48 +0100
Subject: [PATCH 3/3] [ELF][Hexagon] Fix host endianness assumption

Fixes: b42f96bc057f ("[lld] Add thunks for hexagon (#111217)")
(cherry picked from commit 723b40a8d92f76fc913ef21061fc3d74e8c47441)
---
 lld/ELF/Relocations.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 9549cc6f56326..608cdd0d26660 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -2153,9 +2153,8 @@ static int getHexagonPacketOffset(const InputSection &isec,
   for (unsigned i = 0;; i++) {
     if (i == 3 || rel.offset < (i + 1) * 4)
       return i * 4;
-    uint32_t instWord = 0;
-    memcpy(&instWord, data.data() + (rel.offset - (i + 1) * 4),
-           sizeof(instWord));
+    uint32_t instWord =
+        read32(isec.getCtx(), data.data() + (rel.offset - (i + 1) * 4));
     if (((instWord & HEXAGON_MASK_END_PACKET) == HEXAGON_END_OF_PACKET) ||
         ((instWord & HEXAGON_MASK_END_PACKET) == HEXAGON_END_OF_DUPLEX))
       return i * 4;



More information about the llvm-branch-commits mailing list