[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
This commit is contained in:
Alexander Richardson 2017-12-11 20:47:21 +00:00
parent 3c6c14d14b
commit d2481bed05
16 changed files with 30 additions and 22 deletions

View File

@ -144,25 +144,32 @@ TargetInfo *getTarget();
template <class ELFT> bool isMipsPIC(const Defined *Sym);
static inline void reportRangeError(uint8_t *Loc, RelType Type, const Twine &V,
int64_t Min, uint64_t Max) {
error(getErrorLocation(Loc) + "relocation " + lld::toString(Type) +
" out of range: " + V + " is not in [" + Twine(Min) + ", " +
Twine(Max) + "]");
}
template <unsigned N>
static void checkInt(uint8_t *Loc, int64_t V, RelType Type) {
if (!llvm::isInt<N>(V))
error(getErrorLocation(Loc) + "relocation " + lld::toString(Type) +
" out of range");
reportRangeError(Loc, Type, Twine(V), llvm::minIntN(N), llvm::maxIntN(N));
}
template <unsigned N>
static void checkUInt(uint8_t *Loc, uint64_t V, RelType Type) {
if (!llvm::isUInt<N>(V))
error(getErrorLocation(Loc) + "relocation " + lld::toString(Type) +
" out of range");
reportRangeError(Loc, Type, Twine(V), 0, llvm::maxUIntN(N));
}
template <unsigned N>
static void checkIntUInt(uint8_t *Loc, uint64_t V, RelType Type) {
if (!llvm::isInt<N>(V) && !llvm::isUInt<N>(V))
error(getErrorLocation(Loc) + "relocation " + lld::toString(Type) +
" out of range");
// For the error message we should cast V to a signed integer so that error
// messages show a small negative value rather than an extremely large one
reportRangeError(Loc, Type, Twine((int64_t)V), llvm::minIntN(N),
llvm::maxUIntN(N));
}
template <unsigned N>

View File

@ -24,4 +24,4 @@ _start:
// | FileCheck %s --check-prefix=OVERFLOW
// RUN: not ld.lld %t.o %t257.o -o %t2
// | FileCheck %s --check-prefix=OVERFLOW
// OVERFLOW: Relocation R_AARCH64_ABS16 out of range
// OVERFLOW: Relocation R_AARCH64_ABS16 out of range: 65536 is not in [-32768, 65535]

View File

@ -24,4 +24,4 @@ _start:
// | FileCheck %s --check-prefix=OVERFLOW
// RUN: not ld.lld %t.o %t257.o -o %t2
// | FileCheck %s --check-prefix=OVERFLOW
// OVERFLOW: Relocation R_AARCH64_ABS32 out of range
// OVERFLOW: Relocation R_AARCH64_ABS32 out of range: 4294967296 is not in [-2147483648, 4294967295]

View File

@ -3,7 +3,7 @@
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-none %s -o %t.o
# RUN: not ld.lld -shared %t.o -o %t 2>&1 | FileCheck %s
# CHECK: relocation R_AARCH64_LD_PREL_LO19 out of range
# CHECK: relocation R_AARCH64_LD_PREL_LO19 out of range: 2065536 is not in [-1048576, 1048575]
ldr x8, patatino
.data

View File

@ -28,4 +28,4 @@ _start:
// | FileCheck %s --check-prefix=OVERFLOW
// RUN: not ld.lld %t.o %t257.o -o %t2
// | FileCheck %s --check-prefix=OVERFLOW
// OVERFLOW: Relocation R_AARCH64_PREL16 out of range
// OVERFLOW: Relocation R_AARCH64_PREL16 out of range: -94209 is not in [-32768, 65535]

View File

@ -28,4 +28,4 @@ _start:
// | FileCheck %s --check-prefix=OVERFLOW
// RUN: not ld.lld %t.o %t257.o -o %t2
// | FileCheck %s --check-prefix=OVERFLOW
// OVERFLOW: Relocation R_AARCH64_PREL32 out of range
// OVERFLOW: Relocation R_AARCH64_PREL32 out of range: 18446744071562006527 is not in [-2147483648, 4294967295]

View File

@ -9,6 +9,6 @@
// CHECK-NEXT: 200000 42
// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s
// ERROR: relocation R_386_16 out of range
// ERROR: relocation R_386_16 out of range: 65536 is not in [0, 65535]
.short foo

View File

@ -9,6 +9,6 @@
// CHECK-NEXT: 200000 42
// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s
// ERROR: relocation R_386_8 out of range
// ERROR: relocation R_386_8 out of range: 256 is not in [0, 255]
.byte foo

View File

@ -16,7 +16,7 @@
// RUN: not ld.lld -Ttext 0x200 %t.o %t2.o -o %t2 2>&1 | FileCheck --check-prefix=ERR %s
// ERR: {{.*}}:(.text+0x1): relocation R_386_PC16 out of range
// ERR: {{.*}}:(.text+0x1): relocation R_386_PC16 out of range: 65536 is not in [-65536, 65535]
.global _start
_start:

View File

@ -12,7 +12,7 @@
# RUN: }" > %t.script
# RUN: not ld.lld %t.o -T %t.script -o %t 2>&1 | FileCheck %s
# CHECK: error: {{.*}}:(.eh_frame+0x20): relocation R_X86_64_PC32 out of range
# CHECK: error: {{.*}}:(.eh_frame+0x20): relocation R_X86_64_PC32 out of range: 64424443872 is not in [-2147483648, 2147483647]
.text
.globl _start

View File

@ -4,7 +4,7 @@
# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t1.o
# RUN: not ld.lld %t1.o -o %t.exe 2>&1 | FileCheck %s
# CHECK: relocation R_MIPS_CALL16 out of range
# CHECK: relocation R_MIPS_CALL16 out of range: 32768 is not in [-32768, 32767]
.macro generate_values
.irp i, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,

View File

@ -5,4 +5,4 @@
.short sym+65539
// CHECK: relocation R_PPC64_ADDR16 out of range
// CHECK: relocation R_PPC64_ADDR16 out of range: 65539 is not in [-32768, 32767]

View File

@ -9,6 +9,6 @@
// CHECK-NEXT: 200000 42
// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s
// ERROR: relocation R_X86_64_16 out of range
// ERROR: relocation R_X86_64_16 out of range: 65536 is not in [0, 65535]
.short foo

View File

@ -9,6 +9,7 @@
// CHECK-NEXT: 200000 42
// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s
// ERROR: relocation R_X86_64_8 out of range
// ERROR: relocation R_X86_64_8 out of range: 256 is not in [0, 255]
// ERROR: relocation R_X86_64_8 out of range: 256 is not in [0, 255]
.byte foo

View File

@ -6,5 +6,5 @@
movl $big, %edx
movq $foo - 0x1000000000000, %rdx
# CHECK: {{.*}}:(.text+0x1): relocation R_X86_64_32 out of range
# CHECK: {{.*}}:(.text+0x8): relocation R_X86_64_32S out of range
# CHECK: {{.*}}:(.text+0x1): relocation R_X86_64_32 out of range: 68719476736 is not in [0, 4294967295]
# CHECK: {{.*}}:(.text+0x8): relocation R_X86_64_32S out of range: -281474976710656 is not in [-2147483648, 2147483647]

View File

@ -1,7 +1,7 @@
// RUN: llvm-mc %s -o %t.o -triple x86_64-pc-linux -filetype=obj
// RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s
// CHECK: {{.*}}:(.text+0x3): relocation R_X86_64_PC32 out of range
// CHECK: {{.*}}:(.text+0x3): relocation R_X86_64_PC32 out of range: 2147483648 is not in [-2147483648, 2147483647]
// CHECK-NOT: relocation
lea foo(%rip), %rax