[PATCH 09/10] ld: Add simple DT_RELR tests

Fangrui Song i@maskray.me
Sat Jan 8 08:37:09 GMT 2022


On 2022-01-07, H.J. Lu via Binutils wrote:
>	* testsuite/ld-elf/dt-relr-1.s: New file.
>	* testsuite/ld-elf/dt-relr-1a.d: Likewise.
>	* testsuite/ld-elf/dt-relr-1b.d: Likewise.
>	* testsuite/ld-elf/dt-relr-1c.d: Likewise.
>	* testsuite/ld-elf/dt-relr-2.s: Likewise.
>	* testsuite/ld-elf/dt-relr-2a.d: Likewise.
>	* testsuite/ld-elf/dt-relr-2b.d: Likewise.
>	* testsuite/ld-elf/dt-relr-2c.d: Likewise.
>	* testsuite/ld-elf/dt-relr-2d.d: Likewise.
>	* testsuite/ld-elf/dt-relr-2e.d: Likewise.
>	* testsuite/ld-elf/dt-relr-2f.d: Likewise.
>	* testsuite/ld-elf/dt-relr-2g.d: Likewise.
>	* testsuite/ld-elf/dt-relr-2h.d: Likewise.
>---
> ld/testsuite/ld-elf/dt-relr-1.s  | 13 +++++++++++++
> ld/testsuite/ld-elf/dt-relr-1a.d | 10 ++++++++++
> ld/testsuite/ld-elf/dt-relr-1b.d |  9 +++++++++
> ld/testsuite/ld-elf/dt-relr-1c.d |  9 +++++++++
> ld/testsuite/ld-elf/dt-relr-2.s  | 20 ++++++++++++++++++++
> ld/testsuite/ld-elf/dt-relr-2a.d | 10 ++++++++++
> ld/testsuite/ld-elf/dt-relr-2b.d | 17 +++++++++++++++++
> ld/testsuite/ld-elf/dt-relr-2c.d | 17 +++++++++++++++++
> ld/testsuite/ld-elf/dt-relr-2d.d |  9 +++++++++
> ld/testsuite/ld-elf/dt-relr-2e.d |  9 +++++++++
> ld/testsuite/ld-elf/dt-relr-2f.d |  8 ++++++++
> ld/testsuite/ld-elf/dt-relr-2g.d |  9 +++++++++
> ld/testsuite/ld-elf/dt-relr-2h.d |  9 +++++++++
> 13 files changed, 149 insertions(+)
> create mode 100644 ld/testsuite/ld-elf/dt-relr-1.s
> create mode 100644 ld/testsuite/ld-elf/dt-relr-1a.d
> create mode 100644 ld/testsuite/ld-elf/dt-relr-1b.d
> create mode 100644 ld/testsuite/ld-elf/dt-relr-1c.d
> create mode 100644 ld/testsuite/ld-elf/dt-relr-2.s
> create mode 100644 ld/testsuite/ld-elf/dt-relr-2a.d
> create mode 100644 ld/testsuite/ld-elf/dt-relr-2b.d
> create mode 100644 ld/testsuite/ld-elf/dt-relr-2c.d
> create mode 100644 ld/testsuite/ld-elf/dt-relr-2d.d
> create mode 100644 ld/testsuite/ld-elf/dt-relr-2e.d
> create mode 100644 ld/testsuite/ld-elf/dt-relr-2f.d
> create mode 100644 ld/testsuite/ld-elf/dt-relr-2g.d
> create mode 100644 ld/testsuite/ld-elf/dt-relr-2h.d
>
>diff --git a/ld/testsuite/ld-elf/dt-relr-1.s b/ld/testsuite/ld-elf/dt-relr-1.s
>new file mode 100644
>index 00000000000..18486d3acb2
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-1.s
>@@ -0,0 +1,13 @@
>+	.text
>+	.p2align 3
>+	.globl _start
>+_start:
>+	.byte 0
>+
>+	.data
>+	.p2align 3
>+	.globl data
>+data:
>+	.byte 0
>+	//  Offset is not a multiple of 2.  Don't use DT_RELR.
>+	.dc.a __ehdr_start + 10

.data
.balign 1
.dc.a .data

may be worth adding as a test.

Currently R_X86_64_RELATIVE is used even if its r_offset is even.
There is conservative but safe as it's difficult to ensure an input
section's address is even when its alignment is 1.

>diff --git a/ld/testsuite/ld-elf/dt-relr-1a.d b/ld/testsuite/ld-elf/dt-relr-1a.d
>new file mode 100644
>index 00000000000..55c93cefb59
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-1a.d
>@@ -0,0 +1,10 @@
>+#source: dt-relr-1.s
>+#ld: -e _start $DT_RELR_LDFLAGS
>+#readelf: -rW -d
>+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
>+
>+#...
>+There is no dynamic section in this file.
>+#...
>+There are no relocations in this file.
>+#pass
>diff --git a/ld/testsuite/ld-elf/dt-relr-1b.d b/ld/testsuite/ld-elf/dt-relr-1b.d
>new file mode 100644
>index 00000000000..2b78f75d378
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-1b.d
>@@ -0,0 +1,9 @@
>+#source: dt-relr-1.s
>+#ld: -e _start -pie $DT_RELR_LDFLAGS
>+#readelf: -rW -d
>+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
>+
>+#failif
>+#...
>+Relocation section '\.relr\.dyn' at offset .*
>+#pass
>diff --git a/ld/testsuite/ld-elf/dt-relr-1c.d b/ld/testsuite/ld-elf/dt-relr-1c.d
>new file mode 100644
>index 00000000000..14f6cda6832
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-1c.d
>@@ -0,0 +1,9 @@
>+#source: dt-relr-1.s
>+#ld: -shared $DT_RELR_LDFLAGS
>+#readelf: -rW -d
>+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
>+
>+#failif
>+#...
>+Relocation section '\.relr\.dyn' at offset .*
>+#pass
>diff --git a/ld/testsuite/ld-elf/dt-relr-2.s b/ld/testsuite/ld-elf/dt-relr-2.s
>new file mode 100644
>index 00000000000..c3917ee8c3a
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-2.s
>@@ -0,0 +1,20 @@
>+	.text
>+	.p2align 3
>+	.globl _start
>+_start:
>+	.byte 0
>+
>+	.data
>+	.p2align 3
>+	.globl data
>+data:
>+
>+	.dc.a .data
>+	.dc.a 0
>+	.dc.a data + 2
>+	.dc.a __ehdr_start + 4
>+	.dc.a __ehdr_start + 9
>+
>+	.byte 0
>+	//  Offset is not a multiple of 2.  Don't use DT_RELR.
>+	.dc.a __ehdr_start + 10
>diff --git a/ld/testsuite/ld-elf/dt-relr-2a.d b/ld/testsuite/ld-elf/dt-relr-2a.d
>new file mode 100644
>index 00000000000..31ef9e8e80e
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-2a.d
>@@ -0,0 +1,10 @@
>+#source: dt-relr-2.s
>+#ld: -e _start $DT_RELR_LDFLAGS
>+#readelf: -rW -d
>+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
>+
>+#...
>+There is no dynamic section in this file.
>+#...
>+There are no relocations in this file.
>+#pass
>diff --git a/ld/testsuite/ld-elf/dt-relr-2b.d b/ld/testsuite/ld-elf/dt-relr-2b.d
>new file mode 100644
>index 00000000000..7c401732a56
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-2b.d
>@@ -0,0 +1,17 @@
>+#source: dt-relr-2.s
>+#ld: -e _start -pie $DT_RELR_LDFLAGS
>+#readelf: -rW -d
>+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
>+
>+#...
>+ 0x[0-9a-f]+ \(RELR\)    +0x[0-9a-f]+
>+ 0x[0-9a-f]+ \(RELRSZ\)  +(8|16) \(bytes\)
>+ 0x[0-9a-f]+ \(RELRENT\) +(4|8) \(bytes\)
>+#...
>+Relocation section '\.rel(a|)\.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
>+#...
>+[0-9a-f]+ +[0-9a-f]+ +R_.*_RELATIVE .*
>+#...
>+Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
>+  4 offsets
>+#pass
>diff --git a/ld/testsuite/ld-elf/dt-relr-2c.d b/ld/testsuite/ld-elf/dt-relr-2c.d
>new file mode 100644
>index 00000000000..63877b2f90f
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-2c.d
>@@ -0,0 +1,17 @@
>+#source: dt-relr-2.s
>+#ld: -shared $DT_RELR_LDFLAGS
>+#readelf: -rW -d
>+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
>+
>+#...
>+ 0x[0-9a-f]+ \(RELR\)    +0x[0-9a-f]+
>+ 0x[0-9a-f]+ \(RELRSZ\)  +(8|16) \(bytes\)
>+ 0x[0-9a-f]+ \(RELRENT\) +(4|8) \(bytes\)
>+#...
>+Relocation section '\.rel(a|)\.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
>+#...
>+[0-9a-f]+ +[0-9a-f]+ +R_.*_RELATIVE .*
>+#...
>+Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
>+  3 offsets
>+#pass
>diff --git a/ld/testsuite/ld-elf/dt-relr-2d.d b/ld/testsuite/ld-elf/dt-relr-2d.d
>new file mode 100644
>index 00000000000..270a901f1a6
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-2d.d
>@@ -0,0 +1,9 @@
>+#source: dt-relr-2.s
>+#ld: -e _start -pie $DT_RELR_LDFLAGS --no-relax
>+#readelf: -rW -d
>+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
>+
>+#failif
>+#...
>+Relocation section '\.relr\.dyn' at offset .*
>+#pass
>diff --git a/ld/testsuite/ld-elf/dt-relr-2e.d b/ld/testsuite/ld-elf/dt-relr-2e.d
>new file mode 100644
>index 00000000000..79ea62b096a
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-2e.d
>@@ -0,0 +1,9 @@
>+#source: dt-relr-2.s
>+#ld: -e _start -pie $DT_RELR_LDFLAGS -z nocombreloc
>+#readelf: -rW -d
>+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
>+
>+#failif
>+#...
>+Relocation section '\.relr\.dyn' at offset .*
>+#pass
>diff --git a/ld/testsuite/ld-elf/dt-relr-2f.d b/ld/testsuite/ld-elf/dt-relr-2f.d
>new file mode 100644
>index 00000000000..4ad592f71fb
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-2f.d
>@@ -0,0 +1,8 @@
>+#source: dt-relr-2.s
>+#ld: -r $DT_RELR_LDFLAGS
>+#readelf: -rW
>+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
>+
>+#...
>+Relocation section '\.rel(a|)\.data' at offset 0x[0-9a-f]+ contains 5 entries:
>+#pass
>diff --git a/ld/testsuite/ld-elf/dt-relr-2g.d b/ld/testsuite/ld-elf/dt-relr-2g.d
>new file mode 100644
>index 00000000000..78e370068af
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-2g.d
>@@ -0,0 +1,9 @@
>+#source: dt-relr-2.s
>+#ld: -e _start -pie $NO_DT_RELR_LDFLAGS
>+#readelf: -rW -d
>+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
>+
>+#failif
>+#...
>+Relocation section '\.relr\.dyn' at offset .*
>+#pass
>diff --git a/ld/testsuite/ld-elf/dt-relr-2h.d b/ld/testsuite/ld-elf/dt-relr-2h.d
>new file mode 100644
>index 00000000000..312373fb179
>--- /dev/null
>+++ b/ld/testsuite/ld-elf/dt-relr-2h.d
>@@ -0,0 +1,9 @@
>+#source: dt-relr-2.s
>+#ld: -e _start -shared $NO_DT_RELR_LDFLAGS
>+#readelf: -rW -d
>+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
>+
>+#failif
>+#...
>+Relocation section '\.relr\.dyn' at offset .*
>+#pass
>-- 
>2.33.1
>


More information about the Libc-alpha mailing list