[PATCH] Fix riscv ld testsuite failure for compressed1d.

Jim Wilson jimw@sifive.com
Fri Nov 10 18:57:00 GMT 2017


The ld-elf/compressed1d test is failing on riscv32.  The .debug_aranges section
is not expected to be compressed, but it is compressed for this target.  The
problem here is that riscv has linker relaxation that delete code, so
subtractions of text label addresses can't be resolved until linker relaxation
is done.

On x86, the section contents are
Contents of section .debug_aranges:
 0000 1c000000 02000000 00000400 00000000  ................
 0010 00000000 fcffffff 00000000 00000000  ................
with relocs
0000000000000006 R_X86_64_32       .debug_info
0000000000000010 R_X86_64_32       .text

On riscv, the section contents are
 0000 1c000000 02000000 00000400 00000000  ................
 0010 00000000 00000000 00000000 00000000  ................
with relocs
00000006 R_RISCV_32        .Lcu1_begin
00000010 R_RISCV_32        .Lbegin_text1
00000014 R_RISCV_ADD32     .Lbegin_text1
00000014 R_RISCV_SUB32     .Lend_text1

So we see that the x86 section contents do not reduce in size when compressed
because of the -4, but the riscv section contents do reduce in size, so what
the riscv toolchain is doing is correct even though the test is failing.

This looks like a useful test, I can make it work if I hard code in the
constants in an alternate source file, which then gets used for riscv.  The
following patch does this.  Tested on riscv32-elf, riscv64-elf, and
x86_64-elf.

It looks like compressed1e.d may have the same problem, but I haven't looked
at riscv-linux support yet.  I will worry about that later.

OK?

	ld/
	* testsuite/ld-elf/compress1-alt.s: New.
	* testsuite/ld-elf/compressed1d-alt.d: New.
	* testsuite/ld-elf/compressed1d.d: Add riscv*-*-* to notarget list.
---
 ld/testsuite/ld-elf/compress1-alt.s    | 12 ++++++++++++
 ld/testsuite/ld-elf/compressed1d-alt.d | 10 ++++++++++
 ld/testsuite/ld-elf/compressed1d.d     |  4 +++-
 3 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 ld/testsuite/ld-elf/compress1-alt.s
 create mode 100644 ld/testsuite/ld-elf/compressed1d-alt.d

diff --git a/ld/testsuite/ld-elf/compress1-alt.s b/ld/testsuite/ld-elf/compress1-alt.s
new file mode 100644
index 0000000000..0f33236321
--- /dev/null
+++ b/ld/testsuite/ld-elf/compress1-alt.s
@@ -0,0 +1,12 @@
+	.section	.debug_aranges,"",%progbits
+	.4byte	0x1c
+	.2byte	0x2
+	.4byte	0x0
+	.byte	0x4
+	.byte	0x0
+	.2byte	0x0
+	.2byte	0x0
+	.4byte	0x0
+	.4byte	0xfffffffc
+	.4byte	0x0
+	.4byte	0x0
diff --git a/ld/testsuite/ld-elf/compressed1d-alt.d b/ld/testsuite/ld-elf/compressed1d-alt.d
new file mode 100644
index 0000000000..9721f663ad
--- /dev/null
+++ b/ld/testsuite/ld-elf/compressed1d-alt.d
@@ -0,0 +1,10 @@
+#source: compress1-alt.s
+#as: --compress-debug-sections=none
+#ld: -r --compress-debug-sections=zlib-gnu
+#readelf: -SW
+#target: riscv*-*-*
+
+#failif
+#...
+  \[[ 0-9]+\] \.zdebug_aranges[ 	]+(PROGBITS|MIPS_DWARF)[ 	0-9a-z]+ .*
+#...
diff --git a/ld/testsuite/ld-elf/compressed1d.d b/ld/testsuite/ld-elf/compressed1d.d
index 3ca40f9ddb..5c5592df50 100644
--- a/ld/testsuite/ld-elf/compressed1d.d
+++ b/ld/testsuite/ld-elf/compressed1d.d
@@ -2,8 +2,10 @@
 #as: --compress-debug-sections=none
 #ld: -r --compress-debug-sections=zlib-gnu
 #readelf: -SW
-#notarget: d30v-*-* dlx-*-* fr30-*-* frv-*-* ft32-*-* i370-*-* i860-*-* iq2000-*-* mn10200-*-* moxie-*-* msp430-*-* mt-*-* or1k-*-* pj-*-*
+#notarget: d30v-*-* dlx-*-* fr30-*-* frv-*-* ft32-*-* i370-*-* i860-*-* iq2000-*-* mn10200-*-* moxie-*-* msp430-*-* mt-*-* or1k-*-* pj-*-* riscv*-*-*
 # Not all ELF targets use the elf.em emulation...
+# RISC-V has linker relaxations that delete code, so text label subtractions
+# do not get resolved at assembly time, which results in a compressed section.
 
 #failif
 #...
-- 
2.14.1



More information about the Binutils mailing list