LoongArch-Documentation
LoongArch-Documentation copied to clipboard
fix the detail for PC-relative relocations and add explanation
In the BFD code (under review now), we have:
#define RELOCATE_CALC_PC32_HI20(relocation, pc) \
({ \
bfd_vma lo = (relocation) & ((bfd_vma)0xfff); \
pc = pc & (~(bfd_vma)0xfff); \
if (lo > 0x7ff) \
{ \
relocation += 0x1000; \
} \
relocation &= ~(bfd_vma)0xfff; \
relocation -= pc; \
})
#define RELOCATE_CALC_PC64_HI32(relocation, pc) \
({ \
bfd_vma lo = (relocation) & ((bfd_vma)0xfff); \
if (lo > 0x7ff) \
{ \
relocation -= 0x100000000; \
} \
relocation -= (pc & ~(bfd_vma)0xffffffff); \
})
Pay attention at relocation += 0x1000
and relocation -= 0x100000000
.
Currently our detailed description does not strictly match it. This will puzzle the engineer implementing or reviewing the relocs for other linkers (gold/lld/mold) and cause we criticized by the upstream reviewers. Fix the pseudo-code in the "detail" column and add two footnotes as explanation about why the additional operation is needed.