summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/Target.cpp15
-rw-r--r--lld/test/ELF/Inputs/abs255.s2
-rw-r--r--lld/test/ELF/Inputs/abs256.s2
-rw-r--r--lld/test/ELF/Inputs/abs257.s2
-rw-r--r--lld/test/ELF/aarch64-abs16-error.s7
-rw-r--r--lld/test/ELF/aarch64-abs16.s25
-rw-r--r--lld/test/ELF/aarch64-abs32-error.s7
-rw-r--r--lld/test/ELF/aarch64-abs32.s25
-rw-r--r--lld/test/ELF/aarch64-data-relocs.s56
-rw-r--r--lld/test/ELF/aarch64-prel16-error.s7
-rw-r--r--lld/test/ELF/aarch64-prel16.s29
-rw-r--r--lld/test/ELF/aarch64-prel32-error.s7
-rw-r--r--lld/test/ELF/aarch64-prel32.s29
13 files changed, 134 insertions, 79 deletions
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 22cbc25a150..3a649029eeb 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -56,6 +56,13 @@ template <unsigned N> static void checkUInt(uint64_t V, uint32_t Type) {
error("Relocation " + S + " out of range");
}
+template <unsigned N> static void checkIntUInt(uint64_t V, uint32_t Type) {
+ if (isInt<N>(V) || isUInt<N>(V))
+ return;
+ StringRef S = getELFRelocationTypeName(Config->EMachine, Type);
+ error("Relocation " + S + " out of range");
+}
+
template <unsigned N> static void checkAlignment(uint64_t V, uint32_t Type) {
if ((V & (N - 1)) == 0)
return;
@@ -933,11 +940,11 @@ void AArch64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd,
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 @@ void AArch64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd,
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:
diff --git a/lld/test/ELF/Inputs/abs255.s b/lld/test/ELF/Inputs/abs255.s
new file mode 100644
index 00000000000..844ae7d863d
--- /dev/null
+++ b/lld/test/ELF/Inputs/abs255.s
@@ -0,0 +1,2 @@
+.global foo
+foo = 255
diff --git a/lld/test/ELF/Inputs/abs256.s b/lld/test/ELF/Inputs/abs256.s
new file mode 100644
index 00000000000..3f53bc5ec9f
--- /dev/null
+++ b/lld/test/ELF/Inputs/abs256.s
@@ -0,0 +1,2 @@
+.global foo
+foo = 256
diff --git a/lld/test/ELF/Inputs/abs257.s b/lld/test/ELF/Inputs/abs257.s
new file mode 100644
index 00000000000..4ae7fe8fe5e
--- /dev/null
+++ b/lld/test/ELF/Inputs/abs257.s
@@ -0,0 +1,2 @@
+.global foo
+foo = 257
diff --git a/lld/test/ELF/aarch64-abs16-error.s b/lld/test/ELF/aarch64-abs16-error.s
deleted file mode 100644
index 927fb4adf0e..00000000000
--- a/lld/test/ELF/aarch64-abs16-error.s
+++ /dev/null
@@ -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
diff --git a/lld/test/ELF/aarch64-abs16.s b/lld/test/ELF/aarch64-abs16.s
new file mode 100644
index 00000000000..b0734643cb5
--- /dev/null
+++ b/lld/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
diff --git a/lld/test/ELF/aarch64-abs32-error.s b/lld/test/ELF/aarch64-abs32-error.s
deleted file mode 100644
index 754d8821dd7..00000000000
--- a/lld/test/ELF/aarch64-abs32-error.s
+++ /dev/null
@@ -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
diff --git a/lld/test/ELF/aarch64-abs32.s b/lld/test/ELF/aarch64-abs32.s
new file mode 100644
index 00000000000..1d721b80064
--- /dev/null
+++ b/lld/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
diff --git a/lld/test/ELF/aarch64-data-relocs.s b/lld/test/ELF/aarch64-data-relocs.s
index 65329b6fb35..4e2f1a3cb2f 100644
--- a/lld/test/ELF/aarch64-data-relocs.s
+++ b/lld/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
diff --git a/lld/test/ELF/aarch64-prel16-error.s b/lld/test/ELF/aarch64-prel16-error.s
deleted file mode 100644
index c0dc1c20b5f..00000000000
--- a/lld/test/ELF/aarch64-prel16-error.s
+++ /dev/null
@@ -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
diff --git a/lld/test/ELF/aarch64-prel16.s b/lld/test/ELF/aarch64-prel16.s
new file mode 100644
index 00000000000..dc718f27087
--- /dev/null
+++ b/lld/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
diff --git a/lld/test/ELF/aarch64-prel32-error.s b/lld/test/ELF/aarch64-prel32-error.s
deleted file mode 100644
index 5dfaa1cc335..00000000000
--- a/lld/test/ELF/aarch64-prel32-error.s
+++ /dev/null
@@ -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
diff --git a/lld/test/ELF/aarch64-prel32.s b/lld/test/ELF/aarch64-prel32.s
new file mode 100644
index 00000000000..2317e29ce4a
--- /dev/null
+++ b/lld/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
OpenPOWER on IntegriCloud