Skip to content

Commit 0c33799

Browse files
authored
[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.
1 parent e435558 commit 0c33799

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed

llvm/lib/ExecutionEngine/JITLink/JITLink.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,21 @@ Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B,
421421
raw_string_ostream ErrStream(ErrMsg);
422422
Section &Sec = B.getSection();
423423
ErrStream << "In graph " << G.getName() << ", section " << Sec.getName()
424-
<< ": relocation target ";
425-
if (E.getTarget().hasName()) {
426-
ErrStream << "\"" << E.getTarget().getName() << "\"";
427-
} else
428-
ErrStream << E.getTarget().getSection().getName() << " + "
429-
<< formatv("{0:x}", E.getOffset());
430-
ErrStream << " at address " << formatv("{0:x}", E.getTarget().getAddress())
431-
<< " is out of range of " << G.getEdgeKindName(E.getKind())
432-
<< " fixup at " << formatv("{0:x}", B.getFixupAddress(E)) << " (";
424+
<< ": relocation target "
425+
<< formatv("{0:x}", E.getTarget().getAddress() + E.getAddend())
426+
<< " (";
427+
if (E.getTarget().hasName())
428+
ErrStream << E.getTarget().getName();
429+
else
430+
ErrStream << "<anonymous symbol>";
431+
if (E.getAddend()) {
432+
// Target address includes non-zero added, so break down the arithmetic.
433+
ErrStream << formatv(":{0:x}", E.getTarget().getAddress()) << " + "
434+
<< formatv("{0:x}", E.getAddend());
435+
}
436+
ErrStream << ") is out of range of " << G.getEdgeKindName(E.getKind())
437+
<< " fixup at address "
438+
<< formatv("{0:x}", E.getTarget().getAddress()) << " (";
433439

434440
Symbol *BestSymbolForBlock = nullptr;
435441
for (auto *Sym : Sec.symbols())

llvm/test/ExecutionEngine/JITLink/AArch64/ELF_R_AARCH64_ABS32.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# jitlink-check: *{8}xptr = x
1313

14-
# CHECK-ERROR: relocation target "x" {{.*}} is out of range of Pointer32 fixup
14+
# CHECK-ERROR: relocation target {{.*}} (x) is out of range of Pointer32 fixup
1515

1616
--- !ELF
1717
FileHeader:

llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_16.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# jitlink-check: *{8}P = X
1010

11-
# CHECK-ERROR: relocation target "X" {{.*}} is out of range of Pointer16 fixup
11+
# CHECK-ERROR: relocation target {{.*}} (X) is out of range of Pointer16 fixup
1212

1313
.text
1414
.section .text.main,"ax",@progbits

llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_32.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# jitlink-check: *{8}P = X
1010

11-
# CHECK-ERROR: relocation target "X" {{.*}} is out of range of Pointer32 fixup
11+
# CHECK-ERROR: relocation target {{.*}} (X) is out of range of Pointer32 fixup
1212

1313
.text
1414
.section .text.main,"ax",@progbits

llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_8.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# jitlink-check: *{8}P = X
1010

11-
# CHECK-ERROR: relocation target "X" {{.*}} is out of range of Pointer8 fixup
11+
# CHECK-ERROR: relocation target {{.*}} (X) is out of range of Pointer8 fixup
1212

1313
.text
1414
.section .text.main,"ax",@progbits

llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# RUN: llvm-mc -triple=x86_64-unknown-linux -position-independent --defsym=OVERFLOW=1 \
88
# RUN: -filetype=obj -o %t.2.o %s
99
# RUN: not llvm-jitlink -noexec %t.2.o 2>&1 | FileCheck %s
10-
# CHECK: llvm-jitlink error: In graph {{.*}}, section .text: relocation target "main" at address {{.*}} is out of range of Size32 fixup at {{.*}} (main, {{.*}})
10+
# CHECK: llvm-jitlink error: In graph {{.*}}, section .text: relocation target {{.*}} (main:{{.*}} + {{.*}}) is out of range of Size32 fixup at address {{.*}} (main, {{.*}})
1111

1212
.text
1313
.globl main

0 commit comments

Comments
 (0)