MC if D75039 is accepted will output the R_ARM_THM_PC8, R_ARM_THM_PC12 and R_ARM_THM_PREL_11_0 relocations. These are short-ranged relocations that are used to implement the adr rd, literal and ldr rd, literal pseudo instructions.
The instructions use a new RelExpr called R_ARM_PCA in order to calculate the required S + A - Pa expression, where Pa is AlignDown(P, 4) as the instructions add their immediate to AlignDown(PC, 4). We also do not want these relocations to generate or resolve against a PLT entry as the range of these relocations (4095 bytes) is so short they would never reach.
The R_ARM_THM_PC8 has a special encoding convention for the relocation addend, the immediate field is unsigned, yet the addend must be -4 to account for the Thumb PC bias. The ABI (not the architecture) uses the convention that the 8-byte immediate of 0xff represents -4.
References:
- ELF for the Arm Architecture https://static.docs.arm.com/ihi0044/g/aaelf32.pdf for the relocation directives
- Architecture Reference Manual Armv8, for Armv8-A architecture profile https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile
In particular: F5.1.73 LDR (literal) and F5.1.10 ADR
Fixes part of pr 44929 https://bugs.llvm.org/show_bug.cgi?id=44929
TODO:
- Implement the ARM state pc-relative relocations in both MC and LLD
I believe rel.sym is never nullptr, even if ELF32_R_SYM(r) is 0.
The field Relocation::sym is a pointer to: