[PATCH] bfd: Fix 64-bit relocation handling for a.out
Gunther Nikl
gnikl@justmail.de
Thu May 7 19:45:39 GMT 2020
[This is a slightly edited version of the previous mail which was blocked
by sourceware]
Hello Nick,
> Hi Gunther,
>
> > I have an update which ensures only supported sizes are permitted.
> > Thoughts?
>
> I like it. I only have one comment:
>
> > + switch (bfd_get_reloc_size (g->howto))
> > + {
> > + default:
> > + _bfd_error_handler (_("%pB: unsupported relocation size"), abfd);
>
> vs...
>
> > + switch (bfd_get_reloc_size (howto))
> > + {
> > + default:
> > + abort ();
>
> I far prefer error messages (and error return codes, if available) to
> calling abort. As a user I find having an error message telling me at
> least something about what is wrong to be much more useful than an a
> abort referring to source code that I may not even have available.
I agree that an error message is nicer than an abort. I have chosen
abort in the second case since other places in the modified function do
the same.
However, I now believe that this hunk can be dropped. The used bfd
object is an a.out type as the aout_backend_data is used all over the
place with that bfd object in this function. Thus the howto is from
howto_table_std and no unsupported size is possible at this time.
Attached is an updated patch there the aout_link_reloc_link_order change
is removed.
Regards,
Gunther
---
2020-05-XX Gunther Nikl <gnikl@justmail.de>
* aoutx.h (NAME (aout, swap_std_reloc_out)): Reject an unsupported
relocation size.
diff --git a/bfd/aoutx.h b/bfd/aoutx.h
index d5457461ab..09d61b1c2d 100644
--- a/bfd/aoutx.h
+++ b/bfd/aoutx.h
@@ -1946,10 +1946,19 @@ NAME (aout, swap_std_reloc_out) (bfd *abfd,
BFD_ASSERT (g->howto != NULL);
- if (bfd_get_reloc_size (g->howto) != 8)
- r_length = g->howto->size; /* Size as a power of two. */
- else
- r_length = 3;
+ switch (bfd_get_reloc_size (g->howto))
+ {
+ default:
+ _bfd_error_handler (_("%pB: unsupported relocation size"), abfd);
+ bfd_set_error (bfd_error_bad_value);
+ return;
+ case 1: case 2: case 4:
+ r_length = g->howto->size; /* Size as a power of two. */
+ break;
+ case 8:
+ r_length = 3;
+ break;
+ }
r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */
/* XXX This relies on relocs coming from a.out files. */
---
More information about the Binutils
mailing list