This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[AArch64][4/6] LD support TLSLD move/add relocation types
- From: Jiong Wang <jiong dot wang at arm dot com>
- To: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Wed, 19 Aug 2015 13:32:51 +0100
- Subject: [AArch64][4/6] LD support TLSLD move/add relocation types
- Authentication-results: sourceware.org; auth=none
- References: <55D46D3C dot 6070406 at arm dot com> <55D46E1D dot 4000104 at arm dot com> <55D46E7A dot 3010004 at arm dot com> <55D46EFE dot 9060508 at arm dot com>
2015-08-19 Jiong Wang <jiong.wang@arm.com>
bfd/
PR ld/18276
* elfnn-aarch64.c (IS_AARCH64_TLS_RELOC): Recognize new relocation
types, including BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12,
BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0,
BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC,
BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1,
BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC,
BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2.
(elfNN_aarch64_final_link_relocate): Likewise.
* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend): Likewise.
(_bfd_aarch64_elf_resolve_relocation): Likewise.
ld/testsuite/
* ld-aarch64/emit-relocs-87.s: New testcase.
* ld-aarch64/emit-relocs-88.s: Likewise.
* ld-aarch64/emit-relocs-88-overflow.s: Likewise.
* ld-aarch64/emit-relocs-89.s: Likewise.
* ld-aarch64/emit-relocs-90.s: Likewise.
* ld-aarch64/emit-relocs-90-overflow.s: Likewise.
* ld-aarch64/emit-relocs-523.s: Likewise.
* ld-aarch64/emit-relocs-524.s: Likewise.
* ld-aarch64/emit-relocs-525.s: Likewise.
* ld-aarch64/emit-relocs-527.s: Likewise.
* ld-aarch64/emit-relocs-526.s: Likewise.
* ld-aarch64/emit-relocs-528.s: Likewise.
* ld-aarch64/emit-relocs-528-overflow.s: Likewise.
* ld-aarch64/emit-relocs-87.d: New expectation file.
* ld-aarch64/emit-relocs-88.d: Likewise.
* ld-aarch64/emit-relocs-88-overflow.d: Likewise.
* ld-aarch64/emit-relocs-89.d: Likewise.
* ld-aarch64/emit-relocs-90.d: Likewise.
* ld-aarch64/emit-relocs-90-overflow.d: Likewise.
* ld-aarch64/emit-relocs-91.d: Likewise.
* ld-aarch64/emit-relocs-523.d: Likewise.
* ld-aarch64/emit-relocs-524.d: Likewise.
* ld-aarch64/emit-relocs-525.d: Likewise.
* ld-aarch64/emit-relocs-526.d: Likewise.
* ld-aarch64/emit-relocs-527.d: Likewise.
* ld-aarch64/emit-relocs-528.d: Likewise.
* ld-aarch64/emit-relocs-528-overflow.d: Likewise.
* ld-aarch64/aarch64-elf.exp: Run new testcases.
From 20d15cd94c6ec8e5e0c68897e164c123b5d9cb9f Mon Sep 17 00:00:00 2001
From: Jiong Wang <jiong.wang@arm.com>
Date: Wed, 19 Aug 2015 11:18:25 +0100
Subject: [PATCH 4/6] 4
---
bfd/elfnn-aarch64.c | 12 ++++++++++++
bfd/elfxx-aarch64.c | 12 ++++++++++++
ld/testsuite/ld-aarch64/aarch64-elf.exp | 14 ++++++++++++++
ld/testsuite/ld-aarch64/emit-relocs-523.d | 7 +++++++
ld/testsuite/ld-aarch64/emit-relocs-523.s | 11 +++++++++++
ld/testsuite/ld-aarch64/emit-relocs-524.d | 7 +++++++
ld/testsuite/ld-aarch64/emit-relocs-524.s | 11 +++++++++++
ld/testsuite/ld-aarch64/emit-relocs-525.d | 7 +++++++
ld/testsuite/ld-aarch64/emit-relocs-525.s | 11 +++++++++++
ld/testsuite/ld-aarch64/emit-relocs-526-overflow.d | 4 ++++
ld/testsuite/ld-aarch64/emit-relocs-526-overflow.s | 10 ++++++++++
ld/testsuite/ld-aarch64/emit-relocs-526.d | 7 +++++++
ld/testsuite/ld-aarch64/emit-relocs-526.s | 10 ++++++++++
ld/testsuite/ld-aarch64/emit-relocs-527.d | 7 +++++++
ld/testsuite/ld-aarch64/emit-relocs-527.s | 10 ++++++++++
ld/testsuite/ld-aarch64/emit-relocs-528-overflow.d | 4 ++++
ld/testsuite/ld-aarch64/emit-relocs-528-overflow.s | 11 +++++++++++
ld/testsuite/ld-aarch64/emit-relocs-528.d | 7 +++++++
ld/testsuite/ld-aarch64/emit-relocs-528.s | 11 +++++++++++
ld/testsuite/ld-aarch64/emit-relocs-87.d | 8 ++++++++
ld/testsuite/ld-aarch64/emit-relocs-87.s | 10 ++++++++++
ld/testsuite/ld-aarch64/emit-relocs-88-overflow.d | 5 +++++
ld/testsuite/ld-aarch64/emit-relocs-88-overflow.s | 10 ++++++++++
ld/testsuite/ld-aarch64/emit-relocs-88.d | 8 ++++++++
ld/testsuite/ld-aarch64/emit-relocs-88.s | 10 ++++++++++
ld/testsuite/ld-aarch64/emit-relocs-89.d | 8 ++++++++
ld/testsuite/ld-aarch64/emit-relocs-89.s | 10 ++++++++++
ld/testsuite/ld-aarch64/emit-relocs-90-overflow.d | 5 +++++
ld/testsuite/ld-aarch64/emit-relocs-90-overflow.s | 11 +++++++++++
ld/testsuite/ld-aarch64/emit-relocs-90.d | 8 ++++++++
ld/testsuite/ld-aarch64/emit-relocs-90.s | 11 +++++++++++
31 files changed, 277 insertions(+)
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-523.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-523.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-524.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-524.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-525.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-525.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-526-overflow.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-526-overflow.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-526.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-526.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-527.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-527.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-528-overflow.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-528-overflow.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-528.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-528.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-87.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-87.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-88-overflow.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-88-overflow.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-88.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-88.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-89.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-89.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-90-overflow.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-90-overflow.s
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-90.d
create mode 100644 ld/testsuite/ld-aarch64/emit-relocs-90.s
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 6051108..eb79922 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -174,11 +174,17 @@
|| (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
|| (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
|| (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
+ || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \
|| (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
|| (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
|| (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
|| (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
|| (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
+ || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \
+ || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \
+ || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \
+ || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \
+ || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \
|| (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
|| (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
|| (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
@@ -5183,8 +5189,14 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
*unresolved_reloc_p = FALSE;
break;
+ case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12:
case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2:
value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
signed_addend - dtpoff_base (info),
weak_undef_p);
diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c
index dbb134a..82c6ec9 100644
--- a/bfd/elfxx-aarch64.c
+++ b/bfd/elfxx-aarch64.c
@@ -249,6 +249,7 @@ _bfd_aarch64_elf_put_addend (bfd *abfd,
case BFD_RELOC_AARCH64_ADD_LO12:
case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
+ case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12:
case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC:
case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
@@ -291,6 +292,9 @@ _bfd_aarch64_elf_put_addend (bfd *abfd,
case BFD_RELOC_AARCH64_MOVW_G0_S:
case BFD_RELOC_AARCH64_MOVW_G1_S:
case BFD_RELOC_AARCH64_MOVW_G2_S:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2:
case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
@@ -318,6 +322,8 @@ _bfd_aarch64_elf_put_addend (bfd *abfd,
case BFD_RELOC_AARCH64_MOVW_G2:
case BFD_RELOC_AARCH64_MOVW_G2_NC:
case BFD_RELOC_AARCH64_MOVW_G3:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC:
case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
contents = reencode_movw_imm (contents, addend);
@@ -400,8 +406,14 @@ _bfd_aarch64_elf_resolve_relocation (bfd_reloc_code_real_type r_type,
case BFD_RELOC_AARCH64_MOVW_G2_NC:
case BFD_RELOC_AARCH64_MOVW_G2_S:
case BFD_RELOC_AARCH64_MOVW_G3:
+ case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12:
case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC:
+ case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2:
value = value + addend;
break;
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index bb8f4c2..b8e801f 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -68,6 +68,12 @@ run_dump_test "weak-undefined"
run_dump_test "emit-relocs-28"
run_dump_test "emit-relocs-86"
run_dump_test "emit-relocs-86-overflow"
+run_dump_test "emit-relocs-87"
+run_dump_test "emit-relocs-88"
+run_dump_test "emit-relocs-88-overflow"
+run_dump_test "emit-relocs-89"
+run_dump_test "emit-relocs-90"
+run_dump_test "emit-relocs-90-overflow"
run_dump_test "emit-relocs-92"
run_dump_test "emit-relocs-257"
run_dump_test "emit-relocs-257-be"
@@ -119,6 +125,14 @@ run_dump_test "emit-relocs-309-low-bad"
run_dump_test "emit-relocs-311"
run_dump_test "emit-relocs-312"
run_dump_test "emit-relocs-313"
+run_dump_test "emit-relocs-523"
+run_dump_test "emit-relocs-524"
+run_dump_test "emit-relocs-525"
+run_dump_test "emit-relocs-526"
+run_dump_test "emit-relocs-526-overflow"
+run_dump_test "emit-relocs-527"
+run_dump_test "emit-relocs-528"
+run_dump_test "emit-relocs-528-overflow"
run_dump_test "emit-relocs-529"
run_dump_test "emit-relocs-529-overflow"
run_dump_test "emit-relocs-530"
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-523.d b/ld/testsuite/ld-aarch64/emit-relocs-523.d
new file mode 100644
index 0000000..d2d719d
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-523.d
@@ -0,0 +1,7 @@
+#source: emit-relocs-523.s
+#ld: -T relocs.ld -e0 --emit-relocs
+#objdump: -dr
+#...
+0000000000010000 <.text>:
+ 10000: f2c0001d movk x29, #0x0, lsl #32
+ 10000: R_AARCH64_TLSLD_MOVW_DTPREL_G2 v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-523.s b/ld/testsuite/ld-aarch64/emit-relocs-523.s
new file mode 100644
index 0000000..b2c4e5c
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-523.s
@@ -0,0 +1,11 @@
+ .global v1
+ .size v1, 65536
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .zero 65536
+v2:
+ .word 0xcafecafe
+
+ .text
+ movk x29, #:dtprel_g2:v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-524.d b/ld/testsuite/ld-aarch64/emit-relocs-524.d
new file mode 100644
index 0000000..d15b015
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-524.d
@@ -0,0 +1,7 @@
+#source: emit-relocs-524.s
+#ld: -T relocs.ld -e0 --emit-relocs
+#objdump: -dr
+#...
+0000000000010000 <.text>:
+ 10000: f2a0003d movk x29, #0x1, lsl #16
+ 10000: R_AARCH64_TLSLD_MOVW_DTPREL_G1 v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-524.s b/ld/testsuite/ld-aarch64/emit-relocs-524.s
new file mode 100644
index 0000000..58480b8
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-524.s
@@ -0,0 +1,11 @@
+ .global v1
+ .size v1, 65536
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .zero 65536
+v2:
+ .word 0xcafecafe
+
+ .text
+ movk x29, #:dtprel_g1:v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-525.d b/ld/testsuite/ld-aarch64/emit-relocs-525.d
new file mode 100644
index 0000000..6588062
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-525.d
@@ -0,0 +1,7 @@
+#source: emit-relocs-525.s
+#ld: -T relocs.ld -e0 --emit-relocs
+#objdump: -dr
+#...
+0000000000010000 <.text>:
+ 10000: f2a00031 movk x17, #0x1, lsl #16
+ 10000: R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-525.s b/ld/testsuite/ld-aarch64/emit-relocs-525.s
new file mode 100644
index 0000000..b52595e
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-525.s
@@ -0,0 +1,11 @@
+ .global v1
+ .size v1, 65536
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .zero 65536
+v2:
+ .word 0xcafecafe
+
+ .text
+ movk x17, #:dtprel_g1_nc:v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-526-overflow.d b/ld/testsuite/ld-aarch64/emit-relocs-526-overflow.d
new file mode 100644
index 0000000..7a29afb
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-526-overflow.d
@@ -0,0 +1,4 @@
+#source: emit-relocs-526-overflow.s
+#ld: -T relocs.ld -e0 --emit-relocs
+#objdump: -dr
+#error: .*\(.text\+0x\d+\): relocation truncated to fit: R_AARCH64_TLSLD_MOVW_DTPREL_G0 against symbol `v2' .*
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-526-overflow.s b/ld/testsuite/ld-aarch64/emit-relocs-526-overflow.s
new file mode 100644
index 0000000..28e953f
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-526-overflow.s
@@ -0,0 +1,10 @@
+ .global v1
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .zero 65536
+v2:
+ .word 0xcafecafe
+
+ .text
+ movk x17, #:dtprel_g0:v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-526.d b/ld/testsuite/ld-aarch64/emit-relocs-526.d
new file mode 100644
index 0000000..ed432d6
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-526.d
@@ -0,0 +1,7 @@
+#source: emit-relocs-526.s
+#ld: -T relocs.ld -e0 --emit-relocs
+#objdump: -dr
+#...
+0000000000010000 <.text>:
+ 10000: f2800091 movk x17, #0x4
+ 10000: R_AARCH64_TLSLD_MOVW_DTPREL_G0 v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-526.s b/ld/testsuite/ld-aarch64/emit-relocs-526.s
new file mode 100644
index 0000000..3216468
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-526.s
@@ -0,0 +1,10 @@
+ .global v1
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .word 0xdeaddead
+v2:
+ .word 0xcafecafe
+
+ .text
+ movk x17, #:dtprel_g0:v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-527.d b/ld/testsuite/ld-aarch64/emit-relocs-527.d
new file mode 100644
index 0000000..a546cd8
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-527.d
@@ -0,0 +1,7 @@
+#source: emit-relocs-527.s
+#ld: -T relocs.ld -e0 --emit-relocs
+#objdump: -dr
+#...
+0000000000010000 <.text>:
+ 10000: f2800091 movk x17, #0x4
+ 10000: R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-527.s b/ld/testsuite/ld-aarch64/emit-relocs-527.s
new file mode 100644
index 0000000..04dc37c
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-527.s
@@ -0,0 +1,10 @@
+ .global v1
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .word 0xdeaddead
+v2:
+ .word 0xcafecafe
+
+ .text
+ movk x17, #:dtprel_g0_nc:v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-528-overflow.d b/ld/testsuite/ld-aarch64/emit-relocs-528-overflow.d
new file mode 100644
index 0000000..ed754ff
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-528-overflow.d
@@ -0,0 +1,4 @@
+#source: emit-relocs-528-overflow.s
+#ld: -T relocs.ld -e0 --emit-relocs
+#objdump: -dr
+#error: .*\(.text\+0x\d+\): relocation truncated to fit: R_AARCH64_TLSLD_ADD_DTPREL_HI12 against symbol `v2' .*
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-528-overflow.s b/ld/testsuite/ld-aarch64/emit-relocs-528-overflow.s
new file mode 100644
index 0000000..1a3645f
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-528-overflow.s
@@ -0,0 +1,11 @@
+ .global v1
+ .size v1, 16777216
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .zero 16777216
+v2:
+ .word 0xcafecafe
+
+ .text
+ add x20, x9, #:dtprel_hi12:v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-528.d b/ld/testsuite/ld-aarch64/emit-relocs-528.d
new file mode 100644
index 0000000..ee2797f
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-528.d
@@ -0,0 +1,7 @@
+#source: emit-relocs-528.s
+#ld: -T relocs.ld -e0 --emit-relocs
+#objdump: -dr
+#...
+0000000000010000 <.text>:
+ 10000: 91002934 add x20, x9, #0xa
+ 10000: R_AARCH64_TLSLD_ADD_DTPREL_HI12 v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-528.s b/ld/testsuite/ld-aarch64/emit-relocs-528.s
new file mode 100644
index 0000000..6e6a0b4
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-528.s
@@ -0,0 +1,11 @@
+ .global v1
+ .size v1, 40960
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .zero 40960
+v2:
+ .word 0xcafecafe
+
+ .text
+ add x20, x9, #:dtprel_hi12:v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-87.d b/ld/testsuite/ld-aarch64/emit-relocs-87.d
new file mode 100644
index 0000000..dce85b6
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-87.d
@@ -0,0 +1,8 @@
+#source: emit-relocs-87.s
+#as: -mabi=ilp32
+#ld: -m [aarch64_choose_ilp32_emul] -e0 --emit-relocs
+#objdump: -dr
+#...
+.* <.text>:
+ .*: f2a00015 movk x21, #0x0, lsl #16
+ .*: R_AARCH64_P32_TLSLD_MOVW_DTPREL_G1 v1
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-87.s b/ld/testsuite/ld-aarch64/emit-relocs-87.s
new file mode 100644
index 0000000..5d1162e
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-87.s
@@ -0,0 +1,10 @@
+ .global v1
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .word 0xdeaddead
+v2:
+ .word 0xcafecafe
+
+ .text
+ movk x21, #:dtprel_g1:v1
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-88-overflow.d b/ld/testsuite/ld-aarch64/emit-relocs-88-overflow.d
new file mode 100644
index 0000000..cedf505
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-88-overflow.d
@@ -0,0 +1,5 @@
+#source: emit-relocs-88-overflow.s
+#as: -mabi=ilp32
+#ld: -m [aarch64_choose_ilp32_emul] -e0 --emit-relocs
+#objdump: -dr
+#error: .*\(.text\+0x\d+\): relocation truncated to fit: R_AARCH64_P32_TLSLD_MOVW_DTPREL_G0 against symbol `v2' .*
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-88-overflow.s b/ld/testsuite/ld-aarch64/emit-relocs-88-overflow.s
new file mode 100644
index 0000000..a4e5265
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-88-overflow.s
@@ -0,0 +1,10 @@
+ .global v1
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .zero 65536
+v2:
+ .word 0xcafecafe
+
+ .text
+ movk x21, #:dtprel_g0:v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-88.d b/ld/testsuite/ld-aarch64/emit-relocs-88.d
new file mode 100644
index 0000000..a6f6320
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-88.d
@@ -0,0 +1,8 @@
+#source: emit-relocs-88.s
+#as: -mabi=ilp32
+#ld: -m [aarch64_choose_ilp32_emul] -e0 --emit-relocs
+#objdump: -dr
+#...
+.* <.text>:
+ .*: f2800015 movk x21, #0x0
+ .*: R_AARCH64_P32_TLSLD_MOVW_DTPREL_G0 v1
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-88.s b/ld/testsuite/ld-aarch64/emit-relocs-88.s
new file mode 100644
index 0000000..cd5eda2
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-88.s
@@ -0,0 +1,10 @@
+ .global v1
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .word 0xdeaddead
+v2:
+ .word 0xcafecafe
+
+ .text
+ movk x21, #:dtprel_g0:v1
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-89.d b/ld/testsuite/ld-aarch64/emit-relocs-89.d
new file mode 100644
index 0000000..33cf0cc
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-89.d
@@ -0,0 +1,8 @@
+#source: emit-relocs-89.s
+#as: -mabi=ilp32
+#ld: -m [aarch64_choose_ilp32_emul] -e0 --emit-relocs
+#objdump: -dr
+#...
+.* <.text>:
+ .*: f2800015 movk x21, #0x0
+ .*: R_AARCH64_P32_TLSLD_MOVW_DTPREL_G0_NC v1
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-89.s b/ld/testsuite/ld-aarch64/emit-relocs-89.s
new file mode 100644
index 0000000..b4d135c
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-89.s
@@ -0,0 +1,10 @@
+ .global v1
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .word 0xdeaddead
+v2:
+ .word 0xcafecafe
+
+ .text
+ movk x21, #:dtprel_g0_nc:v1
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-90-overflow.d b/ld/testsuite/ld-aarch64/emit-relocs-90-overflow.d
new file mode 100644
index 0000000..f5f65b5
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-90-overflow.d
@@ -0,0 +1,5 @@
+#source: emit-relocs-90-overflow.s
+#as: -mabi=ilp32
+#ld: -m [aarch64_choose_ilp32_emul] -e0 --emit-relocs
+#objdump: -dr
+#error: .*\(.text\+0x\d+\): relocation truncated to fit: R_AARCH64_P32_TLSLD_ADD_DTPREL_HI12 against symbol `v2' .*
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-90-overflow.s b/ld/testsuite/ld-aarch64/emit-relocs-90-overflow.s
new file mode 100644
index 0000000..e10298d
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-90-overflow.s
@@ -0,0 +1,11 @@
+ .global v1
+ .size v1, 16777216
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .zero 16777216
+v2:
+ .word 0xcafecafe
+
+ .text
+ add w20, w9, #:dtprel_hi12:v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-90.d b/ld/testsuite/ld-aarch64/emit-relocs-90.d
new file mode 100644
index 0000000..d6ef58b
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-90.d
@@ -0,0 +1,8 @@
+#source: emit-relocs-90.s
+#as: -mabi=ilp32
+#ld: -m [aarch64_choose_ilp32_emul] -e0 --emit-relocs
+#objdump: -dr
+#...
+.* <.text>:
+ .*: 11019134 add w20, w9, #0x64
+ .*: R_AARCH64_P32_TLSLD_ADD_DTPREL_HI12 v2
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-90.s b/ld/testsuite/ld-aarch64/emit-relocs-90.s
new file mode 100644
index 0000000..e60f9ba
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/emit-relocs-90.s
@@ -0,0 +1,11 @@
+ .global v1
+ .size v1, 409600
+ .global v2
+ .section .tdata,"awT",%progbits
+v1:
+ .zero 409600
+v2:
+ .word 0xcafecafe
+
+ .text
+ add w20, w9, #:dtprel_hi12:v2
--
1.9.1