[llvm] [llvm][MC][ARM][Assembly] Emit relocations for ADRs and big-endian targets (PR #73834)

via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 21 14:24:15 PST 2023


bd1976bris wrote:

@eleanor-arm / @smithp35 / @DavidSpickett - I don't think this patch or the proceeding one is valid. 

I'm motivated by the code added here: https://reviews.freebsd.org/D2035 to FreeBSD where `cachebailout` is referenced with `adr r3, _C_LABEL(cachebailout)` and both the reference and the symbol are in the same section (`.text`). Previously, this was codegen'd either with an `add` (if the target was at a higher address) or a `sub` (lower). 

With these patches the compiler always codegen's as if the reference was in another section to the target, even when they are in the same section. That means that the compiler can't use the information as to whether the target is at a higher or lower address to the reference, and it seems that the compiler always codegen's `adr r3, _C_LABEL(cachebailout)` as a `sub` in that case. This means that the target may is out of range (it is in the FreeBSD example) and the linker will error trying to patch the relocation for the reference. 

I think that these patches need reworking so that either relocations are not used in the case where the reference and target are in the same section, or a more complicated relocation/relaxation scheme is used to allow the linker to adjust the instruction used. Alternatively, we could replace these patches with something simpler, for example the GNU assembler seems to simply error if the target for an `adr`/`ldr` is in a different section - perhaps that would be more suitable?

https://github.com/llvm/llvm-project/pull/73834


More information about the llvm-commits mailing list