[PATCH v6] MIPS: Reject branch absolute relocs for PIC for linking

YunQiang Su syq@gcc.gnu.org
Sun Feb 25 14:08:47 GMT 2024


Maciej W. Rozycki <macro@orcam.me.uk> 于2024年2月22日周四 21:13写道:
>
> On Thu, 22 Feb 2024, YunQiang Su wrote:
>
> > > > +               howto = MIPS_ELF_RTYPE_TO_HOWTO (abfd, r_type, NEWABI_P (abfd));
> > > > +               info->callbacks->einfo
> > > > +                 /* xgettext:c-format */
> > > > +                 (_("%X%H: relocation %s against `*ABS*' cannot be used"
> > >
> > > There's no "*ABS*" in the source and IMHO that'd look confusing
> > > to innocent users.  How about "...against an absolute value"?
> > > Or "...against an absolute value or absolute symbol"?  Perhaps
> > > the latter is a bit too wordy, but also more complete.
> > >
> >
> > Good idea. I think that we should use "...against an absolute value".
> > "absolute symbol"  is not included in this code, as it's r_symndx is
> > not STN_UNDEF.
>
>  Well code says otherwise:
>
> +             if (branch_reloc_p (r_type) && r_symndx == STN_UNDEF)
>
> did you mean "the relocation's r_symndx is STN_UNDEF"?
>
>  But it can be a relocation against an absolute symbol, for example if the
> symbol referred to by a relocation is supplied by another module in the
> link or a linker script and said symbol is absolute.  This case has to be

I have no idea whether we should emit this error for this case:
   If the symbol is set by a linker script, and is near enough with
our instruction,
   the object should be ok for PIC?
If not near enough, a "relocation truncated to fit" error will emit.

> covered in testing as well, as I infer from your code it won't be handled
> correctly.
>
>  In fact this situation is not unique to branch relocations, because no
> PC-relative relocation against an absolute symbol or value can be resolved
> at link time for PIC/PIE links.  So you need to make your code generic for
> any relocations that have the `pc_relative' flag set in their howto unless
> we have a way to make a dynamic relocation out of such a relocation (which
> is none right now, as we still only have R_MIPS_REL32 as the sole dynamic
> relocation, except for TLS stuff).
>
>  Extra test cases will be appreciated if you can come up with ones.
>
>   Maciej


More information about the Binutils mailing list