Do I need to modify the AddrLoc of LLD for ARC target?

Hi LLVM developers,

basic-arc.s:

main:
bl memset

$ arc-elf32-gcc -mcpu=arc600 -o basic-arc.o -c

$ arc-elf32-readelf -r basic-arc.o

Relocation section '.rela.text' at offset 0xd4 contains 1 entries:
Offset Info Type Sym.Value Sym. Name + Addend
00000000 00000611 R_ARC_S25W_PCREL 00000000 memset + 0

High address: 0x0

$ arc-elf32-ld -o basic-arc basic-arc.o -L/opt/arc-gnu/lib/gcc/arc-elf32/7.1.1/arc600 -L/opt/arc-gnu/lib/gcc/arc-elf32/7.1.1/../../../../arc-elf32/lib/arc600 -L/opt/arc-gnu/lib/gcc/arc-elf32/7.1.1 -L/opt/arc-gnu/lib/gcc/arc-elf32/7.1.1/../../../../arc-elf32/lib --start-group -lgcc -lc -lnosys --end-group -Ttext=0

DEBUG: arc-ld: R_ARC_S25W_PCREL relocation: 1 S: 4 A: 0 P: 0 = (vma: 0 + output_offset: 0 + reloc_offset: 0 - 0) & ~0x3
DEBUG: arc-ld: type: R_ARC_S25W_PCREL insn: 2054

$ ld.lld -o basic-arc-lld basic-arc.o $ARC_LINKER_LIB -Ttext=0

DEBUG: lld: R_ARC_S25W_PCREL TargetVA: 4 A: 0 P: 0 <-- same P as arc-ld
DEBUG: lld: R_ARC_S25W_PCREL: Insn: 2050 Rel: 1
DEBUG: lld: R_ARC_S25W_PCREL: Insn: 2054 <-- same relocation value as arc-ld

But with several different high address *not* 0x0, such as 0x6:

DEBUG: arc-ld: R_ARC_S25W_PCREL relocation: 2 S: 12 A: 0 P: 4 = (vma: 6 + output_offset: 0 + reloc_offset: 0 - 0) & ~0x3
DEBUG: arc-ld: type: R_ARC_S25W_PCREL insn: 2058

DEBUG: lld: R_ARC_S25W_PCREL TargetVA: 4 A: 0 P: 8 <-- different P?
DEBUG: lld: R_ARC_S25W_PCREL: Insn: 2050 Rel: 1
DEBUG: lld: R_ARC_S25W_PCREL: Insn: 2054 <-- different relocation value

How arc-ld calculates P?

P = ((reloc_data.input_section->output_section ? reloc_data.input_section->output_section->vma : 0) + reloc_data.input_section->output_offset + (reloc_data.reloc_offset - (reloc_data.bitsize >= 32 ? 4 : 0))) & ~0x3;

for example, R_ARC_S25W_PCREL's bitsize < 32, P = (6 + 0 + 0 - 0) & ~0x3 = 4, when vma is 6, output and reloc offset is 0.

How LLD calculates P (AddrLoc)?

P = getOutputSection()->Addr + getOffset(Rel.Offset);

for example, the same high address 0x6, LLD's P is 8, different with arc-ld? so do I need to modify the value of P for R_PC case in the getRelocTargetVA? please give me some hints, thanks a lot!

PS: arc-ld R_ARC_S25W_PCREL's FORMULA is: ( S + A ) - P ) >> 2, and it needs middle endian convert, so:

Insn = middleEndianConvert (insn, TRUE);

Insn = replaceDisp25w(Insn, ( S + A ) - P ) >> 2);

Insn = middleEndianConvert (insn, TRUE);

write32le(Loc, Insn);

The *debug* patch to verify the AddrLoc of LLD for ARC target:

Index: ELF/Arch/ARC.cpp