R_LARCH_PCREL20_S2 is a new added relocation type in LoongArch ELF
psABI v2.10 [1] which is not corvered by D138135 except R_LARCH_64_PCREL.
A motivation to support R_LARCH_PCREL20_S2 in lld is to build the
runtime of .NET core (a.k.a CoreCLR) in which strict PC-relative
semantics need to be guaranteed [2]. The normal pcalau12i + addi.d
approach doesn't work because the code will be copied to other places
with different "page" and offsets. To achieve this, we can use pcaddi
with explicit R_LARCH_PCREL20_S2 reloc to address +-2MB PC-relative
range with 4-bytes aligned.
[1]: https://github.com/loongson/la-abi-specs/releases/tag/v2.10
[2]: https://github.com/dotnet/runtime/blob/release/7.0/src/coreclr/vm/loongarch64/asmhelpers.S#L307
I remember MaskRay once mentioned the desire to keep lld invocations to a minimum? To me this looks like two pcaddi's pointing to two separate sections (one above .text and one below), then only one run for the positive cases would be enough. Let's see what he thinks.