RISC-V: Add ld test cases for weak reference calls

Message ID 20180529062417.13883-1-sebastian.huber@embedded-brains.de
State New
Headers show
Series
  • RISC-V: Add ld test cases for weak reference calls
Related show

Commit Message

Sebastian Huber May 29, 2018, 6:24 a.m.
The new "Weak reference 64" test case fails currently:

ld-new: tmpdir/weakref64.o: in function `_start':
(.text+0x14): relocation truncated to fit: R_RISCV_CALL against undefined symbol `f'
FAIL: Weak reference 64

ld/
	PR ld/23244
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Add test cases.
	* testsuite/ld-riscv-elf/weakref.ld: New file.
	* testsuite/ld-riscv-elf/weakref32.d: Likewise.
	* testsuite/ld-riscv-elf/weakref32.s: Likewise.
	* testsuite/ld-riscv-elf/weakref64.d: Likewise.
	* testsuite/ld-riscv-elf/weakref64.s: Likewise.
---
 ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp |  8 ++++++++
 ld/testsuite/ld-riscv-elf/weakref.ld       |  6 ++++++
 ld/testsuite/ld-riscv-elf/weakref32.d      | 19 +++++++++++++++++++
 ld/testsuite/ld-riscv-elf/weakref32.s      | 18 ++++++++++++++++++
 ld/testsuite/ld-riscv-elf/weakref64.d      | 19 +++++++++++++++++++
 ld/testsuite/ld-riscv-elf/weakref64.s      | 18 ++++++++++++++++++
 6 files changed, 88 insertions(+)
 create mode 100644 ld/testsuite/ld-riscv-elf/weakref.ld
 create mode 100644 ld/testsuite/ld-riscv-elf/weakref32.d
 create mode 100644 ld/testsuite/ld-riscv-elf/weakref32.s
 create mode 100644 ld/testsuite/ld-riscv-elf/weakref64.d
 create mode 100644 ld/testsuite/ld-riscv-elf/weakref64.s

-- 
2.13.6

Comments

Jim Wilson May 31, 2018, midnight | #1
On 05/28/2018 11:24 PM, Sebastian Huber wrote:
> The new "Weak reference 64" test case fails currently:

> 

> ld-new: tmpdir/weakref64.o: in function `_start':

> (.text+0x14): relocation truncated to fit: R_RISCV_CALL against undefined symbol `f'

> FAIL: Weak reference 64

> 

> ld/

> 	PR ld/23244

> 	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Add test cases.

> 	* testsuite/ld-riscv-elf/weakref.ld: New file.

> 	* testsuite/ld-riscv-elf/weakref32.d: Likewise.

> 	* testsuite/ld-riscv-elf/weakref32.s: Likewise.

> 	* testsuite/ld-riscv-elf/weakref64.d: Likewise.

> 	* testsuite/ld-riscv-elf/weakref64.s: Likewise.


The weakref64.d file is not right, as we can't use auipc/jalr in the 
64-bit case.  We will need different output, and I won't know the right 
output until I figure out how to write a patch to fix it.  Otherwise, 
this looks OK and looks like a good idea.  I'd like to try to fix the 
bug first and then fix the weakref64.d file before checking it in.  But 
if I don't get around to this in a few days I will go ahead and check in 
the patch as is, and worry about fixing the weakref64.d file later.

Jim

Patch

diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
index cd11680b55..c06b618744 100644
--- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
+++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
@@ -23,6 +23,14 @@  if [istarget "riscv*-*-*"] {
     run_dump_test "c-lui"
     run_dump_test "disas-jalr"
     run_dump_test "pcrel-lo-addend"
+    run_ld_link_tests {
+	{ "Weak reference 32" "-T weakref.ld -melf32lriscv" ""
+	    "-march=rv32i -mabi=ilp32" {weakref32.s}
+	    {{objdump -d weakref32.d}} "weakref32"}
+	{ "Weak reference 64" "-T weakref.ld -melf64lriscv" ""
+	    "-march=rv64i -mabi=lp64" {weakref64.s}
+	    {{objdump -d weakref64.d}} "weakref64"}
+    }
 
     # The following tests require shared library support.
     if ![check_shared_lib_support] {
diff --git a/ld/testsuite/ld-riscv-elf/weakref.ld b/ld/testsuite/ld-riscv-elf/weakref.ld
new file mode 100644
index 0000000000..a1d362bbba
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/weakref.ld
@@ -0,0 +1,6 @@ 
+ENTRY(_start)
+SECTIONS {
+	.text 0x90000000 : {
+		*(.text*)
+	}
+}
diff --git a/ld/testsuite/ld-riscv-elf/weakref32.d b/ld/testsuite/ld-riscv-elf/weakref32.d
new file mode 100644
index 0000000000..2e77619672
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/weakref32.d
@@ -0,0 +1,19 @@ 
+
+.*:     file format elf32-littleriscv
+
+
+Disassembly of section \.text:
+
+90000000 <_start>:
+90000000:	70000797          	auipc	a5,0x70000
+90000004:	00078793          	mv	a5,a5
+90000008:	02078263          	beqz	a5,9000002c <_start\+0x2c>
+9000000c:	ff010113          	addi	sp,sp,-16
+90000010:	00112623          	sw	ra,12\(sp\)
+90000014:	70000097          	auipc	ra,0x70000
+90000018:	fec080e7          	jalr	-20\(ra\) # 0 <_start\+0x70000000>
+9000001c:	00c12083          	lw	ra,12\(sp\)
+90000020:	01010113          	addi	sp,sp,16
+90000024:	70000317          	auipc	t1,0x70000
+90000028:	fdc30067          	jr	-36\(t1\) # 0 <_start\+0x70000000>
+9000002c:	00008067          	ret
diff --git a/ld/testsuite/ld-riscv-elf/weakref32.s b/ld/testsuite/ld-riscv-elf/weakref32.s
new file mode 100644
index 0000000000..14df041218
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/weakref32.s
@@ -0,0 +1,18 @@ 
+	.option nopic
+	.text
+	.align	1
+	.globl	_start
+	.type	_start, @function
+_start:
+	lla	a5,f
+	beqz	a5,.L1
+	addi	sp,sp,-16
+	sw	ra,12(sp)
+	call	f
+	lw	ra,12(sp)
+	addi	sp,sp,16
+	tail	f
+.L1:
+	ret
+	.size	_start, .-_start
+	.weak	f
diff --git a/ld/testsuite/ld-riscv-elf/weakref64.d b/ld/testsuite/ld-riscv-elf/weakref64.d
new file mode 100644
index 0000000000..eb736a5eb8
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/weakref64.d
@@ -0,0 +1,19 @@ 
+
+.*:     file format elf64-littleriscv
+
+
+Disassembly of section \.text:
+
+0000000080000000 <_start>:
+    90000000:	70000797          	auipc	a5,0x70000
+    90000004:	00078793          	mv	a5,a5
+    90000008:	02078263          	beqz	a5,9000002c <_start+0x2c>
+    9000000c:	ff010113          	addi	sp,sp,-16
+    90000010:	00113423          	sd	ra,8\(sp\)
+    90000014:	70000097          	auipc	ra,0x70000
+    90000018:	fec080e7          	jalr	-20\(ra\) # 0 <_start\+0x70000000>
+    9000001c:	00813083          	ld	ra,8\(sp\)
+    90000020:	01010113          	addi	sp,sp,16
+    90000024:	70000317          	auipc	t1,0x70000
+    90000028:	fdc30067          	jr	-36\(t1\) # 0 <_start\+0x70000000>
+    9000002c:	00008067          	ret
diff --git a/ld/testsuite/ld-riscv-elf/weakref64.s b/ld/testsuite/ld-riscv-elf/weakref64.s
new file mode 100644
index 0000000000..5872626665
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/weakref64.s
@@ -0,0 +1,18 @@ 
+	.option nopic
+	.text
+	.align	1
+	.globl	_start
+	.type	_start, @function
+_start:
+	lla	a5,f
+	beqz	a5,.L1
+	addi	sp,sp,-16
+	sd	ra,8(sp)
+	call	f
+	ld	ra,8(sp)
+	addi	sp,sp,16
+	tail	f
+.L1:
+	ret
+	.size	_start, .-_start
+	.weak	f