[PATCH] D75042: [LLD][ELF][ARM] Implement Thumb pc-relative relocations for adr and ldr

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 24 05:01:39 PST 2020


psmith created this revision.
psmith added reviewers: ruiu, MaskRay, grimar.
Herald added subscribers: kristof.beyls, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
psmith added a parent revision: D75039: [MC][ELF][ARM] Add relocations for Thumb pc-relative fixups.

MC if D75039 <https://reviews.llvm.org/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


https://reviews.llvm.org/D75042

Files:
  lld/ELF/Arch/ARM.cpp
  lld/ELF/InputSection.cpp
  lld/ELF/Relocations.h
  lld/test/ELF/arm-thumb-adr-err.s
  lld/test/ELF/arm-thumb-adr.s
  lld/test/ELF/arm-thumb-ldrlit-err.s
  lld/test/ELF/arm-thumb-ldrlit.s
  lld/test/ELF/arm-thumb-pc8-weak.s
  lld/test/ELF/arm-thumb-undefined-weak.s
  lld/test/ELF/arm-thumb2-adr-err.s
  lld/test/ELF/arm-thumb2-adr.s
  lld/test/ELF/arm-thumb2-ldrlit-err.s
  lld/test/ELF/arm-thumb2-ldrlit.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75042.246179.patch
Type: text/x-patch
Size: 22407 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200224/07680ed7/attachment.bin>


More information about the llvm-commits mailing list