For many tasks on RISC-V, a sequence ofauipc
and an instruction with a short offset is used for PC-relative addressing (including jumps). This needs a temporary register. The GNU linker is capable of replacing this instruction sequence with one instruction if the offset is short enough. That one instruction does not affect the temporary register.
Thus, the original code sequence and the one that replaces it have slightly different semantics. They perform the same address computation but one leaves some data in the temporary register while the other one does not.
In which cases is the linker allowed to perform such a transformation? If I wrote an auipc
instruction myself, followed by another instruction, would the linker be allowed to rewrite these, or would it need special relocation information?