Skip to content

[JITLink] Include target addend in out-of-range error #145423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_16.s
Original file line number Diff line number Diff line change
Expand Up @@ -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",@progbits
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_32.s
Original file line number Diff line number Diff line change
Expand Up @@ -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",@progbits
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_8.s
Original file line number Diff line number Diff line change
Expand Up @@ -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",@progbits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down