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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Jim Wilson-2
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

Reply | Threaded
Open this post in threaded view
|

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

Nick Clifton
Hi Jim,

> 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.

> @@ -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;
>      }

Just a thought - it might be worth adding a comment here so that a reader of
the code can understand why a "success" result is being returned for an error.

Cheers
  Nick


Reply | Threaded
Open this post in threaded view
|

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

Jim Wilson-2
I don't see a similar comment in any other port, but it seems reasonable.  Many
ports just return true unconditionally here.  The riscv port has support to
return false if a malloc call fails.  Otherwise, it should not return false
at present.

Committed.

Jim

        bfd/
        * elfnn-riscv.c (riscv_elf_relocate_section): Add comment for previous
        change.
---
 bfd/elfnn-riscv.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index a37f4aac76..dd9c300b5e 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -2253,6 +2253,8 @@ riscv_elf_relocate_section (bfd *output_bfd,
       if (msg)
  info->callbacks->warning
   (info, msg, name, input_bfd, input_section, rel->r_offset);
+      /* We already reported the error via a callback, so don't try to report
+ it again by returning false.  That leads to spurious errors.  */
       ret = TRUE;
       goto out;
     }
--
2.14.1