[committed v3 2/2] RISC-V: Added ld testcase for pcgp relaxation.

Nelson Chu nelson.chu@sifive.com
Fri Oct 22 10:00:31 GMT 2021


From: Lewis Revill <lewis.revill@embecosm.com>

Consider the the pcgp-relax-02 testcase,

        .text
        .globl _start
_start:
.L1:    auipc   a0, %pcrel_hi(data_a)
.L2:    auipc   a1, %pcrel_hi(data_b)
        addi    a0, a0, %pcrel_lo(.L1)
        addi    a1, a1, %pcrel_lo(.L2)

        .data
        .word 0x0
        .globl data_a
data_a:
        .word 0x1

        .section .rodata
        .globl data_b
data_b:
        .word 0x2

If the first auipc is deleted, but we are still building the pcgp
table (connect the high and low pcrel relocations), then there is
an aliasing issue that we need some way to disambiguate which of
the two symbols we are targeting.  Therefore, Palmer thought of a
way to use R_RISCV_DELETE to split this into two phases, so we
could resolve the addresses before creating the ambiguities.

This patch just add the ld testcase for the above case, in case we
have changed something but break this.

ld/
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Renamed pcgp-relax
	to pcgp-relax-01, and added pcgp-relax-02.
	* testsuite/ld-riscv-elf/pcgp-relax-01.d: Renmaed from pcgp-relax.
	* testsuite/ld-riscv-elf/pcgp-relax-01.s: Likewise.
	* testsuite/ld-riscv-elf/pcgp-relax-02.d: New testcase.
	* testsuite/ld-riscv-elf/pcgp-relax-02.s: Likewise.
---
 ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp |  3 ++-
 ld/testsuite/ld-riscv-elf/pcgp-relax-01.d  | 16 ++++++++++++++++
 ld/testsuite/ld-riscv-elf/pcgp-relax-01.s  | 29 +++++++++++++++++++++++++++++
 ld/testsuite/ld-riscv-elf/pcgp-relax-02.d  | 15 +++++++++++++++
 ld/testsuite/ld-riscv-elf/pcgp-relax-02.s  | 18 ++++++++++++++++++
 ld/testsuite/ld-riscv-elf/pcgp-relax.d     | 16 ----------------
 ld/testsuite/ld-riscv-elf/pcgp-relax.s     | 29 -----------------------------
 7 files changed, 80 insertions(+), 46 deletions(-)
 create mode 100644 ld/testsuite/ld-riscv-elf/pcgp-relax-01.d
 create mode 100644 ld/testsuite/ld-riscv-elf/pcgp-relax-01.s
 create mode 100644 ld/testsuite/ld-riscv-elf/pcgp-relax-02.d
 create mode 100644 ld/testsuite/ld-riscv-elf/pcgp-relax-02.s
 delete mode 100644 ld/testsuite/ld-riscv-elf/pcgp-relax.d
 delete mode 100644 ld/testsuite/ld-riscv-elf/pcgp-relax.s

diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
index 20ca3bd..78a7134 100644
--- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
+++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
@@ -121,7 +121,8 @@ proc run_relax_twice_test {} {
 if [istarget "riscv*-*-*"] {
     run_dump_test "align-small-region"
     run_dump_test "call-relax"
-    run_dump_test "pcgp-relax"
+    run_dump_test "pcgp-relax-01"
+    run_dump_test "pcgp-relax-02"
     run_dump_test "c-lui"
     run_dump_test "c-lui-2"
     run_dump_test "disas-jalr"
diff --git a/ld/testsuite/ld-riscv-elf/pcgp-relax-01.d b/ld/testsuite/ld-riscv-elf/pcgp-relax-01.d
new file mode 100644
index 0000000..f942567
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/pcgp-relax-01.d
@@ -0,0 +1,16 @@
+#source: pcgp-relax-01.s
+#ld: --relax
+#objdump: -d -Mno-aliases
+
+.*:[ 	]+file format .*
+
+
+Disassembly of section \.text:
+
+0+[0-9a-f]+ <_start>:
+.*:[ 	]+[0-9a-f]+[ 	]+addi[ 	]+a0,a0,[0-9]+
+.*:[ 	]+[0-9a-f]+[ 	]+jal[ 	]+ra,[0-9a-f]+ <_start>
+.*:[ 	]+[0-9a-f]+[ 	]+addi[ 	]+a1,gp,\-[0-9]+ # [0-9a-f]+ <data_g>
+.*:[ 	]+[0-9a-f]+[ 	]+addi[ 	]+a2,gp,\-[0-9]+ # [0-9a-f]+ <data_g>
+.*:[ 	]+[0-9a-f]+[ 	]+addi[ 	]+a3,tp,0 # 0 <data_t>
+.*:[ 	]+[0-9a-f]+[ 	]+auipc[ 	]+a0,0x[0-9a-f]+
diff --git a/ld/testsuite/ld-riscv-elf/pcgp-relax-01.s b/ld/testsuite/ld-riscv-elf/pcgp-relax-01.s
new file mode 100644
index 0000000..fab6a5b
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/pcgp-relax-01.s
@@ -0,0 +1,29 @@
+	.text
+	.globl _start
+_start:
+	addi	a0, a0, %pcrel_lo(.L2)
+
+	call	_start
+.L1:
+	auipc	a1, %pcrel_hi(data_g)
+	addi	a1, a1, %pcrel_lo(.L1)
+
+	lui	a2, %hi(data_g)
+	addi	a2, a2, %lo(data_g)
+
+	lui	a3, %tprel_hi(data_t)
+	add	a3, a3, tp, %tprel_add(data_t)
+	addi	a3, a3, %tprel_lo(data_t)
+
+.L2:
+	auipc   a0, %pcrel_hi(data_g)
+
+	.data
+	.word 0x0
+	.globl data_g
+data_g:
+	.word 0x1
+
+	.section .tbss
+data_t:
+	.word 0x0
diff --git a/ld/testsuite/ld-riscv-elf/pcgp-relax-02.d b/ld/testsuite/ld-riscv-elf/pcgp-relax-02.d
new file mode 100644
index 0000000..c6c73c5
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/pcgp-relax-02.d
@@ -0,0 +1,15 @@
+#source: pcgp-relax-02.s
+#as:
+#ld: --relax
+#objdump: -d
+
+.*:[ 	]+file format .*
+
+
+Disassembly of section .text:
+
+[0-9a-f]+ <_start>:
+.*:[ 	]+[0-9a-f]+[ 	]+auipc[ 	]+a1.*
+.*:[ 	]+[0-9a-f]+[ 	]+addi[ 	]+a0,gp.*<data_a>
+.*:[ 	]+[0-9a-f]+[ 	]+addi[ 	]+a1,a1.*<data_b>
+#pass
diff --git a/ld/testsuite/ld-riscv-elf/pcgp-relax-02.s b/ld/testsuite/ld-riscv-elf/pcgp-relax-02.s
new file mode 100644
index 0000000..ca4aa1f
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/pcgp-relax-02.s
@@ -0,0 +1,18 @@
+	.text
+	.globl _start
+_start:
+.L1:	auipc	a0, %pcrel_hi(data_a)
+.L2:	auipc	a1, %pcrel_hi(data_b)
+	addi	a0, a0, %pcrel_lo(.L1)
+	addi	a1, a1, %pcrel_lo(.L2)
+
+	.data
+	.word 0x0
+	.globl data_a
+data_a:
+	.word 0x1
+
+	.section .rodata
+	.globl data_b
+data_b:
+	.word 0x2
diff --git a/ld/testsuite/ld-riscv-elf/pcgp-relax.d b/ld/testsuite/ld-riscv-elf/pcgp-relax.d
deleted file mode 100644
index dae2b62..0000000
--- a/ld/testsuite/ld-riscv-elf/pcgp-relax.d
+++ /dev/null
@@ -1,16 +0,0 @@
-#source: pcgp-relax.s
-#ld: --relax
-#objdump: -d -Mno-aliases
-
-.*:[ 	]+file format .*
-
-
-Disassembly of section \.text:
-
-0+[0-9a-f]+ <_start>:
-.*:[ 	]+[0-9a-f]+[ 	]+addi[ 	]+a0,a0,[0-9]+
-.*:[ 	]+[0-9a-f]+[ 	]+jal[ 	]+ra,[0-9a-f]+ <_start>
-.*:[ 	]+[0-9a-f]+[ 	]+addi[ 	]+a1,gp,\-[0-9]+ # [0-9a-f]+ <data_g>
-.*:[ 	]+[0-9a-f]+[ 	]+addi[ 	]+a2,gp,\-[0-9]+ # [0-9a-f]+ <data_g>
-.*:[ 	]+[0-9a-f]+[ 	]+addi[ 	]+a3,tp,0 # 0 <data_t>
-.*:[ 	]+[0-9a-f]+[ 	]+auipc[ 	]+a0,0x[0-9a-f]+
diff --git a/ld/testsuite/ld-riscv-elf/pcgp-relax.s b/ld/testsuite/ld-riscv-elf/pcgp-relax.s
deleted file mode 100644
index fab6a5b..0000000
--- a/ld/testsuite/ld-riscv-elf/pcgp-relax.s
+++ /dev/null
@@ -1,29 +0,0 @@
-	.text
-	.globl _start
-_start:
-	addi	a0, a0, %pcrel_lo(.L2)
-
-	call	_start
-.L1:
-	auipc	a1, %pcrel_hi(data_g)
-	addi	a1, a1, %pcrel_lo(.L1)
-
-	lui	a2, %hi(data_g)
-	addi	a2, a2, %lo(data_g)
-
-	lui	a3, %tprel_hi(data_t)
-	add	a3, a3, tp, %tprel_add(data_t)
-	addi	a3, a3, %tprel_lo(data_t)
-
-.L2:
-	auipc   a0, %pcrel_hi(data_g)
-
-	.data
-	.word 0x0
-	.globl data_g
-data_g:
-	.word 0x1
-
-	.section .tbss
-data_t:
-	.word 0x0
-- 
2.7.4



More information about the Binutils mailing list