[PATCH v6] MIPS: Reject branch absolute relocs for PIC for linking
Maciej W. Rozycki
macro@orcam.me.uk
Fri Mar 1 17:23:22 GMT 2024
On Sun, 25 Feb 2024, YunQiang Su wrote:
> > > 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.
If the symbol referred is absolute, then the case is no different from an
absolute relocation. You just can't calculate a PC-relative reference to
an absolute value at static link time, because the distance from PC to
that value will depend on the base address at load time. It is different
from a reference to a regular (non-absolute) symbol that just turns out
too distant for a PC-relative relocation to reach (where the "relocation
truncated to fit" case applies).
Maciej
More information about the Binutils
mailing list