RISC-V: Disallow output format changes.

Message ID 20180306200332.4059-1-jimw@sifive.com
State New
Headers show
Series
  • RISC-V: Disallow output format changes.
Related show

Commit Message

Jim Wilson March 6, 2018, 8:03 p.m.
This fixes PR 22920 by disallowing output format changes in linker scripts,
same as is already done by several other targets.  The testcase now generates
a link time error instead of silently producing incorrect results.  It also
turns two ld-srec failures into expected failures, and two misc tests are no
longer run.

This was tested with riscv{32,64}-{elf,linux} testsuite runs.  The unexpected
failures decrease by 2 for all 4 targets, and the expected failures increase
by 2 because of the srec tests.  The expected passes drop by 2 as 2 tests are
no longer run.  Otherwise, there are no regressions.

Committed.

Jim

	PR 22920
	* emultempl/riscvelf.em (riscv_create_output_section_statements): New.
	(LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS): New.
	* testsuite/ld-elf/pr21884.d (#notarget): Add riscv*-*-*.
	* testsuite/ld-unique/pr21529.d (#notarget): Likewise.
	* testsuite/ld-srec/srec.exp (run_srec_test): For riscv*-*-* target,
	call setup_xfail.
---
 ld/emultempl/riscvelf.em         | 20 ++++++++++++++++++++
 ld/testsuite/ld-elf/pr21884.d    |  2 +-
 ld/testsuite/ld-srec/srec.exp    |  6 ++++++
 ld/testsuite/ld-unique/pr21529.d |  2 +-
 4 files changed, 28 insertions(+), 2 deletions(-)

-- 
2.14.1

Comments

Jim Wilson March 6, 2018, 8:10 p.m. | #1
On Tue, Mar 6, 2018 at 12:03 PM, Jim Wilson <jimw@sifive.com> wrote:
> This fixes PR 22920 by disallowing output format changes in linker scripts,

> same as is already done by several other targets.  The testcase now generates

> a link time error instead of silently producing incorrect results.


Actually, the testcase in this PR was causing a linker crash.  It was
the ld-srec testcases that were silently producing incorrect output.

Jim

Patch

diff --git a/ld/emultempl/riscvelf.em b/ld/emultempl/riscvelf.em
index a284c6303f..eaaf4c58b5 100644
--- a/ld/emultempl/riscvelf.em
+++ b/ld/emultempl/riscvelf.em
@@ -62,7 +62,27 @@  gld${EMULATION_NAME}_after_allocation (void)
   gld${EMULATION_NAME}_map_segments (need_layout);
 }
 
+/* This is a convenient point to tell BFD about target specific flags.
+   After the output has been created, but before inputs are read.  */
+
+static void
+riscv_create_output_section_statements (void)
+{
+  /* See PR 22920 for an example of why this is necessary.  */
+  if (strstr (bfd_get_target (link_info.output_bfd), "riscv") == NULL)
+    {
+      /* The RISC-V backend needs special fields in the output hash structure.
+	 These will only be created if the output format is a RISC-V format,
+	 hence we do not support linking and changing output formats at the
+	 same time.  Use a link followed by objcopy to change output formats.  */
+      einfo (_("%F%P: error: cannot change output format"
+	       " whilst linking %s binaries\n"), "RISC-V");
+      return;
+    }
+}
+
 EOF
 
 LDEMUL_BEFORE_ALLOCATION=riscv_elf_before_allocation
 LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
+LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=riscv_create_output_section_statements
diff --git a/ld/testsuite/ld-elf/pr21884.d b/ld/testsuite/ld-elf/pr21884.d
index 2645a874bf..e7eae56cef 100644
--- a/ld/testsuite/ld-elf/pr21884.d
+++ b/ld/testsuite/ld-elf/pr21884.d
@@ -2,7 +2,7 @@ 
 #source: pr21884b.s
 #ld: -T pr21884.t
 #objdump: -b binary -s
-#notarget: aarch64*-*-* arm*-*-* avr-*-* hppa-*-* ia64-*-* m68hc1*-*-* nds32*-*-* score-*-* v850-*-*
+#notarget: aarch64*-*-* arm*-*-* avr-*-* hppa-*-* ia64-*-* m68hc1*-*-* nds32*-*-* riscv*-*-* score-*-* v850-*-*
 # Skip targets which can't change output format to binary.
 
 .*:     file format binary
diff --git a/ld/testsuite/ld-srec/srec.exp b/ld/testsuite/ld-srec/srec.exp
index fb6162f056..7cda271039 100644
--- a/ld/testsuite/ld-srec/srec.exp
+++ b/ld/testsuite/ld-srec/srec.exp
@@ -282,6 +282,12 @@  proc run_srec_test { test objs } {
 	setup_xfail "msp430*-*-*"
     }
 
+    # The RISC-V target does not correctly process
+    # relocs when output format is not ELF.
+    if [istarget riscv*-*-*] {
+	setup_xfail "riscv*-*-*"
+    }
+
     # SH64 targets cannot convert format in the linker 
     # using the -oformat command line switch.
     if [istarget sh64*-*-elf] {
diff --git a/ld/testsuite/ld-unique/pr21529.d b/ld/testsuite/ld-unique/pr21529.d
index 655a9eff9e..11d47b8443 100644
--- a/ld/testsuite/ld-unique/pr21529.d
+++ b/ld/testsuite/ld-unique/pr21529.d
@@ -1,6 +1,6 @@ 
 #ld: --oformat binary -T pr21529.ld -e main
 #objdump: -s -b binary
-#notarget: aarch64*-*-* arm*-*-* avr-*-* ia64-*-* m68hc1*-*-* nds32*-*-* score-*-* v850-*-*
+#notarget: aarch64*-*-* arm*-*-* avr-*-* ia64-*-* m68hc1*-*-* nds32*-*-* riscv*-*-* score-*-* v850-*-*
 # Skip targets which can't change output format to binary.
 
 #pass