LoongArch-Documentation icon indicating copy to clipboard operation
LoongArch-Documentation copied to clipboard

fix the detail for PC-relative relocations and add explanation

Open xry111 opened this issue 2 years ago • 0 comments

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.

xry111 avatar Jul 25 '22 06:07 xry111