[EXTERNAL] Re: [PATCH] RISC-V: Do not gp relax against an ABS symbol if it is far away.
Maciej W. Rozycki
macro@orcam.me.uk
Tue Aug 8 12:04:05 GMT 2023
On Tue, 8 Aug 2023, Joseph Faulls wrote:
> > What's the use case for using AUIPC/LW to load an absolute symbol?
> > Such symbols are not used in contexts where an address could
> > alternatively be expected, so the correct sequence, and in PIC or PIE
> > code indeed the only valid, for direct references from code is
> > LUI/ADDI
>
> For my clarification, are you saying that the AUIPC/LW should never have
> been generated? If so, how is it possible for the compiler to know that
> the symbol referenced will be an absolute symbol?
No, the compiler won't ever know that a reference will ultimately resolve
to an absolute symbol; I don't think there's a way to tell it. Then such
symbols aren't usually used in compiled code as they are awkward to refer
to (e.g. in C you'll only ever use `&symbol' to get at one). Most often
I'd expect them to be referred in handcoded assembly, via the LI macro,
and possibly defined via the GAS's or LD's `--defsym' command-line option,
or in a linker script.
Maciej
More information about the Binutils
mailing list