[llvm] [JITLink] Include target addend in out-of-range error (PR #145423)
Maksim Panchenko via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 23 21:57:13 PDT 2025
https://github.com/maksfb updated https://github.com/llvm/llvm-project/pull/145423
>From 1417046d2d2b168e55b20d9691db60340976048c Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Mon, 23 Jun 2025 15:25:55 -0700
Subject: [PATCH 1/4] [JITLink] Include target addend in out-of-range error
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.
---
llvm/lib/ExecutionEngine/JITLink/JITLink.cpp | 6 ++++--
.../test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
index 355f44d589a2d..4f0fa725398d8 100644
--- a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
@@ -427,8 +427,10 @@ Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B,
} 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())
+ ErrStream << " at address " << formatv("{0:x}", E.getTarget().getAddress());
+ if (E.getAddend())
+ ErrStream << " with addend " << formatv("{0:x}", E.getAddend());
+ ErrStream << " is out of range of " << G.getEdgeKindName(E.getKind())
<< " fixup at " << formatv("{0:x}", B.getFixupAddress(E)) << " (";
Symbol *BestSymbolForBlock = nullptr;
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..dea87e75d8ad9 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" at address {{.*}} with addend {{.*}} is out of range of Size32 fixup at {{.*}} (main, {{.*}})
.text
.globl main
>From 5d32fee1bcdc0eea67e9430a7a0b147934088628 Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Mon, 23 Jun 2025 20:35:46 -0700
Subject: [PATCH 2/4] Address suggestion
---
llvm/lib/ExecutionEngine/JITLink/JITLink.cpp | 26 +++++++++++--------
.../JITLink/AArch64/ELF_R_AARCH64_ABS32.yaml | 2 +-
.../JITLink/x86-64/ELF_R_X86_64_16.s | 2 +-
.../JITLink/x86-64/ELF_R_X86_64_32.s | 2 +-
.../JITLink/x86-64/ELF_R_X86_64_8.s | 2 +-
.../JITLink/x86-64/ELF_R_X86_64_SIZE.s | 2 +-
6 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
index 4f0fa725398d8..23b72daedacaa 100644
--- a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
@@ -421,17 +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());
- if (E.getAddend())
- ErrStream << " with addend " << formatv("{0:x}", E.getAddend());
- ErrStream << " 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 dea87e75d8ad9..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 {{.*}} with addend {{.*}} 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
>From b03845c1e19cd6374909352b04217914a4757bed Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Mon, 23 Jun 2025 20:44:46 -0700
Subject: [PATCH 3/4] Include "<addend>:" in the message
---
llvm/lib/ExecutionEngine/JITLink/JITLink.cpp | 4 ++--
llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
index 23b72daedacaa..785df86ab4391 100644
--- a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
@@ -430,8 +430,8 @@ Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B,
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 << formatv(":{0:x}", E.getTarget().getAddress())
+ << formatv(" + <addend>:{0:x}", E.getAddend());
}
ErrStream << ") is out of range of " << G.getEdgeKindName(E.getKind())
<< " fixup at address "
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 afc2015f6c555..3661ff5a6e9ff 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:{{.*}} + {{.*}}) is out of range of Size32 fixup at address {{.*}} (main, {{.*}})
+# CHECK: llvm-jitlink error: In graph {{.*}}, section .text: relocation target {{.*}} (main:{{.*}} + <addend>:{{.*}}) is out of range of Size32 fixup at address {{.*}} (main, {{.*}})
.text
.globl main
>From d5379814d4688300bdf308bc2b585547d451b391 Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Mon, 23 Jun 2025 21:56:49 -0700
Subject: [PATCH 4/4] Revert "Include "<addend>:" in the message"
This reverts commit b03845c1e19cd6374909352b04217914a4757bed.
---
llvm/lib/ExecutionEngine/JITLink/JITLink.cpp | 4 ++--
llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
index 785df86ab4391..23b72daedacaa 100644
--- a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
@@ -430,8 +430,8 @@ Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B,
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(" + <addend>:{0:x}", E.getAddend());
+ 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 "
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 3661ff5a6e9ff..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:{{.*}} + <addend>:{{.*}}) is out of range of Size32 fixup at address {{.*}} (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