Index: lld/trunk/ELF/Target.cpp =================================================================== --- lld/trunk/ELF/Target.cpp +++ lld/trunk/ELF/Target.cpp @@ -56,6 +56,13 @@ error("Relocation " + S + " out of range"); } +template static void checkIntUInt(uint64_t V, uint32_t Type) { + if (isInt(V) || isUInt(V)) + return; + StringRef S = getELFRelocationTypeName(Config->EMachine, Type); + error("Relocation " + S + " out of range"); +} + template static void checkAlignment(uint64_t V, uint32_t Type) { if ((V & (N - 1)) == 0) return; @@ -933,11 +940,11 @@ uint64_t SA) const { switch (Type) { case R_AARCH64_ABS16: - checkInt<16>(SA, Type); + checkIntUInt<16>(SA, Type); write16le(Loc, SA); break; case R_AARCH64_ABS32: - checkInt<32>(SA, Type); + checkIntUInt<32>(SA, Type); write32le(Loc, SA); break; case R_AARCH64_ABS64: @@ -990,11 +997,11 @@ or32le(Loc, (SA & 0xFFF) << 10); break; case R_AARCH64_PREL16: - checkInt<16>(SA - P, Type); + checkIntUInt<16>(SA - P, Type); write16le(Loc, SA - P); break; case R_AARCH64_PREL32: - checkInt<32>(SA - P, Type); + checkIntUInt<32>(SA - P, Type); write32le(Loc, SA - P); break; case R_AARCH64_PREL64: Index: lld/trunk/test/ELF/Inputs/abs255.s =================================================================== --- lld/trunk/test/ELF/Inputs/abs255.s +++ lld/trunk/test/ELF/Inputs/abs255.s @@ -0,0 +1,2 @@ +.global foo +foo = 255 Index: lld/trunk/test/ELF/Inputs/abs256.s =================================================================== --- lld/trunk/test/ELF/Inputs/abs256.s +++ lld/trunk/test/ELF/Inputs/abs256.s @@ -0,0 +1,2 @@ +.global foo +foo = 256 Index: lld/trunk/test/ELF/Inputs/abs257.s =================================================================== --- lld/trunk/test/ELF/Inputs/abs257.s +++ lld/trunk/test/ELF/Inputs/abs257.s @@ -0,0 +1,2 @@ +.global foo +foo = 257 Index: lld/trunk/test/ELF/aarch64-abs16-error.s =================================================================== --- lld/trunk/test/ELF/aarch64-abs16-error.s +++ lld/trunk/test/ELF/aarch64-abs16-error.s @@ -1,7 +0,0 @@ -// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t -// RUN: not ld.lld -shared %t -o %t2 2>&1 | FileCheck %s -// REQUIRES: aarch64 - -.hword sym+65539 - -// CHECK: R_AARCH64_ABS16 out of range Index: lld/trunk/test/ELF/aarch64-abs16.s =================================================================== --- lld/trunk/test/ELF/aarch64-abs16.s +++ lld/trunk/test/ELF/aarch64-abs16.s @@ -0,0 +1,25 @@ +// REQUIRES: aarch64 +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs255.s -o %t255.o +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs256.s -o %t256.o +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs257.s -o %t257.o + +.data + .hword foo + 0xfeff + .hword foo - 0x8100 + +// RUN: ld.lld -shared %t.o %t256.o -o %t.so +// RUN: llvm-objdump -s -section=.data %t.so | FileCheck %s + +// CHECK: Contents of section .data: +// 1090: S = 0x100, A = 0xfeff +// S + A = 0xffff +// 1092: S = 0x100, A = -0x8100 +// S + A = 0x8000 +// CHECK-NEXT: 1090 ffff0080 + +// RUN: not ld.lld -shared %t.o %t255.o -o %t.so +// | FileCheck %s --check-prefix=OVERFLOW +// RUN: not ld.lld -shared %t.o %t257.o -o %t.so +// | FileCheck %s --check-prefix=OVERFLOW +// OVERFLOW: Relocation R_AARCH64_ABS16 out of range Index: lld/trunk/test/ELF/aarch64-abs32-error.s =================================================================== --- lld/trunk/test/ELF/aarch64-abs32-error.s +++ lld/trunk/test/ELF/aarch64-abs32-error.s @@ -1,7 +0,0 @@ -// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t -// RUN: not ld.lld -shared %t -o %t2 2>&1 | FileCheck %s -// REQUIRES: aarch64 - -.word sym+99999999999 - -// CHECK: R_AARCH64_ABS32 out of range Index: lld/trunk/test/ELF/aarch64-abs32.s =================================================================== --- lld/trunk/test/ELF/aarch64-abs32.s +++ lld/trunk/test/ELF/aarch64-abs32.s @@ -0,0 +1,25 @@ +// REQUIRES: aarch64 +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs255.s -o %t255.o +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs256.s -o %t256.o +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs257.s -o %t257.o + +.data + .word foo + 0xfffffeff + .word foo - 0x80000100 + +// RUN: ld.lld -shared %t.o %t256.o -o %t.so +// RUN: llvm-objdump -s -section=.data %t.so | FileCheck %s + +// CHECK: Contents of section .data: +// 1090: S = 0x100, A = 0xfffffeff +// S + A = 0xffffffff +// 1094: S = 0x100, A = -0x80000100 +// S + A = 0x80000000 +// CHECK-NEXT: 1090 ffffffff 00000080 + +// RUN: not ld.lld -shared %t.o %t255.o -o %t.so +// | FileCheck %s --check-prefix=OVERFLOW +// RUN: not ld.lld -shared %t.o %t257.o -o %t.so +// | FileCheck %s --check-prefix=OVERFLOW +// OVERFLOW: Relocation R_AARCH64_ABS32 out of range Index: lld/trunk/test/ELF/aarch64-data-relocs.s =================================================================== --- lld/trunk/test/ELF/aarch64-data-relocs.s +++ lld/trunk/test/ELF/aarch64-data-relocs.s @@ -1,58 +1,20 @@ // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t // RUN: ld.lld -shared %t -o %t2 -// RUN: llvm-objdump -d %t2 | FileCheck %s +// RUN: llvm-objdump -s %t2 | FileCheck %s // REQUIRES: aarch64 -.section .R_AARCH64_ABS16, "ax",@progbits - .hword sym+12 - -.section .R_AARCH64_ABS32, "ax",@progbits - .word sym+24 - .section .R_AARCH64_ABS64, "ax",@progbits - .xword sym+36 - -// CHECK: Disassembly of section .R_AARCH64_ABS16: -// CHECK-NEXT: $d.0: -// CHECK-NEXT: 1000: 0c 00 .short -// ^-- A = 0xc + .xword sym + 36 -// CHECK-NEXT: Disassembly of section .R_AARCH64_ABS32: -// CHECK-NEXT: $d.1: -// CHECK-NEXT: 1002: 18 00 00 00 .word -// ^-- A = 0x18 +// CHECK: Contents of section .R_AARCH64_ABS64: +// CHECK-NEXT: 1000 24000000 00000000 +// ^-- A = 0x24 -// CHECK-NEXT: Disassembly of section .R_AARCH64_ABS64: -// CHECK-NEXT: $d.2: -// CHECK-NEXT: 1006: 24 00 00 00 .word -// ^-- A = 0x24 -// CHECK-NEXT: 100a: 00 00 00 00 .word - -.section .R_AARCH64_PREL16, "ax",@progbits - .hword sym - . + 12 -.section .R_AARCH64_PREL32, "ax",@progbits - .word sym - . + 24 .section .R_AARCH64_PREL64, "ax",@progbits .xword sym - . + 36 -// S + A = 0xc -// P = 0x100e -// SA - P = 0xeffe -// CHECK: Disassembly of section .R_AARCH64_PREL16: -// CHECK-NEXT: $d.3: -// CHECK-NEXT: 100e: fe ef .short - -// S + A = 0x18 -// P = 0x1010 -// SA - P = 0xfffff016 -// CHECK: Disassembly of section .R_AARCH64_PREL32: -// CHECK-NEXT: $d.4: -// CHECK-NEXT: 1010: 08 f0 ff ff .word - // S + A = 0x24 -// P = 0x1014 -// SA - P = 0xfffffffffffff010 -// CHECK: Disassembly of section .R_AARCH64_PREL64: -// CHECK-NEXT: $d.5: -// CHECK-NEXT: 1014: 10 f0 ff ff .word -// CHECK-NEXT: 1018: ff ff ff ff .word +// P = 0x1008 +// SA - P = 0xfffffffffffff01c +// CHECK: Contents of section .R_AARCH64_PREL64: +// CHECK-NEXT: 1008 1cf0ffff ffffffff Index: lld/trunk/test/ELF/aarch64-prel16-error.s =================================================================== --- lld/trunk/test/ELF/aarch64-prel16-error.s +++ lld/trunk/test/ELF/aarch64-prel16-error.s @@ -1,7 +0,0 @@ -// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t -// RUN: not ld.lld -shared %t -o %t2 2>&1 | FileCheck %s -// REQUIRES: aarch64 - -.hword sym + 65539 - . - -// CHECK: R_AARCH64_PREL16 out of range Index: lld/trunk/test/ELF/aarch64-prel16.s =================================================================== --- lld/trunk/test/ELF/aarch64-prel16.s +++ lld/trunk/test/ELF/aarch64-prel16.s @@ -0,0 +1,29 @@ +// REQUIRES: aarch64 +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs255.s -o %t255.o +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs256.s -o %t256.o +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs257.s -o %t257.o + +.data + .hword foo - . + 0x10f8f + .hword foo - . - 0x706e + +// Note: If this test fails, it is probably results from +// the change of the address of the .data section. +// You may found the correct address in the aarch64_abs16.s test, +// if it's already fixed. Then, update addends accordingly. +// RUN: ld.lld -shared %t.o %t256.o -o %t.so +// RUN: llvm-objdump -s -section=.data %t.so | FileCheck %s + +// CHECK: Contents of section .data: +// 1090: S = 0x100, A = 0x10f8f, P = 0x1090 +// S + A - P = 0xffff +// 1092: S = 0x100, A = -0x706e, P = 0x1092 +// S + A - P = 0x8000 +// CHECK-NEXT: 1090 ffff0080 + +// RUN: not ld.lld -shared %t.o %t255.o -o %t.so +// | FileCheck %s --check-prefix=OVERFLOW +// RUN: not ld.lld -shared %t.o %t257.o -o %t.so +// | FileCheck %s --check-prefix=OVERFLOW +// OVERFLOW: Relocation R_AARCH64_PREL16 out of range Index: lld/trunk/test/ELF/aarch64-prel32-error.s =================================================================== --- lld/trunk/test/ELF/aarch64-prel32-error.s +++ lld/trunk/test/ELF/aarch64-prel32-error.s @@ -1,7 +0,0 @@ -// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t -// RUN: not ld.lld -shared %t -o %t2 2>&1 | FileCheck %s -// REQUIRES: aarch64 - -.word sym + 99999999999 - . - -// CHECK: R_AARCH64_PREL32 out of range Index: lld/trunk/test/ELF/aarch64-prel32.s =================================================================== --- lld/trunk/test/ELF/aarch64-prel32.s +++ lld/trunk/test/ELF/aarch64-prel32.s @@ -0,0 +1,29 @@ +// REQUIRES: aarch64 +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs255.s -o %t255.o +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs256.s -o %t256.o +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs257.s -o %t257.o + +.data + .word foo - . + 0x100000f8f + .word foo - . - 0x7ffff06c + +// Note: If this test fails, it is probably results from +// the change of the address of the .data section. +// You may found the correct address in the aarch64_abs32.s test, +// if it's already fixed. Then, update addends accordingly. +// RUN: ld.lld -shared %t.o %t256.o -o %t.so +// RUN: llvm-objdump -s -section=.data %t.so | FileCheck %s + +// CHECK: Contents of section .data: +// 1090: S = 0x100, A = 0x100000f8f, P = 0x1090 +// S + A - P = 0xffffffff +// 1094: S = 0x100, A = -0x7ffff06c, P = 0x1094 +// S + A - P = 0x80000000 +// CHECK-NEXT: 1090 ffffffff 00000080 + +// RUN: not ld.lld -shared %t.o %t255.o -o %t.so +// | FileCheck %s --check-prefix=OVERFLOW +// RUN: not ld.lld -shared %t.o %t257.o -o %t.so +// | FileCheck %s --check-prefix=OVERFLOW +// OVERFLOW: Relocation R_AARCH64_PREL32 out of range