[PATCH 2/2] aarch64: Add some DT_RELR ld tests
Szabolcs Nagy
szabolcs.nagy@arm.com
Wed May 29 09:03:12 GMT 2024
---
ld/testsuite/ld-aarch64/aarch64-elf.exp | 6 ++
ld/testsuite/ld-aarch64/relr-align.d | 22 +++++
ld/testsuite/ld-aarch64/relr-align.s | 106 +++++++++++++++++++++
ld/testsuite/ld-aarch64/relr-data-pie.d | 18 ++++
ld/testsuite/ld-aarch64/relr-data-shared.d | 18 ++++
ld/testsuite/ld-aarch64/relr-data.s | 71 ++++++++++++++
ld/testsuite/ld-aarch64/relr-got-pie.d | 15 +++
ld/testsuite/ld-aarch64/relr-got-shared.d | 15 +++
ld/testsuite/ld-aarch64/relr-got.s | 40 ++++++++
9 files changed, 311 insertions(+)
create mode 100644 ld/testsuite/ld-aarch64/relr-align.d
create mode 100644 ld/testsuite/ld-aarch64/relr-align.s
create mode 100644 ld/testsuite/ld-aarch64/relr-data-pie.d
create mode 100644 ld/testsuite/ld-aarch64/relr-data-shared.d
create mode 100644 ld/testsuite/ld-aarch64/relr-data.s
create mode 100644 ld/testsuite/ld-aarch64/relr-got-pie.d
create mode 100644 ld/testsuite/ld-aarch64/relr-got-shared.d
create mode 100644 ld/testsuite/ld-aarch64/relr-got.s
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index 9ce61579e6c..a66c2e63237 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -468,6 +468,12 @@ run_dump_test_lp64 "bti-far-2"
run_dump_test_lp64 "bti-far-opt"
run_dump_test_lp64 "bti-far-3"
+run_dump_test_lp64 "relr-align"
+run_dump_test_lp64 "relr-data-pie"
+run_dump_test_lp64 "relr-data-shared"
+run_dump_test_lp64 "relr-got-pie"
+run_dump_test_lp64 "relr-got-shared"
+
if { ![skip_sframe_tests] } {
run_dump_test "sframe-simple-1"
}
diff --git a/ld/testsuite/ld-aarch64/relr-align.d b/ld/testsuite/ld-aarch64/relr-align.d
new file mode 100644
index 00000000000..ac2fa6eff08
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-align.d
@@ -0,0 +1,22 @@
+#source: relr-align.s
+#ld: -shared -z pack-relative-relocs -T relocs.ld
+#readelf: -rW
+
+Relocation section '\.rela\.dyn' at offset 0x10090 contains 3 entries:
+ Offset Info Type Symbol's Value Symbol's Name \+ Addend
+0000000012340011 0000000000000403 R_AARCH64_RELATIVE 10000
+0000000012340019 0000000000000403 R_AARCH64_RELATIVE 10000
+0000000012340041 0000000000000403 R_AARCH64_RELATIVE 10000
+
+Relocation section '\.relr\.dyn' at offset 0x100d8 contains 9 entries which relocate 10 locations:
+Index: Entry Address Symbolic Address
+0000: 0000000012340000 0000000012340000 double_0
+0001: 0000000000000003 0000000012340008 double_0 \+ 0x8
+0002: 0000000012340022 0000000012340022 double_2
+0003: 0000000000000003 000000001234002a double_2 \+ 0x8
+0004: 0000000012340038 0000000012340038 single_0
+0005: 000000001234004a 000000001234004a single_2
+0006: 0000000012340058 0000000012340058 big
+0007: 8000000100000001 0000000012340158 big \+ 0x100
+ 0000000012340250 big \+ 0x1f8
+0008: 0000000000000003 0000000012340258 big \+ 0x200
diff --git a/ld/testsuite/ld-aarch64/relr-align.s b/ld/testsuite/ld-aarch64/relr-align.s
new file mode 100644
index 00000000000..94223cd3512
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-align.s
@@ -0,0 +1,106 @@
+// Test DT_RELR with differently aligned relative relocs.
+
+.text
+.global _start
+_start:
+foo:
+
+.data
+.p2align 3
+double_0:
+.xword foo
+.xword foo
+.byte 0
+double_1:
+.xword foo
+.xword foo
+.byte 0
+double_2:
+.xword foo
+.xword foo
+.byte 0
+.byte 0
+.byte 0
+.byte 0
+.byte 0
+.byte 0
+single_0:
+.xword foo
+.byte 0
+single_1:
+.xword foo
+.byte 0
+single_2:
+.xword foo
+.byte 0
+.byte 0
+.byte 0
+.byte 0
+.byte 0
+.byte 0
+big:
+.xword foo
+.xword 1
+.xword 2
+.xword 3
+.xword 4
+.xword 5
+.xword 6
+.xword 7
+.xword 8
+.xword 9
+.xword 10
+.xword 11
+.xword 12
+.xword 13
+.xword 14
+.xword 15
+.xword 16
+.xword 17
+.xword 18
+.xword 19
+.xword 20
+.xword 21
+.xword 22
+.xword 23
+.xword 24
+.xword 25
+.xword 26
+.xword 27
+.xword 28
+.xword 29
+.xword 30
+.xword 31
+.xword foo + 32
+.xword 33
+.xword 34
+.xword 35
+.xword 36
+.xword 37
+.xword 38
+.xword 39
+.xword 40
+.xword 41
+.xword 42
+.xword 43
+.xword 44
+.xword 45
+.xword 46
+.xword 47
+.xword 48
+.xword 49
+.xword 50
+.xword 51
+.xword 52
+.xword 53
+.xword 54
+.xword 55
+.xword 56
+.xword 57
+.xword 58
+.xword 59
+.xword 60
+.xword 61
+.xword 62
+.xword foo + 63
+.xword foo + 64
diff --git a/ld/testsuite/ld-aarch64/relr-data-pie.d b/ld/testsuite/ld-aarch64/relr-data-pie.d
new file mode 100644
index 00000000000..b96e9b61ca4
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-data-pie.d
@@ -0,0 +1,18 @@
+#source: relr-data.s
+#ld: -pie -z pack-relative-relocs -T relocs.ld
+#readelf: -rW
+
+Relocation section '\.rela\.dyn' at offset 0x100e0 contains 5 entries:
+ Offset Info Type Symbol's Value Symbol's Name \+ Addend
+0000000012340000 0000000000000403 R_AARCH64_RELATIVE 10004
+0000000012340008 0000000000000403 R_AARCH64_RELATIVE 10008
+0000000012340010 0000000000000403 R_AARCH64_RELATIVE 1000c
+0000000012340018 0000000000000403 R_AARCH64_RELATIVE 12340050
+0000000012340040 0000000300000101 R_AARCH64_ABS64 0000000000000000 sym_weak_undef \+ 0
+
+Relocation section '\.relr\.dyn' at offset 0x10158 contains 2 entries which relocate 4 locations:
+Index: Entry Address Symbolic Address
+0000: 0000000012340020 0000000012340020 aligned_local
+0001: 0000000000000027 0000000012340028 aligned_hidden
+ 0000000012340030 aligned_global
+ 0000000012340048 aligned_DYNAMIC
diff --git a/ld/testsuite/ld-aarch64/relr-data-shared.d b/ld/testsuite/ld-aarch64/relr-data-shared.d
new file mode 100644
index 00000000000..d94b335fac2
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-data-shared.d
@@ -0,0 +1,18 @@
+#source: relr-data.s
+#ld: -shared -z pack-relative-relocs -T relocs.ld
+#readelf: -rW
+
+Relocation section '\.rela\.dyn' at offset 0x10150 contains 6 entries:
+ Offset Info Type Symbol's Value Symbol's Name \+ Addend
+0000000012340000 0000000000000403 R_AARCH64_RELATIVE 10004
+0000000012340008 0000000000000403 R_AARCH64_RELATIVE 10008
+0000000012340018 0000000000000403 R_AARCH64_RELATIVE 12340050
+0000000012340010 0000000400000101 R_AARCH64_ABS64 000000000001000c sym_global \+ 0
+0000000012340030 0000000400000101 R_AARCH64_ABS64 000000000001000c sym_global \+ 0
+0000000012340040 0000000300000101 R_AARCH64_ABS64 0000000000000000 sym_weak_undef \+ 0
+
+Relocation section '\.relr\.dyn' at offset 0x101e0 contains 2 entries which relocate 3 locations:
+Index: Entry Address Symbolic Address
+0000: 0000000012340020 0000000012340020 aligned_local
+0001: 0000000000000023 0000000012340028 aligned_hidden
+ 0000000012340048 aligned_DYNAMIC
diff --git a/ld/testsuite/ld-aarch64/relr-data.s b/ld/testsuite/ld-aarch64/relr-data.s
new file mode 100644
index 00000000000..93b401e4b5e
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-data.s
@@ -0,0 +1,71 @@
+// Test symbol references in .data when used with DT_RELR.
+// Relocations for unaligned sections are currently not packed.
+
+.text
+.global _start
+_start:
+ nop
+
+sym_local:
+ nop
+
+.global sym_hidden
+.hidden sym_hidden
+sym_hidden:
+ nop
+
+.global sym_global
+sym_global:
+ nop
+
+.global sym_global_abs
+.set sym_global_abs, 42
+
+.global sym_weak_undef
+.weak sym_weak_undef
+
+.section .data.unaligned_local
+unaligned_local:
+.xword sym_local
+
+.section .data.unaligned_hidden
+unaligned_hidden:
+.xword sym_hidden
+
+.section .data.unaligned_global
+unaligned_global:
+.xword sym_global
+
+.section .data.unaligned_DYNAMIC
+unaligned_DYNAMIC:
+.xword _DYNAMIC
+
+.section .data.aligned_local
+.p2align 1
+aligned_local:
+.xword sym_local
+
+.section .data.aligned_hidden
+.p2align 1
+aligned_hidden:
+.xword sym_hidden
+
+.section .data.aligned_global
+.p2align 1
+aligned_global:
+.xword sym_global
+
+.section .data.aligned_global_abs
+.p2align 1
+aligned_global_abs:
+.xword sym_global_abs
+
+.section .data.aligned_weak_undef
+.p2align 1
+aligned_weak_undef:
+.xword sym_weak_undef
+
+.section .data.aligned_DYNAMIC
+.p2align 1
+aligned_DYNAMIC:
+.xword _DYNAMIC
diff --git a/ld/testsuite/ld-aarch64/relr-got-pie.d b/ld/testsuite/ld-aarch64/relr-got-pie.d
new file mode 100644
index 00000000000..2a397498009
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-got-pie.d
@@ -0,0 +1,15 @@
+#source: relr-got.s
+#ld: -pie -z pack-relative-relocs -T relocs.ld
+#readelf: -rW
+
+Relocation section '\.rela\.dyn' at offset 0x100e8 contains 2 entries:
+ Offset Info Type Symbol's Value Symbol's Name \+ Addend
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000020030 0000000200000401 R_AARCH64_GLOB_DAT 0000000000000000 sym_weak_undef \+ 0
+
+Relocation section '\.relr\.dyn' at offset 0x10118 contains 2 entries which relocate 4 locations:
+Index: Entry Address Symbolic Address
+0000: 0000000000020008 0000000000020008 _GLOBAL_OFFSET_TABLE_ \+ 0x8
+0001: 000000000000000f 0000000000020010 _GLOBAL_OFFSET_TABLE_ \+ 0x10
+ 0000000000020018 _GLOBAL_OFFSET_TABLE_ \+ 0x18
+ 0000000000020020 _GLOBAL_OFFSET_TABLE_ \+ 0x20
diff --git a/ld/testsuite/ld-aarch64/relr-got-shared.d b/ld/testsuite/ld-aarch64/relr-got-shared.d
new file mode 100644
index 00000000000..59526947a9a
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-got-shared.d
@@ -0,0 +1,15 @@
+#source: relr-got.s
+#ld: -shared -z pack-relative-relocs -T relocs.ld
+#readelf: -rW
+
+Relocation section '\.rela\.dyn' at offset 0x10168 contains 3 entries:
+ Offset Info Type Symbol's Value Symbol's Name \+ Addend
+0000000000020020 0000000300000401 R_AARCH64_GLOB_DAT 0000000000010038 sym_global \+ 0
+0000000000020028 0000000500000401 R_AARCH64_GLOB_DAT 000000000000002a sym_global_abs \+ 0
+0000000000020030 0000000200000401 R_AARCH64_GLOB_DAT 0000000000000000 sym_weak_undef \+ 0
+
+Relocation section '\.relr\.dyn' at offset 0x101b0 contains 2 entries which relocate 3 locations:
+Index: Entry Address Symbolic Address
+0000: 0000000000020008 0000000000020008 _GLOBAL_OFFSET_TABLE_ \+ 0x8
+0001: 0000000000000007 0000000000020010 _GLOBAL_OFFSET_TABLE_ \+ 0x10
+ 0000000000020018 _GLOBAL_OFFSET_TABLE_ \+ 0x18
diff --git a/ld/testsuite/ld-aarch64/relr-got.s b/ld/testsuite/ld-aarch64/relr-got.s
new file mode 100644
index 00000000000..44e44633eb4
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-got.s
@@ -0,0 +1,40 @@
+// Test GOT relocations with DT_RELR.
+
+.text
+.global _start
+_start:
+ adrp x0, :got:sym_local
+ ldr x0, [x0, :got_lo12:sym_local]
+
+ adrp x0, :got:sym_hidden
+ ldr x0, [x0, :got_lo12:sym_hidden]
+
+ adrp x0, :got:sym_global
+ ldr x0, [x0, :got_lo12:sym_global]
+
+ adrp x0, :got:sym_global
+ ldr x0, [x0, :got_lo12:sym_global_abs]
+
+ adrp x0, :got:sym_weak_undef
+ ldr x0, [x0, :got_lo12:sym_weak_undef]
+
+ adrp x0, :got:_DYNAMIC
+ ldr x0, [x0, :got_lo12:_DYNAMIC]
+
+sym_local:
+ nop
+
+.global sym_hidden
+.hidden sym_hidden
+sym_hidden:
+ nop
+
+.global sym_global
+sym_global:
+ nop
+
+.global sym_global_abs
+.set sym_global_abs, 42
+
+.global sym_weak_undef
+.weak sym_weak_undef
--
2.25.1
More information about the Binutils
mailing list