[PATCH] aarch64: Test DT_RELR with discarded sections
Szabolcs Nagy
szabolcs.nagy@arm.com
Tue Jun 4 10:29:53 GMT 2024
---
ld/testsuite/ld-aarch64/aarch64-elf.exp | 2 +
ld/testsuite/ld-aarch64/relr-discard-pie.d | 22 ++++
ld/testsuite/ld-aarch64/relr-discard-shared.d | 22 ++++
ld/testsuite/ld-aarch64/relr-discard.ld | 13 +++
ld/testsuite/ld-aarch64/relr-discard.s | 102 ++++++++++++++++++
5 files changed, 161 insertions(+)
create mode 100644 ld/testsuite/ld-aarch64/relr-discard-pie.d
create mode 100644 ld/testsuite/ld-aarch64/relr-discard-shared.d
create mode 100644 ld/testsuite/ld-aarch64/relr-discard.ld
create mode 100644 ld/testsuite/ld-aarch64/relr-discard.s
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index 38929ffc3c6..0e70ca3e028 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -475,6 +475,8 @@ run_dump_test_lp64 "relr-got-pie"
run_dump_test_lp64 "relr-got-shared"
run_dump_test_lp64 "relr-text-pie"
run_dump_test_lp64 "relr-text-shared"
+run_dump_test_lp64 "relr-discard-pie"
+run_dump_test_lp64 "relr-discard-shared"
if { ![skip_sframe_tests] } {
run_dump_test "sframe-simple-1"
diff --git a/ld/testsuite/ld-aarch64/relr-discard-pie.d b/ld/testsuite/ld-aarch64/relr-discard-pie.d
new file mode 100644
index 00000000000..4837aa7031d
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-discard-pie.d
@@ -0,0 +1,22 @@
+#source: relr-discard.s
+#ld: -pie --no-apply-dynamic-relocs -z pack-relative-relocs -T relr-discard.ld
+#readelf: -rW
+
+Relocation section '\.rela\.dyn' at offset 0x1.* contains 9 entries:
+ Offset Info Type Symbol's Value Symbol's Name \+ Addend
+0000000000030000 0000000000000403 R_AARCH64_RELATIVE 10004
+0000000000030008 0000000000000403 R_AARCH64_RELATIVE 10008
+0000000000030010 0000000000000403 R_AARCH64_RELATIVE 1000c
+0000000000030018 0000000000000403 R_AARCH64_RELATIVE 30050
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000030040 .*00000101 R_AARCH64_ABS64 0000000000000000 sym_weak_undef \+ 0
+
+Relocation section '\.relr\.dyn' at offset 0x1.* contains 2 entries which relocate 4 locations:
+Index: Entry Address Symbolic Address
+0000: 0000000000030020 0000000000030020 aligned_local
+0001: 0000000000000027 0000000000030028 aligned_hidden
+ 0000000000030030 aligned_global
+ 0000000000030048 aligned_DYNAMIC
diff --git a/ld/testsuite/ld-aarch64/relr-discard-shared.d b/ld/testsuite/ld-aarch64/relr-discard-shared.d
new file mode 100644
index 00000000000..295c469c9eb
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-discard-shared.d
@@ -0,0 +1,22 @@
+#source: relr-discard.s
+#ld: -shared --no-apply-dynamic-relocs -z pack-relative-relocs -T relr-discard.ld
+#readelf: -rW
+
+Relocation section '\.rela\.dyn' at offset 0x1.* contains 10 entries:
+ Offset Info Type Symbol's Value Symbol's Name \+ Addend
+0000000000030000 0000000000000403 R_AARCH64_RELATIVE 10004
+0000000000030008 0000000000000403 R_AARCH64_RELATIVE 10008
+0000000000030018 0000000000000403 R_AARCH64_RELATIVE 30050
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000030010 .*00000101 R_AARCH64_ABS64 000000000001000c sym_global \+ 0
+0000000000030030 .*00000101 R_AARCH64_ABS64 000000000001000c sym_global \+ 0
+0000000000030040 .*00000101 R_AARCH64_ABS64 0000000000000000 sym_weak_undef \+ 0
+
+Relocation section '\.relr\.dyn' at offset 0x1.* contains 2 entries which relocate 3 locations:
+Index: Entry Address Symbolic Address
+0000: 0000000000030020 0000000000030020 aligned_local
+0001: 0000000000000023 0000000000030028 aligned_hidden
+ 0000000000030048 aligned_DYNAMIC
diff --git a/ld/testsuite/ld-aarch64/relr-discard.ld b/ld/testsuite/ld-aarch64/relr-discard.ld
new file mode 100644
index 00000000000..288ba23e11c
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-discard.ld
@@ -0,0 +1,13 @@
+OUTPUT_ARCH(aarch64)
+ENTRY(_start)
+SECTIONS
+{
+ /DISCARD/ : { *(.discard.*) }
+
+ . = 0x10000;
+ .text : { *(.text) }
+ . = 0x20000;
+ .got : { *(.got) *(.got.plt)}
+ . = 0x30000;
+ .data : { *(.data) *(.data.*) }
+}
diff --git a/ld/testsuite/ld-aarch64/relr-discard.s b/ld/testsuite/ld-aarch64/relr-discard.s
new file mode 100644
index 00000000000..a6d2351a64b
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-discard.s
@@ -0,0 +1,102 @@
+// Test DT_RELR with references in discarded sections.
+
+.text
+.p2align 3
+.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
+
+
+.section .discard.aligned_local,"a"
+.p2align 1
+discard_aligned_local:
+.xword sym_local
+
+.section .discard.aligned_hidden,"a"
+.p2align 1
+discard_aligned_hidden:
+.xword sym_hidden
+
+.section .discard.aligned_global,"a"
+.p2align 1
+discard_aligned_global:
+.xword sym_global
+
+.section .discard.aligned_global_abs,"a"
+.p2align 1
+discard_aligned_global_abs:
+.xword sym_global_abs
+
+.section .discard.aligned_weak_undef,"a"
+.p2align 1
+discard_aligned_weak_undef:
+.xword sym_weak_undef
+
+.section .discard.aligned_DYNAMIC,"a"
+.p2align 1
+discard_aligned_DYNAMIC:
+.xword _DYNAMIC
--
2.25.1
More information about the Binutils
mailing list