[lld] r320416 - [ELF] When a relocation is out of range print the value and the range
Alexander Richardson via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 12:47:21 PST 2017
Author: arichardson
Date: Mon Dec 11 12:47:21 2017
New Revision: 320416
URL: http://llvm.org/viewvc/llvm-project?rev=320416&view=rev
Log:
[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
Modified:
lld/trunk/ELF/Target.h
lld/trunk/test/ELF/aarch64-abs16.s
lld/trunk/test/ELF/aarch64-abs32.s
lld/trunk/test/ELF/aarch64-ldprel-lo19-invalid.s
lld/trunk/test/ELF/aarch64-prel16.s
lld/trunk/test/ELF/aarch64-prel32.s
lld/trunk/test/ELF/i386-reloc-16.s
lld/trunk/test/ELF/i386-reloc-8.s
lld/trunk/test/ELF/i386-reloc-range.s
lld/trunk/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s
lld/trunk/test/ELF/mips-out-of-bounds-call16-reloc.s
lld/trunk/test/ELF/ppc64-addr16-error.s
lld/trunk/test/ELF/x86-64-reloc-16.s
lld/trunk/test/ELF/x86-64-reloc-8.s
lld/trunk/test/ELF/x86-64-reloc-error.s
lld/trunk/test/ELF/x86-64-reloc-range.s
Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Mon Dec 11 12:47:21 2017
@@ -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>
Modified: lld/trunk/test/ELF/aarch64-abs16.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-abs16.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-abs16.s (original)
+++ lld/trunk/test/ELF/aarch64-abs16.s Mon Dec 11 12:47:21 2017
@@ -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]
Modified: lld/trunk/test/ELF/aarch64-abs32.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-abs32.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-abs32.s (original)
+++ lld/trunk/test/ELF/aarch64-abs32.s Mon Dec 11 12:47:21 2017
@@ -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]
Modified: lld/trunk/test/ELF/aarch64-ldprel-lo19-invalid.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-ldprel-lo19-invalid.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-ldprel-lo19-invalid.s (original)
+++ lld/trunk/test/ELF/aarch64-ldprel-lo19-invalid.s Mon Dec 11 12:47:21 2017
@@ -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
Modified: lld/trunk/test/ELF/aarch64-prel16.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-prel16.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-prel16.s (original)
+++ lld/trunk/test/ELF/aarch64-prel16.s Mon Dec 11 12:47:21 2017
@@ -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]
Modified: lld/trunk/test/ELF/aarch64-prel32.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-prel32.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-prel32.s (original)
+++ lld/trunk/test/ELF/aarch64-prel32.s Mon Dec 11 12:47:21 2017
@@ -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]
Modified: lld/trunk/test/ELF/i386-reloc-16.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/i386-reloc-16.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/i386-reloc-16.s (original)
+++ lld/trunk/test/ELF/i386-reloc-16.s Mon Dec 11 12:47:21 2017
@@ -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
Modified: lld/trunk/test/ELF/i386-reloc-8.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/i386-reloc-8.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/i386-reloc-8.s (original)
+++ lld/trunk/test/ELF/i386-reloc-8.s Mon Dec 11 12:47:21 2017
@@ -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
Modified: lld/trunk/test/ELF/i386-reloc-range.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/i386-reloc-range.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/i386-reloc-range.s (original)
+++ lld/trunk/test/ELF/i386-reloc-range.s Mon Dec 11 12:47:21 2017
@@ -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:
Modified: lld/trunk/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s (original)
+++ lld/trunk/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s Mon Dec 11 12:47:21 2017
@@ -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
Modified: lld/trunk/test/ELF/mips-out-of-bounds-call16-reloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-out-of-bounds-call16-reloc.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-out-of-bounds-call16-reloc.s (original)
+++ lld/trunk/test/ELF/mips-out-of-bounds-call16-reloc.s Mon Dec 11 12:47:21 2017
@@ -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,
Modified: lld/trunk/test/ELF/ppc64-addr16-error.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ppc64-addr16-error.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/ppc64-addr16-error.s (original)
+++ lld/trunk/test/ELF/ppc64-addr16-error.s Mon Dec 11 12:47:21 2017
@@ -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]
Modified: lld/trunk/test/ELF/x86-64-reloc-16.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-reloc-16.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/x86-64-reloc-16.s (original)
+++ lld/trunk/test/ELF/x86-64-reloc-16.s Mon Dec 11 12:47:21 2017
@@ -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
Modified: lld/trunk/test/ELF/x86-64-reloc-8.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-reloc-8.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/x86-64-reloc-8.s (original)
+++ lld/trunk/test/ELF/x86-64-reloc-8.s Mon Dec 11 12:47:21 2017
@@ -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
Modified: lld/trunk/test/ELF/x86-64-reloc-error.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-reloc-error.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/x86-64-reloc-error.s (original)
+++ lld/trunk/test/ELF/x86-64-reloc-error.s Mon Dec 11 12:47:21 2017
@@ -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]
Modified: lld/trunk/test/ELF/x86-64-reloc-range.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-reloc-range.s?rev=320416&r1=320415&r2=320416&view=diff
==============================================================================
--- lld/trunk/test/ELF/x86-64-reloc-range.s (original)
+++ lld/trunk/test/ELF/x86-64-reloc-range.s Mon Dec 11 12:47:21 2017
@@ -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
More information about the llvm-commits
mailing list