[PATCH 0/8] ARM: clean up PC-relative arithmetic

Nicolas Pitre nicolas.pitre at linaro.org
Wed Aug 3 11:27:58 PDT 2016

On Wed, 3 Aug 2016, Ard Biesheuvel wrote:

> There are various places in the ARM kernel where the following pattern
> is used to create a PC-relative reference that is valid even before the
> MMU is on:
>      adr    rX, 1f
>      ldr    rY, [rX]
>      add    rX, rX, rY
>      ...
>   1: .long  <symbol> - .   
> or
>      adr    rX, 1f
>      ldmia  rX, {rY .. rY+n}
>      sub    rX, rX, rY
>      add    rY+1, rY+1, rX
>      add    rY+2, rY+2, rX
>      ...
>   1: .long  .
>      .long  <symbolY>
>      .long  <symbolY+1>
>      ...
> Both cases can be greatly simplified by letting the linker do the
> calculations for us. This series implements adr_l, ldr_l and str_l
> macros, and uses them to simplify a couple of instances of the above
> patterns.

I echo Dave's concern about the availability of the :pc_g*_nc: relocs.

Could this be used to solve the XIP translation problem in some 
universal way? Right now only a few cases are covered. For reference, see:


commit d7811455 ("ARM: 8512/1: proc-v7.S: Adjust stack address when XIP_KERNEL")

commit 8ff97fa3 ("ARM: make the physical-relative calculation more obvious")


More information about the linux-arm-kernel mailing list