RISC-V: Improve linker error for FP mismatch.

Message ID 20181113235525.29712-1-jimw@sifive.com
State New
Headers show
Series
  • RISC-V: Improve linker error for FP mismatch.
Related show

Commit Message

Jim Wilson Nov. 13, 2018, 11:55 p.m.
Mixing single-float and double-float code at link time gives an error message
that says we can't link hard-float with soft-float which is confusing.  This
improves the error message to give the correct string for the four different
supported FP ABI formats.

This was tested cross with riscv{32,64}-{elf,linux} on the binutils, gas and
ld testsuites.  There were no regressions.

Committed.

Jim

	bfd/
	* elfnn-riscv.c (riscv_float_abi_string): New.
	(_bfd_riscv_elf_merge_private_bfd_data): Use it for error message.
---
 bfd/elfnn-riscv.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

-- 
2.17.1

Patch

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 5cde72f003..a3599d73a9 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -2638,6 +2638,31 @@  riscv_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
     }
 }
 
+/* Given the ELF header flags in FLAGS, it returns a string that describes the
+   float ABI.  */
+
+static const char *
+riscv_float_abi_string (flagword flags)
+{
+  switch (flags & EF_RISCV_FLOAT_ABI)
+    {
+    case EF_RISCV_FLOAT_ABI_SOFT:
+      return "soft-float";
+      break;
+    case EF_RISCV_FLOAT_ABI_SINGLE:
+      return "single-float";
+      break;
+    case EF_RISCV_FLOAT_ABI_DOUBLE:
+      return "double-float";
+      break;
+    case EF_RISCV_FLOAT_ABI_QUAD:
+      return "quad-float";
+      break;
+    default:
+      abort ();
+    }
+}
+
 /* Merge backend specific data from an object file to the output
    object file when linking.  */
 
@@ -2674,7 +2699,9 @@  _bfd_riscv_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   if ((old_flags ^ new_flags) & EF_RISCV_FLOAT_ABI)
     {
       (*_bfd_error_handler)
-	(_("%pB: can't link hard-float modules with soft-float modules"), ibfd);
+	(_("%pB: can't link %s modules with %s modules"), ibfd,
+	 riscv_float_abi_string (new_flags),
+	 riscv_float_abi_string (old_flags));
       goto fail;
     }