Index: ELF/Target.h =================================================================== --- ELF/Target.h +++ ELF/Target.h @@ -144,25 +144,32 @@ template 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 static void checkInt(uint8_t *Loc, int64_t V, RelType Type) { if (!llvm::isInt(V)) - error(getErrorLocation(Loc) + "relocation " + lld::toString(Type) + - " out of range"); + reportRangeError(Loc, Type, Twine(V), llvm::minIntN(N), llvm::maxIntN(N)); } template static void checkUInt(uint8_t *Loc, uint64_t V, RelType Type) { if (!llvm::isUInt(V)) - error(getErrorLocation(Loc) + "relocation " + lld::toString(Type) + - " out of range"); + reportRangeError(Loc, Type, Twine(V), 0, llvm::maxUIntN(N)); } template static void checkIntUInt(uint8_t *Loc, uint64_t V, RelType Type) { if (!llvm::isInt(V) && !llvm::isUInt(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 Index: test/ELF/aarch64-abs16.s =================================================================== --- test/ELF/aarch64-abs16.s +++ test/ELF/aarch64-abs16.s @@ -24,4 +24,4 @@ // | 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] Index: test/ELF/aarch64-abs32.s =================================================================== --- test/ELF/aarch64-abs32.s +++ test/ELF/aarch64-abs32.s @@ -24,4 +24,4 @@ // | 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] Index: test/ELF/aarch64-ldprel-lo19-invalid.s =================================================================== --- test/ELF/aarch64-ldprel-lo19-invalid.s +++ test/ELF/aarch64-ldprel-lo19-invalid.s @@ -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 Index: test/ELF/aarch64-prel16.s =================================================================== --- test/ELF/aarch64-prel16.s +++ test/ELF/aarch64-prel16.s @@ -28,4 +28,4 @@ // | 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] Index: test/ELF/aarch64-prel32.s =================================================================== --- test/ELF/aarch64-prel32.s +++ test/ELF/aarch64-prel32.s @@ -28,4 +28,4 @@ // | 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] Index: test/ELF/i386-reloc-16.s =================================================================== --- test/ELF/i386-reloc-16.s +++ test/ELF/i386-reloc-16.s @@ -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 Index: test/ELF/i386-reloc-8.s =================================================================== --- test/ELF/i386-reloc-8.s +++ test/ELF/i386-reloc-8.s @@ -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 Index: test/ELF/i386-reloc-range.s =================================================================== --- test/ELF/i386-reloc-range.s +++ test/ELF/i386-reloc-range.s @@ -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: Index: test/ELF/linkerscript/eh-frame-reloc-out-of-range.s =================================================================== --- test/ELF/linkerscript/eh-frame-reloc-out-of-range.s +++ test/ELF/linkerscript/eh-frame-reloc-out-of-range.s @@ -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 Index: test/ELF/mips-out-of-bounds-call16-reloc.s =================================================================== --- test/ELF/mips-out-of-bounds-call16-reloc.s +++ test/ELF/mips-out-of-bounds-call16-reloc.s @@ -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, Index: test/ELF/ppc64-addr16-error.s =================================================================== --- test/ELF/ppc64-addr16-error.s +++ test/ELF/ppc64-addr16-error.s @@ -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] Index: test/ELF/x86-64-reloc-16.s =================================================================== --- test/ELF/x86-64-reloc-16.s +++ test/ELF/x86-64-reloc-16.s @@ -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 Index: test/ELF/x86-64-reloc-8.s =================================================================== --- test/ELF/x86-64-reloc-8.s +++ test/ELF/x86-64-reloc-8.s @@ -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 Index: test/ELF/x86-64-reloc-error.s =================================================================== --- test/ELF/x86-64-reloc-error.s +++ test/ELF/x86-64-reloc-error.s @@ -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] Index: test/ELF/x86-64-reloc-range.s =================================================================== --- test/ELF/x86-64-reloc-range.s +++ test/ELF/x86-64-reloc-range.s @@ -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