[PATCH] RISC-V: Force linker error exit after unresolvable reloc.

Maciej W. Rozycki macro@wdc.com
Mon Sep 30 12:39:00 GMT 2019


Jim,

> The patch fixes this by forcing a linker error.  I now get this.
> 
> ohan:2059$ sh tmp.script
> /home/jimw/FOSS/BINUTILS/X-riscv64-linux/ld/ld-new: libtmp2.o(.text+0x18): unresolvable R_RISCV_CALL relocation against symbol `sub'
> /home/jimw/FOSS/BINUTILS/X-riscv64-linux/ld/ld-new: final link failed: bad value
> rohan:2060$ echo $?
> 1
> rohan:2061$ ls -lt libtmp2.so
> ls: cannot access 'libtmp2.so': No such file or directory
[...]
> diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
> index 4729bae09a..ef2471eb99 100644
> --- a/bfd/elfnn-riscv.c
> +++ b/bfd/elfnn-riscv.c
> @@ -2297,7 +2297,10 @@ riscv_elf_relocate_section (bfd *output_bfd,
>  	     (uint64_t) rel->r_offset,
>  	     howto->name,
>  	     h->root.root.string);
> -	  continue;
> +
> +	  bfd_set_error (bfd_error_bad_value);
> +	  ret = FALSE;
> +	  goto out;

 FYI, it's better done with one the percent-codes to `_bfd_error_handler' 
rather than aborting the link right away, so that any further link errors 
are also reported and you don't have to shake them out one by one.  I've 
done such an improvement for several error cases in the MIPS backend.

 Since none was attached to this change of yours, is there a test case (as 
one obviously should) already present in the LD test suite that covers 
this error?  If so, then I can start from there and provide you with a 
quick change to show you what I mean.

  Maciej



More information about the Binutils mailing list