[LLD][ELF][ARM] Implement Thumb pc-relative relocations for adr and ldr
authorPeter Smith <peter.smith@arm.com>
Sun, 23 Feb 2020 19:46:46 +0000 (19:46 +0000)
committerPeter Smith <peter.smith@arm.com>
Fri, 28 Feb 2020 11:29:29 +0000 (11:29 +0000)
commit6b035b607f5f5e4db6f1ca51340d7a87b5807a0c
tree0fbfa488986f5267a6a34aaabe28621b4c1bd081
parent2a92fc9b8e6a079acd53ec3675cfd9bb153ab1ea
[LLD][ELF][ARM] Implement Thumb pc-relative relocations for adr and ldr

MC will now 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 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.

Differential Revision: https://reviews.llvm.org/D75042
13 files changed:
lld/ELF/Arch/ARM.cpp
lld/ELF/InputSection.cpp
lld/ELF/Relocations.h
lld/test/ELF/arm-thumb-adr-err.s [new file with mode: 0644]
lld/test/ELF/arm-thumb-adr.s [new file with mode: 0644]
lld/test/ELF/arm-thumb-ldrlit-err.s [new file with mode: 0644]
lld/test/ELF/arm-thumb-ldrlit.s [new file with mode: 0644]
lld/test/ELF/arm-thumb-pc8-weak.s [new file with mode: 0644]
lld/test/ELF/arm-thumb-undefined-weak.s
lld/test/ELF/arm-thumb2-adr-err.s [new file with mode: 0644]
lld/test/ELF/arm-thumb2-adr.s [new file with mode: 0644]
lld/test/ELF/arm-thumb2-ldrlit-err.s [new file with mode: 0644]
lld/test/ELF/arm-thumb2-ldrlit.s [new file with mode: 0644]