[LLD][ELF][ARM] Implement ARM pc-relative relocations for ADR and LDR
authorPeter Smith <peter.smith@arm.com>
Sat, 4 Apr 2020 16:15:19 +0000 (17:15 +0100)
committerPeter Smith <peter.smith@arm.com>
Wed, 8 Apr 2020 11:43:44 +0000 (12:43 +0100)
commit28b172e34177fe925ac4f54de2ce073e1d6029d9
tree25c8e1123f8966b4206e4517e901370831706aa2
parent66c18c729da456680af7884f551a6c4627dc6372
[LLD][ELF][ARM] Implement ARM pc-relative relocations for ADR and LDR

The R_ARM_ALU_PC_G0 and R_ARM_LDR_PC_G0 relocations are used by the
ADR and LDR pseudo instructions, and are the basis of the group
relocations that can load an arbitrary constant via a series of add, sub
and ldr instructions.

The relocations need to be obtained via the .reloc directive.

R_ARM_ALU_PC_G0 is much more complicated as the add/sub instruction uses
a modified immediate encoding of an 8-bit immediate rotated right by an
even 4-bit field. This means that the range of representable immediates
is sparse. We extract the encoding and decoding functions for the modified
immediate from llvm/lib/Target/ARM/MCTargetDesc/ARMAddressingModes.h as
this header file is not accessible from LLD. Duplication of code isn't
ideal, but as these are well-defined mathematical functions they are
unlikely to change.

Differential Revision: https://reviews.llvm.org/D75349
lld/ELF/Arch/ARM.cpp
lld/test/ELF/arm-adr-err.s [new file with mode: 0644]
lld/test/ELF/arm-adr-long.s [new file with mode: 0644]
lld/test/ELF/arm-adr.s [new file with mode: 0644]
lld/test/ELF/arm-ldrlit-err.s [new file with mode: 0644]
lld/test/ELF/arm-ldrlit.s [new file with mode: 0644]