[PATCH] RISC-V: Eliminate spurious error w/ reloc truncated message

Jim Wilson jimw@sifive.com
Wed Feb 7 00:55:00 GMT 2018


Linking with a file with a bad relocation in it gives two errors.

rohan:2170$ ld/ld-new tmp.o
tmp.o: In function `_start':
(.text+0x0): relocation truncated to fit: R_RISCV_JAL against `*UND*'
ld/ld-new: final link failed: Symbol needs debug section which does not exist
rohan:2171$ 

The problem is that the riscv relocate_section function is using callbacks to
report an error, and then returning false, which confuses the linker into
thinking that there was a second unreported error.  The first error, relocation
truncated, tried reading debug info to pretty print the error message, and
along the way tried to read a separate debug info file which failed, setting
bfd_error, which is where the second error message comes from.  The solution
is just that we should not return false after successfully reporting an error
via callbacks.

This has the side benefit that it also fixes --noinhibit-exec, which makes
debugging the linker a little easier.

This was tested with check-{binutils,gas,ld} for riscv{32,64}-{elf,linux}.
There were no regressions.

Committed.

	bfd/
	* elfnn-riscv.c (riscv_elf_relocate_section): Return TRUE if used
	callback to report an error.
---
 bfd/elfnn-riscv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 3524fede0f..a37f4aac76 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -2253,6 +2253,7 @@ riscv_elf_relocate_section (bfd *output_bfd,
       if (msg)
 	info->callbacks->warning
 	  (info, msg, name, input_bfd, input_section, rel->r_offset);
+      ret = TRUE;
       goto out;
     }
 
-- 
2.14.1



More information about the Binutils mailing list