Index: ELF/Arch/PPC.cpp =================================================================== --- ELF/Arch/PPC.cpp +++ ELF/Arch/PPC.cpp @@ -260,6 +260,9 @@ std::tie(NewType, Val) = fromDTPREL(Type, Val); switch (NewType) { case R_PPC_ADDR16: + checkIntUInt(Loc, Val, 16, Type); + write16(Loc, Val); + break; case R_PPC_GOT16: case R_PPC_GOT_TLSGD16: case R_PPC_GOT_TLSLD16: Index: ELF/Arch/PPC64.cpp =================================================================== --- ELF/Arch/PPC64.cpp +++ ELF/Arch/PPC64.cpp @@ -756,10 +756,13 @@ break; } case R_PPC64_ADDR16: - case R_PPC64_TPREL16: - checkInt(Loc, Val, 16, OriginalType); + checkIntUInt(Loc, Val, 16, OriginalType); write16(Loc, Val); break; + case R_PPC64_ADDR32: + checkIntUInt(Loc, Val, 32, OriginalType); + write32(Loc, Val); + break; case R_PPC64_ADDR16_DS: case R_PPC64_TPREL16_DS: { checkInt(Loc, Val, 16, OriginalType); @@ -836,7 +839,10 @@ write16(Loc, (read16(Loc) & Mask) | lo(Val)); } } break; - case R_PPC64_ADDR32: + case R_PPC64_TPREL16: + checkInt(Loc, Val, 16, OriginalType); + write16(Loc, Val); + break; case R_PPC64_REL32: checkInt(Loc, Val, 32, Type); write32(Loc, Val); Index: ELF/Target.h =================================================================== --- ELF/Target.h +++ ELF/Target.h @@ -221,7 +221,7 @@ // messages show a small negative value rather than an extremely large one if (V != (uint64_t)llvm::SignExtend64(V, N) && (V >> N) != 0) reportRangeError(Loc, Type, Twine((int64_t)V), llvm::minIntN(N), - llvm::maxIntN(N)); + llvm::maxUIntN(N)); } inline void checkAlignment(uint8_t *Loc, uint64_t V, int N, RelType Type) { Index: test/ELF/aarch64-abs16.s =================================================================== --- test/ELF/aarch64-abs16.s +++ test/ELF/aarch64-abs16.s @@ -20,8 +20,8 @@ // S + A = 0x8000 // CHECK-NEXT: 210000 ffff0080 -// RUN: not ld.lld %t.o %t255.o -o %t2 2>&1 | FileCheck %s --check-prefix=OVERFLOW1 -// OVERFLOW1: relocation R_AARCH64_ABS16 out of range: -32769 is not in [-32768, 32767] +// RUN: not ld.lld %t.o %t255.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=OVERFLOW1 +// OVERFLOW1: relocation R_AARCH64_ABS16 out of range: -32769 is not in [-32768, 65535] -// RUN: not ld.lld %t.o %t257.o -o %t2 2>&1 | FileCheck %s --check-prefix=OVERFLOW2 -// OVERFLOW2: relocation R_AARCH64_ABS16 out of range: 65536 is not in [-32768, 32767] +// RUN: not ld.lld %t.o %t257.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=OVERFLOW2 +// OVERFLOW2: 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 @@ -20,8 +20,8 @@ // S + A = 0x80000000 // CHECK-NEXT: 210000 ffffffff 00000080 -// RUN: not ld.lld %t.o %t255.o -o %t2 2>&1 | FileCheck %s --check-prefix=OVERFLOW1 -// OVERFLOW1: relocation R_AARCH64_ABS32 out of range: -2147483649 is not in [-2147483648, 2147483647] +// RUN: not ld.lld %t.o %t255.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=OVERFLOW1 +// OVERFLOW1: relocation R_AARCH64_ABS32 out of range: -2147483649 is not in [-2147483648, 4294967295] -// RUN: not ld.lld %t.o %t257.o -o %t2 2>&1 | FileCheck %s --check-prefix=OVERFLOW2 -// OVERFLOW2: relocation R_AARCH64_ABS32 out of range: 4294967296 is not in [-2147483648, 2147483647] +// RUN: not ld.lld %t.o %t257.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=OVERFLOW2 +// OVERFLOW2: relocation R_AARCH64_ABS32 out of range: 4294967296 is not in [-2147483648, 4294967295] Index: test/ELF/aarch64-prel16.s =================================================================== --- test/ELF/aarch64-prel16.s +++ test/ELF/aarch64-prel16.s @@ -25,7 +25,7 @@ // CHECK-NEXT: 201000 ffff0080 // RUN: not ld.lld -z max-page-size=4096 %t.o %t255.o -o %t2 2>&1 | FileCheck %s --check-prefix=OVERFLOW1 -// OVERFLOW1: relocation R_AARCH64_PREL16 out of range: -32769 is not in [-32768, 32767] +// OVERFLOW1: relocation R_AARCH64_PREL16 out of range: -32769 is not in [-32768, 65535] // RUN: not ld.lld -z max-page-size=4096 %t.o %t257.o -o %t2 2>&1 | FileCheck %s --check-prefix=OVERFLOW2 -// OVERFLOW2: relocation R_AARCH64_PREL16 out of range: 65536 is not in [-32768, 32767] +// OVERFLOW2: relocation R_AARCH64_PREL16 out of range: 65536 is not in [-32768, 65535] Index: test/ELF/aarch64-prel32.s =================================================================== --- test/ELF/aarch64-prel32.s +++ test/ELF/aarch64-prel32.s @@ -25,7 +25,7 @@ // CHECK-NEXT: 201000 ffffffff 00000080 // RUN: not ld.lld -z max-page-size=4096 %t.o %t255.o -o %t2 2>&1 | FileCheck %s --check-prefix=OVERFLOW1 -// OVERFLOW1: relocation R_AARCH64_PREL32 out of range: -2147483649 is not in [-2147483648, 2147483647] +// OVERFLOW1: relocation R_AARCH64_PREL32 out of range: -2147483649 is not in [-2147483648, 4294967295] // RUN: not ld.lld -z max-page-size=4096 %t.o %t257.o -o %t2 2>&1 | FileCheck %s --check-prefix=OVERFLOW2 -// OVERFLOW2: relocation R_AARCH64_PREL32 out of range: 4294967296 is not in [-2147483648, 2147483647] +// OVERFLOW2: relocation R_AARCH64_PREL32 out of range: 4294967296 is not in [-2147483648, 4294967295] Index: test/ELF/i386-reloc-16.s =================================================================== --- test/ELF/i386-reloc-16.s +++ test/ELF/i386-reloc-16.s @@ -10,6 +10,6 @@ // CHECK-NEXT: 1000 42 // RUN: not ld.lld -shared %t %t2 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR %s -// ERROR: relocation R_386_16 out of range: 65536 is not in [-32768, 32767] +// ERROR: relocation R_386_16 out of range: 65536 is not in [-32768, 65535] .short foo Index: test/ELF/i386-reloc-8.s =================================================================== --- test/ELF/i386-reloc-8.s +++ test/ELF/i386-reloc-8.s @@ -10,6 +10,6 @@ // CHECK-NEXT: 1000 ff // RUN: not ld.lld -shared %t %t2 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR %s -// ERROR: relocation R_386_8 out of range: 256 is not in [-128, 127] +// ERROR: relocation R_386_8 out of range: 256 is not in [-128, 255] .byte foo Index: test/ELF/ppc32-reloc-addr.s =================================================================== --- test/ELF/ppc32-reloc-addr.s +++ test/ELF/ppc32-reloc-addr.s @@ -1,17 +1,9 @@ # REQUIRES: ppc # RUN: llvm-mc -filetype=obj -triple=powerpc %s -o %t.o -# RUN: ld.lld --noinhibit-exec %t.o --defsym=a=0x1234 --defsym=b=0xbcdef -o %t 2>&1 | \ -# RUN: FileCheck --check-prefix=WARN %s +# RUN: ld.lld %t.o --defsym=a=0x1234 --defsym=b=0xbcdef -o %t # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s # RUN: llvm-objdump -s --no-show-raw-insn %t | FileCheck --check-prefix=HEX %s -.section .R_PPC_ADDR16,"ax",@progbits - lis 4, a - lis 4, b -# CHECK-LABEL: section .R_PPC_ADDR16: -# CHECK: lis 4, 4660 -# WARN: warning: {{.*}}.o:(.R_PPC_ADDR16+0x6): relocation R_PPC_ADDR16 out of range: 773615 is not in [-32768, 32767] - .section .R_PPC_ADDR16_HA,"ax",@progbits lis 4, a@ha # CHECK-LABEL: section .R_PPC_ADDR16_HA: Index: test/ELF/ppc64-addr16-error.s =================================================================== --- test/ELF/ppc64-addr16-error.s +++ /dev/null @@ -1,13 +0,0 @@ -// REQUIRES: ppc - -// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t -// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-addr16-error.s -o %t2 -// RUN: not ld.lld -shared %t %t2 -o /dev/null 2>&1 | FileCheck %s - -// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t -// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-addr16-error.s -o %t2 -// RUN: not ld.lld -shared %t %t2 -o /dev/null 2>&1 | FileCheck %s - -.short sym+65539 - -// CHECK: relocation R_PPC64_ADDR16 out of range: 65539 is not in [-32768, 32767] Index: test/ELF/ppc64-reloc-addr.s =================================================================== --- /dev/null +++ test/ELF/ppc64-reloc-addr.s @@ -0,0 +1,25 @@ +# REQUIRES: ppc +# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64le %S/Inputs/abs255.s -o %t255.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64le %S/Inputs/abs256.s -o %t256.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64le %S/Inputs/abs257.s -o %t257.o + +# RUN: ld.lld %t.o %t256.o -o %t +# RUN: llvm-readelf -x .data %t | FileCheck %s +# CHECK: 0x{{[0-9a-f]+}} ffff0080 ffffffff 00000080 + +# RUN: not ld.lld %t.o %t255.o -o /dev/null 2>&1 | FileCheck --check-prefix=OVERFLOW1 %s +# OVERFLOW1: relocation R_PPC64_ADDR16 out of range: -32769 is not in [-32768, 65535] +# OVERFLOW1: relocation R_PPC64_ADDR32 out of range: -2147483649 is not in [-2147483648, 4294967295] + +# RUN: not ld.lld %t.o %t257.o -o /dev/null 2>&1 | FileCheck --check-prefix=OVERFLOW2 %s +# OVERFLOW2: relocation R_PPC64_ADDR16 out of range: 65536 is not in [-32768, 65535] +# OVERFLOW2: relocation R_PPC64_ADDR32 out of range: 4294967296 is not in [-2147483648, 4294967295] + +.globl _start +_start: +.data +.word foo + 0xfeff +.word foo - 0x8100 +.long foo + 0xfffffeff +.long foo - 0x80000100