Skip to content

Commit d2481be

Browse files
committedDec 11, 2017
[ELF] When a relocation is out of range print the value and the range
Reviewers: ruiu, grimar Reviewed By: ruiu Subscribers: emaste, nemanjai, javed.absar, kbarton, llvm-commits Differential Revision: https://reviews.llvm.org/D40962 llvm-svn: 320416
1 parent 3c6c14d commit d2481be

16 files changed

+30
-22
lines changed
 

‎lld/ELF/Target.h

+13-6
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,32 @@ TargetInfo *getTarget();
144144

145145
template <class ELFT> bool isMipsPIC(const Defined *Sym);
146146

147+
static inline void reportRangeError(uint8_t *Loc, RelType Type, const Twine &V,
148+
int64_t Min, uint64_t Max) {
149+
error(getErrorLocation(Loc) + "relocation " + lld::toString(Type) +
150+
" out of range: " + V + " is not in [" + Twine(Min) + ", " +
151+
Twine(Max) + "]");
152+
}
153+
147154
template <unsigned N>
148155
static void checkInt(uint8_t *Loc, int64_t V, RelType Type) {
149156
if (!llvm::isInt<N>(V))
150-
error(getErrorLocation(Loc) + "relocation " + lld::toString(Type) +
151-
" out of range");
157+
reportRangeError(Loc, Type, Twine(V), llvm::minIntN(N), llvm::maxIntN(N));
152158
}
153159

154160
template <unsigned N>
155161
static void checkUInt(uint8_t *Loc, uint64_t V, RelType Type) {
156162
if (!llvm::isUInt<N>(V))
157-
error(getErrorLocation(Loc) + "relocation " + lld::toString(Type) +
158-
" out of range");
163+
reportRangeError(Loc, Type, Twine(V), 0, llvm::maxUIntN(N));
159164
}
160165

161166
template <unsigned N>
162167
static void checkIntUInt(uint8_t *Loc, uint64_t V, RelType Type) {
163168
if (!llvm::isInt<N>(V) && !llvm::isUInt<N>(V))
164-
error(getErrorLocation(Loc) + "relocation " + lld::toString(Type) +
165-
" out of range");
169+
// For the error message we should cast V to a signed integer so that error
170+
// messages show a small negative value rather than an extremely large one
171+
reportRangeError(Loc, Type, Twine((int64_t)V), llvm::minIntN(N),
172+
llvm::maxUIntN(N));
166173
}
167174

168175
template <unsigned N>

‎lld/test/ELF/aarch64-abs16.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ _start:
2424
// | FileCheck %s --check-prefix=OVERFLOW
2525
// RUN: not ld.lld %t.o %t257.o -o %t2
2626
// | FileCheck %s --check-prefix=OVERFLOW
27-
// OVERFLOW: Relocation R_AARCH64_ABS16 out of range
27+
// OVERFLOW: Relocation R_AARCH64_ABS16 out of range: 65536 is not in [-32768, 65535]

‎lld/test/ELF/aarch64-abs32.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ _start:
2424
// | FileCheck %s --check-prefix=OVERFLOW
2525
// RUN: not ld.lld %t.o %t257.o -o %t2
2626
// | FileCheck %s --check-prefix=OVERFLOW
27-
// OVERFLOW: Relocation R_AARCH64_ABS32 out of range
27+
// OVERFLOW: Relocation R_AARCH64_ABS32 out of range: 4294967296 is not in [-2147483648, 4294967295]

‎lld/test/ELF/aarch64-ldprel-lo19-invalid.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-none %s -o %t.o
44
# RUN: not ld.lld -shared %t.o -o %t 2>&1 | FileCheck %s
55

6-
# CHECK: relocation R_AARCH64_LD_PREL_LO19 out of range
6+
# CHECK: relocation R_AARCH64_LD_PREL_LO19 out of range: 2065536 is not in [-1048576, 1048575]
77

88
ldr x8, patatino
99
.data

‎lld/test/ELF/aarch64-prel16.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ _start:
2828
// | FileCheck %s --check-prefix=OVERFLOW
2929
// RUN: not ld.lld %t.o %t257.o -o %t2
3030
// | FileCheck %s --check-prefix=OVERFLOW
31-
// OVERFLOW: Relocation R_AARCH64_PREL16 out of range
31+
// OVERFLOW: Relocation R_AARCH64_PREL16 out of range: -94209 is not in [-32768, 65535]

‎lld/test/ELF/aarch64-prel32.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ _start:
2828
// | FileCheck %s --check-prefix=OVERFLOW
2929
// RUN: not ld.lld %t.o %t257.o -o %t2
3030
// | FileCheck %s --check-prefix=OVERFLOW
31-
// OVERFLOW: Relocation R_AARCH64_PREL32 out of range
31+
// OVERFLOW: Relocation R_AARCH64_PREL32 out of range: 18446744071562006527 is not in [-2147483648, 4294967295]

‎lld/test/ELF/i386-reloc-16.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
// CHECK-NEXT: 200000 42
1010

1111
// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s
12-
// ERROR: relocation R_386_16 out of range
12+
// ERROR: relocation R_386_16 out of range: 65536 is not in [0, 65535]
1313

1414
.short foo

‎lld/test/ELF/i386-reloc-8.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
// CHECK-NEXT: 200000 42
1010

1111
// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s
12-
// ERROR: relocation R_386_8 out of range
12+
// ERROR: relocation R_386_8 out of range: 256 is not in [0, 255]
1313

1414
.byte foo

‎lld/test/ELF/i386-reloc-range.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
// RUN: not ld.lld -Ttext 0x200 %t.o %t2.o -o %t2 2>&1 | FileCheck --check-prefix=ERR %s
1818

19-
// ERR: {{.*}}:(.text+0x1): relocation R_386_PC16 out of range
19+
// ERR: {{.*}}:(.text+0x1): relocation R_386_PC16 out of range: 65536 is not in [-65536, 65535]
2020

2121
.global _start
2222
_start:

‎lld/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# RUN: }" > %t.script
1313
# RUN: not ld.lld %t.o -T %t.script -o %t 2>&1 | FileCheck %s
1414

15-
# CHECK: error: {{.*}}:(.eh_frame+0x20): relocation R_X86_64_PC32 out of range
15+
# CHECK: error: {{.*}}:(.eh_frame+0x20): relocation R_X86_64_PC32 out of range: 64424443872 is not in [-2147483648, 2147483647]
1616

1717
.text
1818
.globl _start

‎lld/test/ELF/mips-out-of-bounds-call16-reloc.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t1.o
55
# RUN: not ld.lld %t1.o -o %t.exe 2>&1 | FileCheck %s
66

7-
# CHECK: relocation R_MIPS_CALL16 out of range
7+
# CHECK: relocation R_MIPS_CALL16 out of range: 32768 is not in [-32768, 32767]
88

99
.macro generate_values
1010
.irp i, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,

‎lld/test/ELF/ppc64-addr16-error.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
.short sym+65539
77

8-
// CHECK: relocation R_PPC64_ADDR16 out of range
8+
// CHECK: relocation R_PPC64_ADDR16 out of range: 65539 is not in [-32768, 32767]

‎lld/test/ELF/x86-64-reloc-16.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
// CHECK-NEXT: 200000 42
1010

1111
// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s
12-
// ERROR: relocation R_X86_64_16 out of range
12+
// ERROR: relocation R_X86_64_16 out of range: 65536 is not in [0, 65535]
1313

1414
.short foo

‎lld/test/ELF/x86-64-reloc-8.s

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// CHECK-NEXT: 200000 42
1010

1111
// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s
12-
// ERROR: relocation R_X86_64_8 out of range
12+
// ERROR: relocation R_X86_64_8 out of range: 256 is not in [0, 255]
13+
// ERROR: relocation R_X86_64_8 out of range: 256 is not in [0, 255]
1314

1415
.byte foo

‎lld/test/ELF/x86-64-reloc-error.s

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
movl $big, %edx
77
movq $foo - 0x1000000000000, %rdx
88

9-
# CHECK: {{.*}}:(.text+0x1): relocation R_X86_64_32 out of range
10-
# CHECK: {{.*}}:(.text+0x8): relocation R_X86_64_32S out of range
9+
# CHECK: {{.*}}:(.text+0x1): relocation R_X86_64_32 out of range: 68719476736 is not in [0, 4294967295]
10+
# CHECK: {{.*}}:(.text+0x8): relocation R_X86_64_32S out of range: -281474976710656 is not in [-2147483648, 2147483647]

‎lld/test/ELF/x86-64-reloc-range.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: llvm-mc %s -o %t.o -triple x86_64-pc-linux -filetype=obj
22
// RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s
33

4-
// CHECK: {{.*}}:(.text+0x3): relocation R_X86_64_PC32 out of range
4+
// CHECK: {{.*}}:(.text+0x3): relocation R_X86_64_PC32 out of range: 2147483648 is not in [-2147483648, 2147483647]
55
// CHECK-NOT: relocation
66

77
lea foo(%rip), %rax

0 commit comments

Comments
 (0)
Please sign in to comment.