summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/Arch/PPC.cpp3
-rw-r--r--lld/ELF/Arch/PPC64.cpp12
-rw-r--r--lld/ELF/Arch/X86_64.cpp4
-rw-r--r--lld/ELF/Target.h2
-rw-r--r--lld/test/ELF/Inputs/i386-reloc-16-error.s3
-rw-r--r--lld/test/ELF/Inputs/i386-reloc-16.s3
-rw-r--r--lld/test/ELF/Inputs/i386-reloc-8-error.s3
-rw-r--r--lld/test/ELF/Inputs/i386-reloc-8.s3
-rw-r--r--lld/test/ELF/Inputs/x86-64-reloc-16-error.s3
-rw-r--r--lld/test/ELF/Inputs/x86-64-reloc-16.s3
-rw-r--r--lld/test/ELF/Inputs/x86-64-reloc-8-error.s3
-rw-r--r--lld/test/ELF/Inputs/x86-64-reloc-8.s3
-rw-r--r--lld/test/ELF/aarch64-abs16.s8
-rw-r--r--lld/test/ELF/aarch64-abs32.s8
-rw-r--r--lld/test/ELF/aarch64-prel16.s4
-rw-r--r--lld/test/ELF/aarch64-prel32.s4
-rw-r--r--lld/test/ELF/i386-reloc-16.s27
-rw-r--r--lld/test/ELF/i386-reloc-8.s27
-rw-r--r--lld/test/ELF/ppc32-reloc-addr.s10
-rw-r--r--lld/test/ELF/ppc64-addr16-error.s13
-rw-r--r--lld/test/ELF/ppc64-reloc-addr.s25
-rw-r--r--lld/test/ELF/x86-64-reloc-16.s14
-rw-r--r--lld/test/ELF/x86-64-reloc-8-16.s25
-rw-r--r--lld/test/ELF/x86-64-reloc-8.s14
24 files changed, 110 insertions, 114 deletions
diff --git a/lld/ELF/Arch/PPC.cpp b/lld/ELF/Arch/PPC.cpp
index 30b6966ffbd..de2c1ee7f9e 100644
--- a/lld/ELF/Arch/PPC.cpp
+++ b/lld/ELF/Arch/PPC.cpp
@@ -260,6 +260,9 @@ void PPC::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
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:
diff --git a/lld/ELF/Arch/PPC64.cpp b/lld/ELF/Arch/PPC64.cpp
index e467b12b2bb..4af935e8a80 100644
--- a/lld/ELF/Arch/PPC64.cpp
+++ b/lld/ELF/Arch/PPC64.cpp
@@ -756,10 +756,13 @@ void PPC64::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
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 @@ void PPC64::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
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);
diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp
index 2f2c9ce473a..33c031c440a 100644
--- a/lld/ELF/Arch/X86_64.cpp
+++ b/lld/ELF/Arch/X86_64.cpp
@@ -349,7 +349,7 @@ void X86_64::relaxTlsLdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {
void X86_64::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
switch (Type) {
case R_X86_64_8:
- checkUInt(Loc, Val, 8, Type);
+ checkIntUInt(Loc, Val, 8, Type);
*Loc = Val;
break;
case R_X86_64_PC8:
@@ -357,7 +357,7 @@ void X86_64::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
*Loc = Val;
break;
case R_X86_64_16:
- checkUInt(Loc, Val, 16, Type);
+ checkIntUInt(Loc, Val, 16, Type);
write16le(Loc, Val);
break;
case R_X86_64_PC16:
diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h
index 88aa074074e..e9cbacb8dd7 100644
--- a/lld/ELF/Target.h
+++ b/lld/ELF/Target.h
@@ -221,7 +221,7 @@ inline void checkIntUInt(uint8_t *Loc, uint64_t V, int N, RelType Type) {
// 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) {
diff --git a/lld/test/ELF/Inputs/i386-reloc-16-error.s b/lld/test/ELF/Inputs/i386-reloc-16-error.s
deleted file mode 100644
index 8deed64dbef..00000000000
--- a/lld/test/ELF/Inputs/i386-reloc-16-error.s
+++ /dev/null
@@ -1,3 +0,0 @@
-.globl foo
-.hidden foo
-foo = 65536
diff --git a/lld/test/ELF/Inputs/i386-reloc-16.s b/lld/test/ELF/Inputs/i386-reloc-16.s
deleted file mode 100644
index ac4601b5c58..00000000000
--- a/lld/test/ELF/Inputs/i386-reloc-16.s
+++ /dev/null
@@ -1,3 +0,0 @@
-.globl foo
-.hidden foo
-foo = 0xffff
diff --git a/lld/test/ELF/Inputs/i386-reloc-8-error.s b/lld/test/ELF/Inputs/i386-reloc-8-error.s
deleted file mode 100644
index b6a7626456d..00000000000
--- a/lld/test/ELF/Inputs/i386-reloc-8-error.s
+++ /dev/null
@@ -1,3 +0,0 @@
-.globl foo
-.hidden foo
-foo = 256
diff --git a/lld/test/ELF/Inputs/i386-reloc-8.s b/lld/test/ELF/Inputs/i386-reloc-8.s
deleted file mode 100644
index ce488f6e1d5..00000000000
--- a/lld/test/ELF/Inputs/i386-reloc-8.s
+++ /dev/null
@@ -1,3 +0,0 @@
-.globl foo
-.hidden foo
-foo = 0xff
diff --git a/lld/test/ELF/Inputs/x86-64-reloc-16-error.s b/lld/test/ELF/Inputs/x86-64-reloc-16-error.s
deleted file mode 100644
index 8deed64dbef..00000000000
--- a/lld/test/ELF/Inputs/x86-64-reloc-16-error.s
+++ /dev/null
@@ -1,3 +0,0 @@
-.globl foo
-.hidden foo
-foo = 65536
diff --git a/lld/test/ELF/Inputs/x86-64-reloc-16.s b/lld/test/ELF/Inputs/x86-64-reloc-16.s
deleted file mode 100644
index c5b2f553604..00000000000
--- a/lld/test/ELF/Inputs/x86-64-reloc-16.s
+++ /dev/null
@@ -1,3 +0,0 @@
-.globl foo
-.hidden foo
-foo = 0x42
diff --git a/lld/test/ELF/Inputs/x86-64-reloc-8-error.s b/lld/test/ELF/Inputs/x86-64-reloc-8-error.s
deleted file mode 100644
index b6a7626456d..00000000000
--- a/lld/test/ELF/Inputs/x86-64-reloc-8-error.s
+++ /dev/null
@@ -1,3 +0,0 @@
-.globl foo
-.hidden foo
-foo = 256
diff --git a/lld/test/ELF/Inputs/x86-64-reloc-8.s b/lld/test/ELF/Inputs/x86-64-reloc-8.s
deleted file mode 100644
index c5b2f553604..00000000000
--- a/lld/test/ELF/Inputs/x86-64-reloc-8.s
+++ /dev/null
@@ -1,3 +0,0 @@
-.globl foo
-.hidden foo
-foo = 0x42
diff --git a/lld/test/ELF/aarch64-abs16.s b/lld/test/ELF/aarch64-abs16.s
index c9d88b31ae3..261413185c7 100644
--- a/lld/test/ELF/aarch64-abs16.s
+++ b/lld/test/ELF/aarch64-abs16.s
@@ -20,8 +20,8 @@ _start:
// 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]
diff --git a/lld/test/ELF/aarch64-abs32.s b/lld/test/ELF/aarch64-abs32.s
index da2005dc97a..7b697d3570a 100644
--- a/lld/test/ELF/aarch64-abs32.s
+++ b/lld/test/ELF/aarch64-abs32.s
@@ -20,8 +20,8 @@ _start:
// 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]
diff --git a/lld/test/ELF/aarch64-prel16.s b/lld/test/ELF/aarch64-prel16.s
index 18a594c319a..49c93472d8f 100644
--- a/lld/test/ELF/aarch64-prel16.s
+++ b/lld/test/ELF/aarch64-prel16.s
@@ -25,7 +25,7 @@ _start:
// 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]
diff --git a/lld/test/ELF/aarch64-prel32.s b/lld/test/ELF/aarch64-prel32.s
index 16c8bb3c201..7246caf2bfe 100644
--- a/lld/test/ELF/aarch64-prel32.s
+++ b/lld/test/ELF/aarch64-prel32.s
@@ -25,7 +25,7 @@ _start:
// 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]
diff --git a/lld/test/ELF/i386-reloc-16.s b/lld/test/ELF/i386-reloc-16.s
index 9a099a6ba3e..aef2394a691 100644
--- a/lld/test/ELF/i386-reloc-16.s
+++ b/lld/test/ELF/i386-reloc-16.s
@@ -1,15 +1,20 @@
-// REQUIRES: x86
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=i386 %s -o %t.o
-// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %S/Inputs/x86-64-reloc-16.s -o %t1
-// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %S/Inputs/x86-64-reloc-16-error.s -o %t2
-// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t
-// RUN: ld.lld -shared %t %t1 -o %t3
-// RUN: llvm-objdump -s %t3 | FileCheck %s
+# RUN: ld.lld %t.o --defsym=a=0 --defsym=b=32768 -o %t
+# RUN: llvm-readelf -x .text %t | FileCheck %s
+# CHECK: b80080bb ffff
-// CHECK: Contents of section .text:
-// CHECK-NEXT: 1000 42
+# RUN: not ld.lld %t.o --defsym=a=-1 --defsym=b=0 -o /dev/null 2>&1 | \
+# RUN: FileCheck --check-prefix=OVERFLOW1 %s
+# OVERFLOW1: relocation R_386_16 out of range: -32769 is not in [-32768, 65535]
-// 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]
+# RUN: not ld.lld %t.o --defsym=a=0 --defsym=b=32769 -o /dev/null 2>&1 | \
+# RUN: FileCheck --check-prefix=OVERFLOW2 %s
+# OVERFLOW2: relocation R_386_16 out of range: 65536 is not in [-32768, 65535]
-.short foo
+.code16
+.global _start
+_start:
+movw $a-32768, %ax
+movw $b+32767, %bx
diff --git a/lld/test/ELF/i386-reloc-8.s b/lld/test/ELF/i386-reloc-8.s
index b46aaa68826..6949ab651f6 100644
--- a/lld/test/ELF/i386-reloc-8.s
+++ b/lld/test/ELF/i386-reloc-8.s
@@ -1,15 +1,20 @@
-// REQUIRES: x86
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=i386 %s -o %t.o
-// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %S/Inputs/i386-reloc-8.s -o %t1
-// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %S/Inputs/i386-reloc-8-error.s -o %t2
-// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t
-// RUN: ld.lld -shared %t %t1 -o %t3
-// RUN: llvm-objdump -s %t3 | FileCheck %s
+# RUN: ld.lld %t.o --defsym=a=0 --defsym=b=128 -o %t
+# RUN: llvm-readelf -x .text %t | FileCheck %s
+# CHECK: b480b7ff
-// CHECK: Contents of section .text:
-// CHECK-NEXT: 1000 ff
+# RUN: not ld.lld %t.o --defsym=a=-1 --defsym=b=0 -o /dev/null 2>&1 | \
+# RUN: FileCheck --check-prefix=OVERFLOW1 %s
+# OVERFLOW1: relocation R_386_8 out of range: -129 is not in [-128, 255]
-// 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]
+# RUN: not ld.lld %t.o --defsym=a=0 --defsym=b=129 -o /dev/null 2>&1 | \
+# RUN: FileCheck --check-prefix=OVERFLOW2 %s
+# OVERFLOW2: relocation R_386_8 out of range: 256 is not in [-128, 255]
-.byte foo
+.code16
+.globl _start
+_start:
+movb $a-128, %ah
+movb $b+127, %bh
diff --git a/lld/test/ELF/ppc32-reloc-addr.s b/lld/test/ELF/ppc32-reloc-addr.s
index 1bf1bdedb55..98bd61b1192 100644
--- a/lld/test/ELF/ppc32-reloc-addr.s
+++ b/lld/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:
diff --git a/lld/test/ELF/ppc64-addr16-error.s b/lld/test/ELF/ppc64-addr16-error.s
deleted file mode 100644
index 5ffca587d6e..00000000000
--- a/lld/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]
diff --git a/lld/test/ELF/ppc64-reloc-addr.s b/lld/test/ELF/ppc64-reloc-addr.s
new file mode 100644
index 00000000000..f3a7708bc38
--- /dev/null
+++ b/lld/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
diff --git a/lld/test/ELF/x86-64-reloc-16.s b/lld/test/ELF/x86-64-reloc-16.s
deleted file mode 100644
index 5157c3706fe..00000000000
--- a/lld/test/ELF/x86-64-reloc-16.s
+++ /dev/null
@@ -1,14 +0,0 @@
-// REQUIRES: x86
-
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-16.s -o %t1
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-16-error.s -o %t2
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
-// RUN: ld.lld -shared %t %t1 -o /dev/null
-
-// CHECK: Contents of section .text:
-// CHECK-NEXT: 200000 42
-
-// RUN: not ld.lld -shared %t %t2 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR %s
-// ERROR: relocation R_X86_64_16 out of range: 65536 is not in [0, 65535]
-
-.short foo
diff --git a/lld/test/ELF/x86-64-reloc-8-16.s b/lld/test/ELF/x86-64-reloc-8-16.s
new file mode 100644
index 00000000000..7c4eeb0a596
--- /dev/null
+++ b/lld/test/ELF/x86-64-reloc-8-16.s
@@ -0,0 +1,25 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %S/Inputs/abs255.s -o %t255.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %S/Inputs/abs256.s -o %t256.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %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]+}} ff80ffff 0080
+
+# RUN: not ld.lld %t.o %t255.o -o /dev/null 2>&1 | FileCheck --check-prefix=OVERFLOW1 %s
+# OVERFLOW1: relocation R_X86_64_8 out of range: -129 is not in [-128, 255]
+# OVERFLOW1: relocation R_X86_64_16 out of range: -32769 is not in [-32768, 65535]
+
+# RUN: not ld.lld %t.o %t257.o -o /dev/null 2>&1 | FileCheck --check-prefix=OVERFLOW2 %s
+# OVERFLOW2: relocation R_X86_64_8 out of range: 256 is not in [-128, 255]
+# OVERFLOW2: relocation R_X86_64_16 out of range: 65536 is not in [-32768, 65535]
+
+.globl _start
+_start:
+.data
+.byte foo - 1
+.byte foo - 384
+.word foo + 0xfeff
+.word foo - 0x8100
diff --git a/lld/test/ELF/x86-64-reloc-8.s b/lld/test/ELF/x86-64-reloc-8.s
deleted file mode 100644
index f71bafb7ffb..00000000000
--- a/lld/test/ELF/x86-64-reloc-8.s
+++ /dev/null
@@ -1,14 +0,0 @@
-// REQUIRES: x86
-
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-8.s -o %t1
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-8-error.s -o %t2
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
-// RUN: ld.lld -shared %t %t1 -o /dev/null
-
-// CHECK: Contents of section .text:
-// CHECK-NEXT: 200000 42
-
-// RUN: not ld.lld -shared %t %t2 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR %s
-// ERROR: relocation R_X86_64_8 out of range: 256 is not in [0, 255]
-
-.byte foo
OpenPOWER on IntegriCloud