[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 09:49:23 GMT 2023


On Thu, 27 Jul 2023, Joseph Faulls wrote:

> Relaxations can cause the gp to move after it has been decided to gp
> relax. Against an absolute symbol, the distance may change such that the
> offset can no longer fit in the 12-bit immediate field.

 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.  Since you're fiddling 
with linker relaxation code here, you may well take the opportunity and 
relax it to LUI/ADDI, or ADDI alone if the value is small.  There may be 
an issue with RV64 objects if the value turns out outside the 32-bit range 
though, which will be a relocation overflow.

  Maciej


More information about the Binutils mailing list