[llvm] 0c33799 - [JITLink] Include target addend in out-of-range error (#145423)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 23 22:46:18 PDT 2025


Author: Maksim Panchenko
Date: 2025-06-23T22:46:15-07:00
New Revision: 0c33799e374a2f67ff7fefe624043254d4082534

URL: https://github.com/llvm/llvm-project/commit/0c33799e374a2f67ff7fefe624043254d4082534
DIFF: https://github.com/llvm/llvm-project/commit/0c33799e374a2f67ff7fefe624043254d4082534.diff

LOG: [JITLink] Include target addend in out-of-range error (#145423)

When JITLink reports an out-of-range error, the underlying reason could
be hidden from the user if it's due to an excessively large target
addend. Add non-zero target addend to the message for clarity.

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
    llvm/test/ExecutionEngine/JITLink/AArch64/ELF_R_AARCH64_ABS32.yaml
    llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_16.s
    llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_32.s
    llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_8.s
    llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
index 355f44d589a2d..23b72daedacaa 100644
--- a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
@@ -421,15 +421,21 @@ Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B,
     raw_string_ostream ErrStream(ErrMsg);
     Section &Sec = B.getSection();
     ErrStream << "In graph " << G.getName() << ", section " << Sec.getName()
-              << ": relocation target ";
-    if (E.getTarget().hasName()) {
-      ErrStream << "\"" << E.getTarget().getName() << "\"";
-    } else
-      ErrStream << E.getTarget().getSection().getName() << " + "
-                << formatv("{0:x}", E.getOffset());
-    ErrStream << " at address " << formatv("{0:x}", E.getTarget().getAddress())
-              << " is out of range of " << G.getEdgeKindName(E.getKind())
-              << " fixup at " << formatv("{0:x}", B.getFixupAddress(E)) << " (";
+              << ": relocation target "
+              << formatv("{0:x}", E.getTarget().getAddress() + E.getAddend())
+              << " (";
+    if (E.getTarget().hasName())
+      ErrStream << E.getTarget().getName();
+    else
+      ErrStream << "<anonymous symbol>";
+    if (E.getAddend()) {
+      // Target address includes non-zero added, so break down the arithmetic.
+      ErrStream << formatv(":{0:x}", E.getTarget().getAddress()) << " + "
+                << formatv("{0:x}", E.getAddend());
+    }
+    ErrStream << ") is out of range of " << G.getEdgeKindName(E.getKind())
+              << " fixup at address "
+              << formatv("{0:x}", E.getTarget().getAddress()) << " (";
 
     Symbol *BestSymbolForBlock = nullptr;
     for (auto *Sym : Sec.symbols())

diff  --git a/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_R_AARCH64_ABS32.yaml b/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_R_AARCH64_ABS32.yaml
index ca992adbba819..efceb7da6d42d 100644
--- a/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_R_AARCH64_ABS32.yaml
+++ b/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_R_AARCH64_ABS32.yaml
@@ -11,7 +11,7 @@
 
 # jitlink-check: *{8}xptr = x
 
-# CHECK-ERROR: relocation target "x" {{.*}} is out of range of Pointer32 fixup
+# CHECK-ERROR: relocation target {{.*}} (x) is out of range of Pointer32 fixup
 
 --- !ELF
 FileHeader:

diff  --git a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_16.s b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_16.s
index eff9ebbff2a04..f93aa4f676d1b 100644
--- a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_16.s
+++ b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_16.s
@@ -8,7 +8,7 @@
 
 # jitlink-check: *{8}P = X
 
-# CHECK-ERROR: relocation target "X" {{.*}} is out of range of Pointer16 fixup
+# CHECK-ERROR: relocation target {{.*}} (X) is out of range of Pointer16 fixup
 
 	.text
 	.section	.text.main,"ax", at progbits

diff  --git a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_32.s b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_32.s
index 696d17a3d19b2..7e6a4047c7644 100644
--- a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_32.s
+++ b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_32.s
@@ -8,7 +8,7 @@
 
 # jitlink-check: *{8}P = X
 
-# CHECK-ERROR: relocation target "X" {{.*}} is out of range of Pointer32 fixup
+# CHECK-ERROR: relocation target {{.*}} (X) is out of range of Pointer32 fixup
 
 	.text
 	.section	.text.main,"ax", at progbits

diff  --git a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_8.s b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_8.s
index d5337682f809b..5f4954e13264e 100644
--- a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_8.s
+++ b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_8.s
@@ -8,7 +8,7 @@
 
 # jitlink-check: *{8}P = X
 
-# CHECK-ERROR: relocation target "X" {{.*}} is out of range of Pointer8 fixup
+# CHECK-ERROR: relocation target {{.*}} (X) is out of range of Pointer8 fixup
 
 	.text
 	.section	.text.main,"ax", at progbits

diff  --git a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s
index abde122f76e23..afc2015f6c555 100644
--- a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s
+++ b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s
@@ -7,7 +7,7 @@
 # RUN: llvm-mc -triple=x86_64-unknown-linux -position-independent --defsym=OVERFLOW=1 \
 # RUN:     -filetype=obj -o %t.2.o %s
 # RUN: not llvm-jitlink -noexec %t.2.o 2>&1 | FileCheck %s
-# CHECK: llvm-jitlink error: In graph {{.*}}, section .text: relocation target "main" at address {{.*}} is out of range of Size32 fixup at {{.*}} (main, {{.*}})
+# CHECK: llvm-jitlink error: In graph {{.*}}, section .text: relocation target {{.*}} (main:{{.*}} + {{.*}}) is out of range of Size32 fixup at address {{.*}} (main, {{.*}})
 
 	.text
 	.globl	main


        


More information about the llvm-commits mailing list