summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/Target.cpp6
-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/i386-reloc-16.s14
-rw-r--r--lld/test/ELF/i386-reloc-8.s14
7 files changed, 46 insertions, 0 deletions
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 0826f4b81d5..023c948b738 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -517,11 +517,17 @@ void X86TargetInfo::relocateOne(uint8_t *Loc, uint32_t Type,
// we want to support them.
switch (Type) {
case R_386_8:
+ checkUInt<8>(Loc, Val, Type);
+ *Loc = Val;
+ break;
case R_386_PC8:
checkInt<8>(Loc, Val, Type);
*Loc = Val;
break;
case R_386_16:
+ checkUInt<16>(Loc, Val, Type);
+ write16le(Loc, Val);
+ break;
case R_386_PC16:
checkInt<16>(Loc, Val, Type);
write16le(Loc, Val);
diff --git a/lld/test/ELF/Inputs/i386-reloc-16-error.s b/lld/test/ELF/Inputs/i386-reloc-16-error.s
new file mode 100644
index 00000000000..8deed64dbef
--- /dev/null
+++ b/lld/test/ELF/Inputs/i386-reloc-16-error.s
@@ -0,0 +1,3 @@
+.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
new file mode 100644
index 00000000000..ac4601b5c58
--- /dev/null
+++ b/lld/test/ELF/Inputs/i386-reloc-16.s
@@ -0,0 +1,3 @@
+.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
new file mode 100644
index 00000000000..b6a7626456d
--- /dev/null
+++ b/lld/test/ELF/Inputs/i386-reloc-8-error.s
@@ -0,0 +1,3 @@
+.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
new file mode 100644
index 00000000000..ce488f6e1d5
--- /dev/null
+++ b/lld/test/ELF/Inputs/i386-reloc-8.s
@@ -0,0 +1,3 @@
+.globl foo
+.hidden foo
+foo = 0xff
diff --git a/lld/test/ELF/i386-reloc-16.s b/lld/test/ELF/i386-reloc-16.s
new file mode 100644
index 00000000000..db9dc0b3690
--- /dev/null
+++ b/lld/test/ELF/i386-reloc-16.s
@@ -0,0 +1,14 @@
+// REQUIRES: x86
+
+// 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
+
+// CHECK: Contents of section .text:
+// 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
+
+.short foo
diff --git a/lld/test/ELF/i386-reloc-8.s b/lld/test/ELF/i386-reloc-8.s
new file mode 100644
index 00000000000..b2e4426910e
--- /dev/null
+++ b/lld/test/ELF/i386-reloc-8.s
@@ -0,0 +1,14 @@
+// REQUIRES: x86
+
+// 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
+
+// CHECK: Contents of section .text:
+// 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
+
+.byte foo
OpenPOWER on IntegriCloud