Fix PC-relative offset calculation for LoongArch
Corrects the PC-relative offset calculation in the LoongArch assembler.
This commit corrects the calculation of PC-relative offsets for the LoongArch architecture in the GNU assembler. Previously, md_pcrel_from incorrectly returned 0, which is not the correct base address for PC-relative jumps on LoongArch (which are relative to the start of the current instruction). The function has been updated to return fixP->fx_frag->fr_address + fixP->fx_where, providing the correct offset.
In Details
The md_pcrel_from function in gas/config/tc-loongarch.c determines the base address for calculating PC-relative relocations. On LoongArch, these relocations are relative to the instruction's address. The previous implementation incorrectly returned 0, implying a fixed base or an error. The fix updates it to calculate the correct PC-relative base by adding the fragment's address (fr_address) and the fixup's offset within the fragment (fx_where). This ensures correct relocation calculation for PC-relative addressing modes.
- gas
- The GNU Assembler, part of the GNU Binutils project.
- LoongArch
- An open-source instruction set architecture developed by Loongson Technology.
- PC-relative offset
- An offset calculated with respect to the current Program Counter (PC) value. Used for position-independent code.
- relocation
- Information in an object file that specifies how to modify code or data after linking, typically to resolve symbol addresses or adjust offsets.
- fixS
- A structure used internally by the assembler to represent fixups or relocation information.
- fragment (fx_frag)
- A unit of code or data within the assembler's internal representation, often corresponding to a section or a part of a section.