[PATCH] D72892: [MC][ARM] Resolve some pcrel fixups at assembly time

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 23 14:50:07 PST 2020


MaskRay added a comment.

In D72892#1886079 <https://reviews.llvm.org/D72892#1886079>, @psmith wrote:

> In D72892#1885906 <https://reviews.llvm.org/D72892#1885906>, @MaskRay wrote:
>
> > Rebase.
> >
> > In case someone needs this workaround before we implement these relocations.
>
>
> Given how close we are to 10.0 and pr44929 is on the 10.0 release blocker list. I think this is workaround is closer than emitting the relocations and updating the linkers. Will be worth waiting to see if there are any objections.
>
> I think that at least a subset of this will be beneficial as there are some fixups that don't have relocations defined. Checking the Arm ARM https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile and https://static.docs.arm.com/ihi0044/g/aaelf32.pdf as well as the binutils implementations it looks like we have relocations defined for:
>
> Arm state
>
> | instruction      | fixup                 | relocation         | gold | bfd |
> | adr r0, bar      | arm_adr_pcrel_12      | R_ARM_ALU_PC_G0_NC | yes  | yes |
> | ldr r0, foo      | arm_ldst_pcrel_12     | R_ARM_LDR_PC_G0    | yes  | yes |
> | ldrd r0, r1, foo | arm_pcrel_10_unscaled | R_ARM_LDRS_PC_G0   | *no* | yes |
> |
>
> There are G1, G2 and G3 relocations as well as the add and ldr have a modified immediate form that shifts the immediate. In GNU as these can be accessed via modifiers such as :pc_g1: symbol.
>
> Thumb state
>
>   | instruction | fixup | relocation | gold | bfd |
>
> | adr r0, bar   | fixup_thumb_adr_pcrel_10 | R_ARM_THM_PC8           | yes | yes |
> | adr.w r0, bar | t2_adr_pcrel_12          | R_ARM_THM_ALU_PREL_11_0 | yes | yes |
> | ldr r0, foo   | fixup_arm_thumb_cp       | R_ARM_THM_PC8           | yes | yes |
> | ldr.w r0, foo | t2_ldst_pcrel_12         | R_ARM_THM_PC12          | yes | yes |
> |
>
> I'm not aware of any relocations for vldr or the thumb state ldrd. I'm not sure I've ever seen these written in assembly though.
>
> I'll start implementing these in LLD, will take a little time as I can't work full time on it. When that is done we can emit relocations for these cases. We'll then have to decide whether to support vldr or ldrd to a global. These may be sufficiently rare to ask for code to be changed.


I discussed with FreeBSD developers on #bsdmips. Hope they can make the assembly code (https://github.com/freebsd/freebsd/blob/master/sys/arm/arm/locore-v6.S#L75) more portable, without any work on LLVM's side.

For some relocation types (e.g. R_ARM_ALU_PC_G0_NC), they were only touched twice in binutils-gdb/bfd/, with the last commit made in 2006 (https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=4962c51a67b10abe404f59ba70d8bc51473fbc16). I can't find a ld/testsuite test demonstrating that it works. Implementing them just makes very rare code constructs like `.globl foo; foo: ... adr r0, foo` work.

If it turns out that more instances run into this issue. I think we can commit the workaround just to the `release/10.x` branch.

@psmith I can't convince myself that they are useful enough deserving your precious time implementing them :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72892/new/

https://reviews.llvm.org/D72892





More information about the llvm-commits mailing list